Permalink
Browse files

Add "empty" folder, feature requested by Emil Andersson

  • Loading branch information...
1 parent 505b242 commit 29e7bfca9717d063f458a8108895ae1b6ce254d6 @titoBouzout committed Dec 13, 2012
Showing with 55 additions and 0 deletions.
  1. +1 −0 Side Bar.sublime-menu
  2. +1 −0 Side Bar.sublime-settings
  3. +53 −0 SideBar.py
@@ -93,6 +93,7 @@
{ "caption": "-", "id": "side-bar-rename-move-separator" },
{ "caption": "Delete", "id": "side-bar-delete", "command": "side_bar_delete", "args": {"paths": []} },
+ { "caption": "Empty", "id": "side-bar-emptry", "command": "side_bar_empty", "args": {"paths": []} },
{ "caption": "-", "id": "side-bar-delete-separator" },
{ "caption": "Refresh", "id": "side-bar-refresh", "command": "refresh_folder_list" },
@@ -21,6 +21,7 @@
"disabled_menuitem_copy_path": false,
"disabled_menuitem_copy_dir_path": true,
"disabled_menuitem_paste_in_parent": false,
+ "disabled_menuitem_empty": true,
//if installed in a default location maybe this works.
"default_browser": "chrome" //one of this list: firefox, chrome, chromium, opera, safari
View
@@ -1128,6 +1128,59 @@ def remove_safe_dir(self, path):
def is_enabled(self, paths = []):
return SideBarSelection(paths).len() > 0 and SideBarSelection(paths).hasProjectDirectories() == False
+
+class SideBarEmptyCommand(sublime_plugin.WindowCommand):
+ def run(self, paths = [], confirmed = 'False'):
+
+ if confirmed == 'False' and s.get('confirm_before_deleting', True):
+ if sublime.platform() == 'osx':
+ if sublime.ok_cancel_dialog('empty the content of the folder?'):
+ self.run(paths, 'True')
+ else:
+ self.confirm([item.path() for item in SideBarSelection(paths).getSelectedDirectoriesOrDirnames()], [item.pathWithoutProject() for item in SideBarSelection(paths).getSelectedDirectoriesOrDirnames()])
+ else:
+ try:
+ for item in SideBarSelection(paths).getSelectedDirectoriesOrDirnames():
+ for content in os.listdir(item.path()):
+ file = os.path.join(item.path(), content)
+ if not SideBarSelection().isNone(file):
+ send2trash(file)
+ if s.get('close_affected_buffers_when_deleting_even_if_dirty', False):
+ item.close_associated_buffers()
+ except:
+ pass
+ SideBarProject().refresh();
+
+ def confirm(self, paths, display_paths):
+ import functools
+ window = sublime.active_window()
+ window.show_input_panel("BUG!", '', '', None, None)
+ window.run_command('hide_panel');
+
+ yes = []
+ yes.append('Yes, empty the selected items.');
+ for item in display_paths:
+ yes.append(item);
+
+ no = []
+ no.append('No');
+ no.append('Cancel the operation.');
+ if sublime.platform() == 'osx':
+ sublime.set_timeout(lambda:window.show_quick_panel([yes, no], functools.partial(self.on_confirm, paths)), 200);
+ else:
+ window.show_quick_panel([yes, no], functools.partial(self.on_confirm, paths))
+
+ def on_confirm(self, paths, result):
+ if result != -1:
+ if result == 0:
+ self.run(paths, 'True')
+
+ def is_enabled(self, paths = []):
+ return SideBarSelection(paths).len() > 0
+
+ def is_visible(self, paths =[]):
+ return not s.get('disabled_menuitem_empty')
+
class SideBarRevealCommand(sublime_plugin.WindowCommand):
def run(self, paths = []):
for item in SideBarSelection(paths).getSelectedItems():

0 comments on commit 29e7bfc

Please sign in to comment.