Skip to content

Commit b8e8db0

Browse files
committed
Add option to prompt when overwriting existing files on move
1 parent dfccca2 commit b8e8db0

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

AdvancedNewFile.sublime-settings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,9 @@
156156

157157
// If default_root is set to current, the project folder should be used as the default
158158
// rather than the home directory.
159-
"current_fallback_to_project": false
159+
"current_fallback_to_project": false,
160+
161+
// If a warning should be displayed when trying to overwrite an existing file using
162+
// the move command.
163+
"warn_overwrite_on_move": false
160164
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ Same as `rename_default`, applied to cut to file command.
190190

191191
If default_root is set to current, the project folder should be used as the default rather than the home directory.
192192

193+
`warn_overwrite_on_move`:
194+
195+
If a warning should be displayed when trying to overwrite an existing file using the move command.
196+
193197
### Project Specific Settings
194198
All of the above settings can also be specified as part of the project specific settings. These values override any previous values set by higher level settings, with aliases being an exception. Alias settings will be merged with higher level configurations for alias. In addition, if the same alias exist for both default/user settings and project settings, the project setting will take precedence.
195199

advanced_new_file/anf_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
COPY_DEFAULT_SETTING = "copy_default"
3535
CUT_TO_FILE_DEFAULT_SETTING = "cut_to_file_default"
3636
CURRENT_FALLBACK_TO_PROJECT_SETTING = "current_fallback_to_project"
37+
WARN_OVERWRITE_ON_MOVE_SETTING = "warn_overwrite_on_move"
3738

3839
SETTINGS = [
3940
ALIAS_SETTING,
@@ -67,7 +68,8 @@
6768
APPEND_EXTENSION_ON_COPY_SETTING,
6869
COPY_DEFAULT_SETTING,
6970
CUT_TO_FILE_DEFAULT_SETTING,
70-
CURRENT_FALLBACK_TO_PROJECT_SETTING
71+
CURRENT_FALLBACK_TO_PROJECT_SETTING,
72+
WARN_OVERWRITE_ON_MOVE_SETTING
7173

7274
]
7375

advanced_new_file/commands/move_file_command.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def _rename_file(self, file_path):
5656

5757
window = self.window
5858
rename_filename = self.get_argument_name()
59+
if not self._try_prompt_if_dest_exists(file_path):
60+
return
5961
if rename_filename:
6062
self.move_from_argument(rename_filename, file_path)
6163
elif self.view is not None:
@@ -83,6 +85,15 @@ def move_from_view(self, source_view, target):
8385
self.move_file_from_disk(source, target)
8486
self.open_file(target)
8587

88+
def _try_prompt_if_dest_exists(self, target):
89+
if self.settings.get(WARN_OVERWRITE_ON_MOVE_SETTING, False):
90+
if (os.path.exists(target)):
91+
return sublime.ok_cancel_dialog(target + "already exists. " +
92+
"move will overwrite " +
93+
"existing file. Continue?")
94+
95+
return True
96+
8697
def move_file_from_disk(self, source, target):
8798
window = self.window
8899
self.view.run_command("save")

0 commit comments

Comments
 (0)