Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some project related functions

  • Loading branch information...
commit 3e3e6648289418143f5156931d62b7a7c952c73a 1 parent 62bf587
@titoBouzout authored
Showing with 114 additions and 43 deletions.
  1. +31 −37 Side Bar.py
  2. +15 −5 Side Bar.sublime-menu
  3. +68 −1 SideBarProject.py
View
68 Side Bar.py
@@ -820,46 +820,40 @@ def run(self, paths = []):
def is_enabled(self, paths = []):
return len(paths) > 0
-#todo:
-class SideBarHideCommand(sublime_plugin.WindowCommand):
+class SideBarProjectOpenFileCommand(sublime_plugin.WindowCommand):
def run(self, paths = []):
- project = self.project()
- if project != '':
- self.hide(paths, project)
- else:
- import functools
- self.window.run_command('hide_panel');
- self.window.show_input_panel("Location of .sublime-project file?:", '', functools.partial(self.on_done, paths), None, None)
-
- def on_done(self, paths, project):
- if project != '':
- self.hide(paths, project)
- else:
- self.run(paths)
+ project = SideBarProject()
+ if project.hasOpenedProject():
+ SideBarItem(project.getProjectFile(), False).edit();
- def hide(self, paths, project):
- s = sublime.load_settings(project)
- print s.get('')
- if len(paths) > 1 :
- sublime.status_message("Items cut")
- else :
- sublime.status_message("Item cut")
+class SideBarProjectItemAddCommand(sublime_plugin.WindowCommand):
+ def run(self, paths = []):
+ project = SideBarProject()
+ if project.hasOpenedProject():
+ for item in SideBarSelection(paths).getSelectedDirectories():
+ project.rootAdd(item.path())
+ view = SideBarItem(project.getProjectFile(), False).edit();
+ sublime.active_window().focus_view(view)
+ sublime.set_timeout(lambda: sublime.active_window().run_command('save'), 250)
+ sublime.set_timeout(lambda: sublime.active_window().run_command('close'), 400)
- sublime.set_timeout(SideBarSelection().refreshSidebar, 1000)
+ def is_enabled(self, paths = []):
+ return False #SideBarSelection(paths).hasDirectories()
- def project(self, file = ''):
- import hashlib
- hash = ''
- for directory in sublime.active_window().folders():
- hash += directory
- hash = hashlib.md5(hash).hexdigest()
-
- s = sublime.load_settings("SideBarEnhancements/Projects.sublime-settings")
- project = s.get(hash, '')
- if project != '':
- return project
- else:
- return ''
+class SideBarProjectItemExcludeCommand(sublime_plugin.WindowCommand):
+ def run(self, paths = []):
+ project = SideBarProject()
+ if project.hasOpenedProject():
+ file = project.getProjectFile()
+ for item in SideBarSelection(paths).getSelectedItems():
+ if item.isDirectory():
+ project.excludeDirectory(item.path())
+ else:
+ project.excludeFile(item.path())
+ view = SideBarItem(file, False).edit();
+ sublime.active_window().focus_view(view)
+ sublime.set_timeout(lambda: sublime.active_window().run_command('save'), 250)
+ sublime.set_timeout(lambda: sublime.active_window().run_command('close'), 400)
def is_enabled(self, paths = []):
- return True
+ return False #len(paths) > 0
View
20 Side Bar.sublime-menu
@@ -83,10 +83,20 @@
{ "caption": "Delete", "id": "side-bar-delete", "command": "side_bar_delete", "args": {"paths": []} },
{ "caption": "-", "id": "side-bar-delete-separator" },
- /*
- { "caption": "Hide", "id": "side-bar-hide", "command": "side_bar_hide", "args": {"paths": []} },
- { "caption": "-", "id": "side-bar-hide-separator" },
- */
- { "caption": "Refresh", "id": "side-bar-refresh", "command": "refresh_folder_list" },
+
+ { "caption": "Project", "id": "side-bar-project",
+ "children":
+ [
+ { "caption": "Refresh", "id": "side-bar-refresh", "command": "refresh_folder_list" },
+ { "caption": "-", "id": "side-bar-refresh-separator" },
+ { "caption": "Open Project File", "id": "side-bar-project-open-file", "command": "side_bar_project_open_file", "args": {"paths": []} },
+ /*
+ I successfully added the following functions but I'm unable to reload the project file
+ */
+ { "caption": "-", "id": "side-bar-project-open-file-separator" },
+ { "caption": "Promote To Project Folder", "id": "side-bar-project-item-add", "command": "side_bar_project_item_add", "args": {"paths": []} },
+ { "caption": "Exclude From Project", "id": "side-bar-project-item-exclude", "command": "side_bar_project_item_exclude", "args": {"paths": []} }
+ ]
+ },
{ "caption": "-", "id": "side-bar-end-separator" }
]
View
69 SideBarProject.py
@@ -1,8 +1,75 @@
import sublime
+import re
+import os
class SideBarProject:
def getDirectories(self):
return sublime.active_window().folders()
- #def getProjectFile():
+ def hasOpenedProject(self):
+ return self.getProjectFile() != None
+
+ def getProjectFile(self):
+ import json
+ data = json.loads(file(os.path.normpath(os.path.join(sublime.packages_path(), '..', 'Settings', 'Session.sublime_session')), 'rb').read())
+ projects = data['workspaces']['recent_workspaces']
+ for project_file in projects:
+ project_file = re.sub(r'^/([^/])/', '\\1:/', project_file);
+ folders = json.loads(file(project_file, 'rb').read())['folders']
+ found_all = True
+ for directory in self.getDirectories():
+ found = False
+ for folder in folders:
+ folder_path = re.sub(r'^/([^/])/', '\\1:/', folder['path']);
+ if folder_path == directory.replace('\\', '/'):
+ found = True
+ break;
+ if found == False:
+ found_all = False
+ break;
+ if found_all:
+ return project_file
+ return None
+
+ def excludeDirectory(self, path):
+ import json
+ project_file = self.getProjectFile();
+ project = json.loads(file(project_file, 'rb').read())
+
+ path = re.sub(r'^([^/])\:/', '/\\1/', path.replace('\\', '/'))
+
+ for folder in project['folders']:
+ if path.find(folder['path']) == 0:
+ try:
+ folder['folder_exclude_patterns'].append(path.replace(folder['path']+'/', '', 1)+'/')
+ except:
+ folder['folder_exclude_patterns'] = [path.replace(folder['path']+'/', '', 1)+'/']
+ file(project_file, 'wb+').write(json.dumps(project, indent=1))
+ return
+
+ def excludeFile(self, path):
+ import json
+ project_file = self.getProjectFile();
+ project = json.loads(file(project_file, 'rb').read())
+
+ path = re.sub(r'^([^/])\:/', '/\\1/', path.replace('\\', '/'))
+
+ for folder in project['folders']:
+ if path.find(folder['path']) == 0:
+ try:
+ folder['file_exclude_patterns'].append(path.replace(folder['path']+'/', '', 1))
+ except:
+ folder['file_exclude_patterns'] = [path.replace(folder['path']+'/', '', 1)]
+ file(project_file, 'wb+').write(json.dumps(project, indent=1))
+ return
+
+ def rootAdd(self, path):
+ import json
+ project_file = self.getProjectFile();
+ project = json.loads(file(project_file, 'rb').read())
+
+ path = re.sub(r'^([^/])\:/', '/\\1/', path.replace('\\', '/'))
+ project['folders'].append({'path':path});
+
+ file(project_file, 'wb+').write(json.dumps(project, indent=1))
Please sign in to comment.
Something went wrong with that request. Please try again.