Permalink
Browse files

Paste runs threaded, allow to delete files with large filenames.

  • Loading branch information...
1 parent a532201 commit 126f6fc023816efc4da4beb856d79cea04679bb9 @titoBouzout committed Feb 2, 2014
Showing with 59 additions and 18 deletions.
  1. +11 −0 CHANGELOG
  2. +47 −17 SideBar.py
  3. +1 −1 sidebar/SideBarSelection.py
View
@@ -2,6 +2,17 @@
SideBarEnhancements Changelog:
+ .4
+
+ * paste now runs threaded.
+ * on windows delete files with big file names.
+
+ TODO
+
+ * Use a real clipboard integrated with the OS
+ * auto refresh proect folder every x time?
+ * duplicate, move, rename, delete threaded.
+
.3
* copy image cant' copy image sizes
View
@@ -1,6 +1,6 @@
# coding=utf8
import sublime, sublime_plugin
-import os
+import os, shutil
import threading, time
@@ -465,6 +465,31 @@ def is_enabled(self, paths = []):
class SideBarPasteCommand(sublime_plugin.WindowCommand):
def run(self, paths = [], in_parent = 'False', test = 'True', replace = 'False'):
+ SideBarPasteThread(paths, in_parent, test, replace).start()
+
+ def is_enabled(self, paths = [], in_parent = False):
+ s = sublime.load_settings("SideBarEnhancements/Clipboard.sublime-settings")
+ return s.get('cut', '') + s.get('copy', '') != '' and len(SideBarSelection(paths).getSelectedDirectoriesOrDirnames()) == 1
+
+ def is_visible(self, paths = [], in_parent = False):
+ if in_parent == 'True':
+ return not s.get('disabled_menuitem_paste_in_parent')
+ else:
+ return True
+
+class SideBarPasteThread(threading.Thread):
+ def __init__(self, paths = [], in_parent = 'False', test = 'True', replace = 'False'):
+ self.paths = paths
+ self.in_parent = in_parent
+ self.test = test
+ self.replace = replace
+ threading.Thread.__init__(self)
+
+ def run(self):
+ SideBarPasteCommand2(sublime_plugin.WindowCommand).run(self.paths, self.in_parent, self.test, self.replace)
+
+class SideBarPasteCommand2(sublime_plugin.WindowCommand):
+ def run(self, paths = [], in_parent = 'False', test = 'True', replace = 'False'):
s = sublime.load_settings("SideBarEnhancements/Clipboard.sublime-settings")
cut = s.get('cut', '')
@@ -524,7 +549,7 @@ def run(self, paths = [], in_parent = 'False', test = 'True', replace = 'False')
if test == 'True' and len(already_exists_paths):
self.confirm(paths, in_parent, already_exists_paths)
elif test == 'True' and not len(already_exists_paths):
- self.run(paths, in_parent, 'False', 'False')
+ SideBarPasteThread(paths, in_parent, 'False', 'False').start();
elif test == 'False':
cut = s.set('cut', '')
SideBarProject().refresh();
@@ -552,19 +577,9 @@ def confirm(self, paths, in_parent, data):
def on_done(self, paths, in_parent, result):
if result != -1:
if result == 0:
- self.run(paths, in_parent, 'False', 'True')
+ SideBarPasteThread(paths, in_parent, 'False', 'True').start()
else:
- self.run(paths, in_parent, 'False', 'False')
-
- def is_enabled(self, paths = [], in_parent = False):
- s = sublime.load_settings("SideBarEnhancements/Clipboard.sublime-settings")
- return s.get('cut', '') + s.get('copy', '') != '' and len(SideBarSelection(paths).getSelectedDirectoriesOrDirnames()) == 1
-
- def is_visible(self, paths = [], in_parent = False):
- if in_parent == 'True':
- return not s.get('disabled_menuitem_paste_in_parent')
- else:
- return True
+ SideBarPasteThread(paths, in_parent, 'False', 'False').start()
class SideBarCopyNameCommand(sublime_plugin.WindowCommand):
def run(self, paths = []):
@@ -1079,7 +1094,10 @@ def run(self, paths = [], confirmed = 'False'):
if s.get('close_affected_buffers_when_deleting_even_if_dirty', False):
item.closeViews()
if s.get('disable_send_to_trash', False):
- self.remove(item.path());
+ if sublime.platform() == 'windows':
+ self.remove('\\\\?\\'+item.path());
+ else:
+ self.remove(item.path());
else:
send2trash(item.path())
SideBarProject().refresh();
@@ -1121,7 +1139,10 @@ def on_done(self, old, new):
if s.get('close_affected_buffers_when_deleting_even_if_dirty', False):
item = SideBarItem(new, os.path.isdir(new))
item.closeViews()
- self.remove(new)
+ if sublime.platform() == 'windows':
+ self.remove('\\\\?\\'+new);
+ else:
+ self.remove(new)
SideBarProject().refresh();
def remove(self, path):
@@ -1149,9 +1170,18 @@ def remove_safe_file(self, path):
def remove_safe_dir(self, path):
if not SideBarSelection().isNone(path):
try:
- os.rmdir(path)
+ shutil.rmtree(path)
except:
print("Unable to remove folder:\n\n"+path)
+ if sublime.platform() == 'windows':
+ try:
+ shutil.rmtree(path)
+ except:
+ # raise error in case we were unable to delete.
+ if os.path.exists(path):
+ shutil.rmtree(path)
+ else:
+ pass
def is_enabled(self, paths = []):
return SideBarSelection(paths).len() > 0 and SideBarSelection(paths).hasProjectDirectories() == False
@@ -180,7 +180,7 @@ def _itemsWithoutContainingChildItems(self, items, item):
return new_list
def isNone(self, path):
- if path == None or path == '' or path == '.' or path == '..' or path == './' or path == '/' or path == '//' or path == '\\' or path == '\\\\' or path == '\\\\\\\\':
+ if path == None or path == '' or path == '.' or path == '..' or path == './' or path == '../' or path == '/' or path == '//' or path == '\\' or path == '\\\\' or path == '\\\\\\\\' or path == '\\\\?\\' or path == '\\\\?' or path == '\\\\\\\\?\\\\':
return True
else:
return False

0 comments on commit 126f6fc

Please sign in to comment.