Browse Source

refactor

tags/0.6.0
Randy Lai 5 years ago
parent
commit
456dc1e292
6 changed files with 63 additions and 48 deletions
  1. +1
    -1
      inux).sublime-keymap
  2. +1
    -1
      SX).sublime-keymap
  3. +1
    -1
      indows).sublime-keymap
  4. +14
    -6
      Default.sublime-commands
  5. +1
    -1
      README.md
  6. +45
    -38
      pm.py

Default → inux).sublime-keymap View File

@@ -1,7 +1,7 @@
[
{
"keys": ["ctrl+alt+p"],
"command": "project_manager_list_projects", "args": {"action": "switch"}
"command": "project_manager", "args": {"action": "switch"}
},
{
"keys": ["ctrl+shift+w"],

Default → SX).sublime-keymap View File

@@ -1,6 +1,6 @@
[
{
"keys": ["super+ctrl+p"],
"command": "project_manager_list_projects", "args": {"action": "switch"}
"command": "project_manager", "args": {"action": "switch"}
}
]

Default → indows).sublime-keymap View File

@@ -1,7 +1,7 @@
[
{
"keys": ["ctrl+alt+p"],
"command": "project_manager_list_projects", "args": {"action": "switch"}
"command": "project_manager", "args": {"action": "switch"}
},
{
"keys": ["ctrl+shift+w"],

+ 14
- 6
Default.sublime-commands View File

@@ -8,27 +8,35 @@
"command": "project_manager_add_project"
},
{
"caption": "Project Manager: Import .sublime-project",
"caption": "Project Manager: Import .sublime-project File",
"command": "project_manager_import_project"
},
{
"caption": "Project Manager: Open Project",
"command": "project_manager_list_projects", "args": {"action": "switch"}
"command": "project_manager", "args": {"action": "switch"}
},
{
"caption": "Project Manager: Open Project in New Window",
"command": "project_manager_list_projects", "args": {"action": "new"}
"command": "project_manager", "args": {"action": "new"}
},
{
"caption": "Project Manager: Append Project",
"command": "project_manager", "args": {"action": "append"}
},
{
"caption": "Project Manager: Remove Project",
"command": "project_manager_list_projects", "args": {"action": "remove"}
"command": "project_manager", "args": {"action": "remove"}
},
{
"caption": "Project Manager: Edit Project",
"command": "project_manager_list_projects", "args": {"action": "edit"}
"command": "project_manager", "args": {"action": "edit"}
},
{
"caption": "Project Manager: Rename Project",
"command": "project_manager_list_projects", "args": {"action": "rename"}
"command": "project_manager", "args": {"action": "rename"}
},
{
"caption": "Project Manager: Clear Recent Projects",
"command": "project_manager_clear_recent_projects"
}
]

+ 1
- 1
README.md View File

@@ -45,7 +45,7 @@ You can additionally add the following keybind in your user keybind settings fil
```
{
"keys": ["super+ctrl+o"],
"command": "project_manager_list_projects", "args": {"action": "new"}
"command": "project_manager", "args": {"action": "new"}
}
```



+ 45
- 38
pm.py View File

@@ -153,7 +153,7 @@ class Manager:
if plist[i][0] is not plist[i][1]:
plist.insert(count, plist.pop(i))
count = count + 1
return [[item[0] for item in plist], [[item[1], item[2]] for item in plist]]
return [item[0] for item in plist], [[item[1], item[2]] for item in plist]

def project_file_name(self, project):
return self.projects_info[project]["file"]
@@ -174,6 +174,10 @@ class Manager:
recent = recent[(50-len(recent)):len(recent)]
j.save(recent)

def clear_recent_projects(self):
j = JsonFile(os.path.join(self.primary_dir, "recent.json"))
j.remove()

def add_project(self):
def on_add(project):
pd = self.window.project_data()
@@ -338,6 +342,28 @@ class Manager:
v.run_command("select_all")


class ProjectManagerAddProject(sublime_plugin.WindowCommand):

def run(self):
self.manager = Manager(self.window)
self.manager.add_project()


class ProjectManagerImportProject(sublime_plugin.WindowCommand):

def run(self):
self.manager = Manager(self.window)
self.manager.import_sublime_project()


class ProjectManagerClearRecentProjects(sublime_plugin.WindowCommand):

def run(self):
self.manager = Manager(self.window)
self.manager.clear_recent_projects()
sublime.status_message("Recent Projects cleared.")


class ProjectManager(sublime_plugin.WindowCommand):

def show_quick_panel(self, items, on_done):
@@ -345,7 +371,17 @@ class ProjectManager(sublime_plugin.WindowCommand):
lambda: self.window.show_quick_panel(items, on_done),
10)

def run(self, action=None):
def run(self, action=None, caller=None):
if action is None:
self.show_options()
else:
self.caller = caller
callback = eval("self.on_" + action)
self.manager = Manager(self.window)
self.projects, display = self.manager.display_projects()
self.show_quick_panel(display, callback)

def show_options(self):
items = [
["Open Project", "Open project in the current window"],
["Open Project in New Window", "Open project in a new window"],
@@ -354,7 +390,8 @@ class ProjectManager(sublime_plugin.WindowCommand):
['Rename Project', "Rename project"],
["Remove Project", "Remove from Project Manager"],
["Add Project", "Add current folders to Project Manager"],
["Import Project", "Import current .sublime-project file"]
["Import Project", "Import current .sublime-project file"],
["Clear Recent Projects", "Clear Recent Projects"]
]
actions = ["switch", "new", "append", "edit", "rename", "remove"]

@@ -363,47 +400,17 @@ class ProjectManager(sublime_plugin.WindowCommand):
return
elif a <= 5:
self.window.run_command(
"project_manager_list_projects",
"project_manager",
args={"action": actions[a], "caller": "manager"}
)
elif a == 6:
self.window.run_command("project_manager_add_project")
elif a == 7:
self.window.run_command("project_manager_import_project")
elif a == 8:
self.window.run_command("project_manager_clear_recent_projects")

if action:
callback(action)
else:
self.show_quick_panel(items, callback)


class ProjectManagerAddProject(sublime_plugin.WindowCommand):

def run(self):
self.manager = Manager(self.window)
self.manager.add_project()


class ProjectManagerImportProject(sublime_plugin.WindowCommand):

def run(self):
self.manager = Manager(self.window)
self.manager.import_sublime_project()


class ProjectManagerListProjects(sublime_plugin.WindowCommand):

def show_quick_panel(self, items, on_done):
sublime.set_timeout(
lambda: self.window.show_quick_panel(items, on_done),
10)

def run(self, action, caller=None):
self.caller = caller
callback = eval("self.on_" + action)
self.manager = Manager(self.window)
self.projects, display = self.manager.display_projects()
self.show_quick_panel(display, callback)
self.show_quick_panel(items, callback)

def on_new(self, action):
if action >= 0:
@@ -445,4 +452,4 @@ class ProjectManagerListProjects(sublime_plugin.WindowCommand):

def on_cancel(self):
if self.caller == "manager":
self.window.run_command("project_manager", args={"action": 0})
self.window.run_command("project_manager")

Loading…
Cancel
Save