diff --git a/Side Bar.sublime-menu b/Side Bar.sublime-menu index 2080e3196..139c94ed6 100644 --- a/Side Bar.sublime-menu +++ b/Side Bar.sublime-menu @@ -35,7 +35,8 @@ { "caption": "In Project Folders…", "id": "side-bar-find-project-folders", "command": "side_bar_find_in_project_folders"}, { "caption": "-", "id": "side-bar-find-project-separator"}, { "id": "side-bar-find-in-files-with-extension", "command": "side_bar_find_in_files_with_extension", "args": {"paths": []}}, - { "caption": "In Paths Containing…", "id": "side-bar-find-files-path-containing", "command": "side_bar_find_files_path_containing", "args": {"paths": []} } + { "caption": "In Paths Containing…", "id": "side-bar-find-files-path-containing", "command": "side_bar_find_files_path_containing", "args": {"paths": []} }, + { "caption": "Mass rename selection…", "id": "side-bar-mass-rename", "command": "side_bar_mass_rename", "args": {"paths": []} } ] }, diff --git a/SideBar.py b/SideBar.py index 4a5353680..df36589d0 100755 --- a/SideBar.py +++ b/SideBar.py @@ -1010,6 +1010,53 @@ def on_done(self, old, branch, leaf): def is_enabled(self, paths = []): return SideBarSelection(paths).len() == 1 and SideBarSelection(paths).hasProjectDirectories() == False +class SideBarMassRenameCommand(sublime_plugin.WindowCommand): + def run(self, paths = []): + import functools + Window().run_command('hide_panel'); + view = Window().show_input_panel("Find:", '', functools.partial(self.on_find, paths), None, None) + + def on_find(self, paths, find): + if not find: + return + import functools + Window().run_command('hide_panel'); + view = Window().show_input_panel("Replace:", '', functools.partial(self.on_replace, paths, find), None, None) + + def on_replace(self, paths, find, replace): + if not replace: + return + if find == '' or replace == '': + return None + else: + to_rename_or_move = [] + for item in SideBarSelection(paths).getSelectedItemsWithoutChildItems(): + self.recurse(item.path(), to_rename_or_move) + print(to_rename_or_move) + to_rename_or_move.sort() + to_rename_or_move.reverse() + for item in to_rename_or_move: + if find in item: + origin = SideBarItem(item, os.path.isdir(item)) + destination = SideBarItem(origin.pathProject()+''+origin.pathWithoutProject().replace(find, replace), os.path.isdir(item)) + origin.move(destination.path()); + SideBarProject().refresh(); + + def recurse(self, path, paths): + if os.path.isfile(path) or os.path.islink(path): + paths.append(path) + else: + for content in os.listdir(path): + file = os.path.join(path, content) + if os.path.isfile(file) or os.path.islink(file): + paths.append(file) + else: + self.recurse(file, paths) + paths.append(path) + + def is_enabled(self, paths = []): + return SideBarSelection(paths).len() > 0 and SideBarSelection(paths).hasProjectDirectories() == False + class SideBarMoveCommand(sublime_plugin.WindowCommand): def run(self, paths = [], new = False): import functools