Skip to content

Commit dbdaaff

Browse files
committed
Feature request added -> #146
1 parent db45a1c commit dbdaaff

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎Side Bar.sublime-menu‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
{ "caption": "In Project Folders…", "id": "side-bar-find-project-folders", "command": "side_bar_find_in_project_folders"},
3636
{ "caption": "-", "id": "side-bar-find-project-separator"},
3737
{ "id": "side-bar-find-in-files-with-extension", "command": "side_bar_find_in_files_with_extension", "args": {"paths": []}},
38-
{ "caption": "In Paths Containing…", "id": "side-bar-find-files-path-containing", "command": "side_bar_find_files_path_containing", "args": {"paths": []} }
38+
{ "caption": "In Paths Containing…", "id": "side-bar-find-files-path-containing", "command": "side_bar_find_files_path_containing", "args": {"paths": []} },
39+
{ "caption": "Mass rename selection…", "id": "side-bar-mass-rename", "command": "side_bar_mass_rename", "args": {"paths": []} }
3940

4041
]
4142
},

‎SideBar.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
10131060
class SideBarMoveCommand(sublime_plugin.WindowCommand):
10141061
def run(self, paths = [], new = False):
10151062
import functools

0 commit comments

Comments
 (0)