@@ -1010,6 +1010,53 @@ def on_done(self, old, branch, leaf):
10101010 def is_enabled (self , paths = []):
10111011 return SideBarSelection (paths ).len () == 1 and SideBarSelection (paths ).hasProjectDirectories () == False
10121012
1013+ class SideBarMassRenameCommand (sublime_plugin .WindowCommand ):
1014+ def run (self , paths = []):
1015+ import functools
1016+ Window ().run_command ('hide_panel' );
1017+ view = Window ().show_input_panel ("Find:" , '' , functools .partial (self .on_find , paths ), None , None )
1018+
1019+ def on_find (self , paths , find ):
1020+ if not find :
1021+ return
1022+ import functools
1023+ Window ().run_command ('hide_panel' );
1024+ view = Window ().show_input_panel ("Replace:" , '' , functools .partial (self .on_replace , paths , find ), None , None )
1025+
1026+ def on_replace (self , paths , find , replace ):
1027+ if not replace :
1028+ return
1029+ if find == '' or replace == '' :
1030+ return None
1031+ else :
1032+ to_rename_or_move = []
1033+ for item in SideBarSelection (paths ).getSelectedItemsWithoutChildItems ():
1034+ self .recurse (item .path (), to_rename_or_move )
1035+ print (to_rename_or_move )
1036+ to_rename_or_move .sort ()
1037+ to_rename_or_move .reverse ()
1038+ for item in to_rename_or_move :
1039+ if find in item :
1040+ origin = SideBarItem (item , os .path .isdir (item ))
1041+ destination = SideBarItem (origin .pathProject ()+ '' + origin .pathWithoutProject ().replace (find , replace ), os .path .isdir (item ))
1042+ origin .move (destination .path ());
1043+ SideBarProject ().refresh ();
1044+
1045+ def recurse (self , path , paths ):
1046+ if os .path .isfile (path ) or os .path .islink (path ):
1047+ paths .append (path )
1048+ else :
1049+ for content in os .listdir (path ):
1050+ file = os .path .join (path , content )
1051+ if os .path .isfile (file ) or os .path .islink (file ):
1052+ paths .append (file )
1053+ else :
1054+ self .recurse (file , paths )
1055+ paths .append (path )
1056+
1057+ def is_enabled (self , paths = []):
1058+ return SideBarSelection (paths ).len () > 0 and SideBarSelection (paths ).hasProjectDirectories () == False
1059+
10131060class SideBarMoveCommand (sublime_plugin .WindowCommand ):
10141061 def run (self , paths = [], new = False ):
10151062 import functools
0 commit comments