def on_done(self, old, new): item = SideBarItem(old, os.path.isdir(old)) try: if not item.move(new): sublime.error_message("Unable to move, destination exists.") self.run([old], new) return except: sublime.error_message("Unable to move:\n\n"+old+"\n\nto\n\n"+new) self.run([old], new) return SideBarProject().refresh();
def on_done(self, old, branch, leaf): self.window.run_command('hide_panel'); leaf = leaf.strip(); new = os.path.join(branch, leaf) item = SideBarItem(old, os.path.isdir(old)) try: if not item.move(new): sublime.error_message("Unable to rename, destination exists.") self.run([old], leaf) return except: sublime.error_message("Unable to rename:\n\n"+old+"\n\nto\n\n"+new) self.run([old], leaf) raise return SideBarProject().refresh();
def run(self, paths = []): item = SideBarItem(os.path.join(sublime.packages_path(), 'User', 'SideBarEnhancements', 'Open With', 'Side Bar.sublime-menu'), False) if not item.exists(): item.create() item.write("""[ {"id": "side-bar-files-open-with", "children": [ //application 1 { "caption": "Photoshop", "id": "side-bar-files-open-with-photoshop", "command": "side_bar_files_open_with", "args": { "paths": [], "application": "Adobe Photoshop CS5.app", // OSX "extensions":"psd|png|jpg|jpeg" //any file with these extensions } }, //separator {"caption":"-"}, //application 2 { "caption": "SeaMonkey", "id": "side-bar-files-open-with-seamonkey", "command": "side_bar_files_open_with", "args": { "paths": [], "application": "C:\\\\Archivos de programa\\\\SeaMonkey\\\\seamonkey.exe", // WINNT "extensions":"" //open all even folders } }, //application n { "caption": "Chrome", "id": "side-bar-files-open-with-chrome", "command": "side_bar_files_open_with", "args": { "paths": [], "application": "C:\\\\Documents and Settings\\\\tito\\\\ConfiguraciĆ³n local\\\\Datos de programa\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe", "extensions":".*" //any file with extension } }, {"caption":"-"} ] } ]"""); item.edit()
def on_done(self, paths, name): for item in SideBarSelection(paths).getSelectedDirectoriesOrDirnames(): item = SideBarItem(item.join(name), False) if item.exists(): sublime.error_message("Unable to create file, file or folder exists.") self.run(paths, name) return else: try: item.create() item.edit() except: sublime.error_message("Unable to create file:\n\n"+item.path()) self.run(paths, name) return SideBarProject().refresh();
def on_done(self, paths, name): for item in SideBarSelection(paths).getSelectedDirectoriesOrDirnames(): item = SideBarItem(item.join(name), True) if item.exists(): sublime.error_message("Unable to create folder, folder or file exists.") self.run(paths, name) return else: item.create() if not item.exists(): sublime.error_message("Unable to create folder:\n\n"+item.path()) self.run(paths, name) return SideBarProject().refresh();
def run(self, paths = [], in_parent = 'False'): s = sublime.load_settings("SideBarEnhancements/Clipboard.sublime-settings") cut = s.get('cut', '') copy = s.get('copy', '') if SideBarSelection(paths).len() > 0: if in_parent == 'False': location = SideBarSelection(paths).getSelectedItems()[0].path() else: location = SideBarSelection(paths).getSelectedDirectoriesOrDirnames()[0].dirname() if os.path.isdir(location) == False: location = SideBarItem(os.path.dirname(location), True) else: location = SideBarItem(location, True) if cut != '': cut = cut.split("\n") for path in cut: path = SideBarItem(path, os.path.isdir(path)) new = os.path.join(location.path(), path.name()) try: if not path.move(new): sublime.error_message("Unable to cut and paste, destination exists.") return except: sublime.error_message("Unable to move:\n\n"+path.path()+"\n\nto\n\n"+new) return if copy != '': copy = copy.split("\n") for path in copy: path = SideBarItem(path, os.path.isdir(path)) new = os.path.join(location.path(), path.name()) try: if not path.copy(new): sublime.error_message("Unable to copy and paste, destination exists.") return except: sublime.error_message("Unable to copy:\n\n"+path.path()+"\n\nto\n\n"+new) return cut = s.set('cut', '') SideBarProject().refresh();
def getSelectedRepos(self, items): repos = [] reposTemp = [] for item in items: original = item.path() while not os.path.exists(item.join('.git')): if item.dirname() == item.path(): break; item.path(item.dirname()) if os.path.exists(item.join('.git')): try: index = reposTemp.index(item.path()) except ValueError: reposTemp.append(item.path()) index = reposTemp.index(item.path()) repos.append(Object()) repos[index].repository = item repos[index].items = [] repos[index].items.append(SideBarItem(original, os.path.isdir(original))) return repos
def getSelectedItemsWithoutChildItems(self): self._obtainSelectionInformationExtended() items = [] for item in self._items_without_containing_child_items: items.append(SideBarItem(item, os.path.isdir(item))) return items
def _obtainSelectionInformationExtended(self): if not self._obtained_selection_information_extended: self._obtained_selection_information_extended = True self._directories = [] self._files = [] self._directories_or_dirnames = [] self._items_without_containing_child_items = [] _directories = [] _files = [] _directories_or_dirnames = [] _items_without_containing_child_items = [] for path in self._paths: if os.path.isdir(path): item = SideBarItem(path, True) if item.path() not in _directories: _directories.append(item.path()) self._directories.append(item) if item.path() not in _directories_or_dirnames: _directories_or_dirnames.append(item.path()) self._directories_or_dirnames.append(item) _items_without_containing_child_items = self._itemsWithoutContainingChildItems( _items_without_containing_child_items, item.path()) else: item = SideBarItem(path, False) if item.path() not in _files: _files.append(item.path()) self._files.append(item) _items_without_containing_child_items = self._itemsWithoutContainingChildItems( _items_without_containing_child_items, item.path()) item = SideBarItem(os.path.dirname(path), True) if item.path() not in _directories_or_dirnames: _directories_or_dirnames.append(item.path()) self._directories_or_dirnames.append(item) self._items_without_containing_child_items = _items_without_containing_child_items
def run( self, object, modal = False, background = False, refresh_funct_view = False, refresh_funct_command = False, refresh_funct_item = False, refresh_funct_to_status_bar = False, refresh_funct_title = False, refresh_funct_no_results = False, refresh_funct_syntax_file = False ): if not refresh_funct_view: pass else: object = Object() object.command = refresh_funct_command object.item = SideBarItem(refresh_funct_item, os.path.isdir(refresh_funct_item)) object.to_status_bar = refresh_funct_to_status_bar object.title = refresh_funct_title object.no_results = refresh_funct_no_results object.syntax_file = refresh_funct_syntax_file debug = False if debug: print '----------------------------------------------------------' print 'GIT:' print object.command print 'CWD:' print object.item.forCwdSystemPath() print 'PATH:' print object.item.forCwdSystemName() failed = False if sublime.platform() == 'windows': object.command = map(self.escapeCMDWindows, object.command) if sublime.platform() is not 'windows' and object.command[0] == 'git' and os.path.exists('/usr/local/git/bin'): object.command[0] = '/usr/local/git/bin/git' cwd = object.item.forCwdSystemPath() try: if sublime.platform() == 'windows': process = subprocess.Popen( #" ".join(object.command), object.command, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, universal_newlines=True) else: process = subprocess.Popen( object.command, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, universal_newlines=True) if background: if debug: print 'SUCCESS' print '----------------------------------------------------------' return True stdout, stderr = process.communicate() SideBarGit.last_stdout = str(stdout).rstrip() self.last_stdout = str(stdout).rstrip() stdout = stdout.strip() if stdout.find('fatal:') == 0 or stdout.find('error:') == 0 or stdout.find('Permission denied') == 0 or stderr: print 'FAILED' failed = True else: if debug: print 'SUCCESS' if stdout: if debug: print 'STDOUT' print stdout if stderr: print 'STDERR' print stderr except OSError as (errno, strerror): print 'FAILED' failed = True print errno print strerror SideBarGit.last_stdout = '' self.last_stdout = ''
def _obtainSelectionInformationExtended(self): if not self._obtained_selection_information_extended: self._obtained_selection_information_extended = True self._directories = [] self._files = [] self._directories_or_dirnames = [] self._items_without_containing_child_items = [] _directories = [] _files = [] _directories_or_dirnames = [] _items_without_containing_child_items = [] for path in self._paths: if os.path.isdir(path): item = SideBarItem(path, True) if item.path() not in _directories: _directories.append(item.path()) self._directories.append(item) if item.path() not in _directories_or_dirnames: _directories_or_dirnames.append(item.path()) self._directories_or_dirnames.append(item) _items_without_containing_child_items = self._itemsWithoutContainingChildItems(_items_without_containing_child_items, item.path()) else: item = SideBarItem(path, False) if item.path() not in _files: _files.append(item.path()) self._files.append(item) _items_without_containing_child_items = self._itemsWithoutContainingChildItems(_items_without_containing_child_items, item.path()) item = SideBarItem(os.path.dirname(path), True) if item.path() not in _directories_or_dirnames: _directories_or_dirnames.append(item.path()) self._directories_or_dirnames.append(item) self._items_without_containing_child_items = _items_without_containing_child_items