From 492cf24cae01cc48751e25e66babe917867ef4b3 Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Sat, 18 Jan 2020 14:59:06 +1100 Subject: [PATCH] rename: use default command instead of custom one The slight problem is that if we don't disable the default command, then it shows up before the `New` command, which isn't right. So, instead, we enable the default (rename_path), but hide it (is_visible() -> False). Then, we create our own little command (fm_rename_path) that calls rename_path. Like this, we control where fm_rename_path shows up in the context menu. File Manager: Rename has been removed from the command palette (use Rename File). fm_rename now prints a deprecation warning. We don't use Python's warning module because warnings aren't enabled by default, and I don't want to change the defaults for everyone. ref #49 --- FileManager.sublime-commands | 4 ---- FileManager.sublime-settings | 1 + Side Bar.sublime-menu | 2 +- commands/rename.py | 11 +++++++++++ prevent_default.py | 6 ++---- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/FileManager.sublime-commands b/FileManager.sublime-commands index f5f4ebd..77d898b 100644 --- a/FileManager.sublime-commands +++ b/FileManager.sublime-commands @@ -3,10 +3,6 @@ "caption": "File Manager: New File", "command": "fm_create" }, - { - "caption": "File Manager: Rename", - "command": "fm_rename" - }, { "caption": "File Manager: Move", "command": "fm_move" diff --git a/FileManager.sublime-settings b/FileManager.sublime-settings index 330c107..74b3133 100644 --- a/FileManager.sublime-settings +++ b/FileManager.sublime-settings @@ -108,6 +108,7 @@ "show_open_in_browser_command": true, "show_open_terminal_command": true, "show_rename_command": true, + "show_rename_path_command": true, "show_create_from_selection_command": true, "show_open_all_command": true, diff --git a/Side Bar.sublime-menu b/Side Bar.sublime-menu index e12db1c..97631a6 100644 --- a/Side Bar.sublime-menu +++ b/Side Bar.sublime-menu @@ -34,7 +34,7 @@ { "caption": "Rename...", "mnemonic": "R", - "command": "fm_rename", + "command": "fm_rename_path", "args": { "paths": [] } diff --git a/commands/rename.py b/commands/rename.py index a654598..cbf7c0e 100644 --- a/commands/rename.py +++ b/commands/rename.py @@ -6,8 +6,19 @@ from .appcommand import AppCommand +class FmRenamePathCommand(AppCommand): + def run(self, paths): + sublime.active_window().run_command("rename_path", {"paths": paths}) + + class FmRenameCommand(AppCommand): def run(self, paths=None): + print( + "fm_rename has been deprecated. It doesn't provide any more useful feature " + "than the default command. You should use rename_path (for a " + "file or a folder) or rename_file (for a file) instead." + ) + sublime.status_message("fm_rename has been deprecated (see console)") self.settings = get_settings() self.window = get_window() self.view = self.window.active_view() diff --git a/prevent_default.py b/prevent_default.py index 0e172d0..928e71a 100644 --- a/prevent_default.py +++ b/prevent_default.py @@ -1,4 +1,5 @@ import sublime_plugin +from Default.side_bar import RenamePathCommand class NewFileAtCommand(sublime_plugin.WindowCommand): @@ -33,13 +34,10 @@ def is_enabled(self): return False -class RenamePathCommand(sublime_plugin.WindowCommand): +class RenamePathCommand(RenamePathCommand): def is_visible(self): return False - def is_enabled(self): - return False - class FindInFolderCommand(sublime_plugin.WindowCommand): def is_visible(self):