Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AdvancedNewFile.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
// the move command.
"warn_overwrite_on_move": false,

// If a warning should be displayed when trying to overwrite an existing file using
// the copy command.
"warn_overwrite_on_copy": false,

// Same as `default_root` for new file commands. In addition to the valid values listed
// for `default_root`, "default_root" will use the value for that setting.
"new_file_default_root": "default_root",
Expand Down
2 changes: 2 additions & 0 deletions advanced_new_file/anf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
COPY_DEFAULT_SETTING = "copy_default"
CUT_TO_FILE_DEFAULT_SETTING = "cut_to_file_default"
CURRENT_FALLBACK_TO_PROJECT_SETTING = "current_fallback_to_project"
WARN_OVERWRITE_ON_COPY_SETTING = "warn_overwrite_on_copy"
WARN_OVERWRITE_ON_MOVE_SETTING = "warn_overwrite_on_move"
NEW_FILE_DEFAULT_ROOT_SETTING = "new_file_default_root"
RENAME_FILE_DEFAULT_ROOT_SETTING = "rename_file_default_root"
Expand Down Expand Up @@ -77,6 +78,7 @@
COPY_DEFAULT_SETTING,
CUT_TO_FILE_DEFAULT_SETTING,
CURRENT_FALLBACK_TO_PROJECT_SETTING,
WARN_OVERWRITE_ON_COPY_SETTING,
WARN_OVERWRITE_ON_MOVE_SETTING,
NEW_FILE_DEFAULT_ROOT_SETTING,
RENAME_FILE_DEFAULT_ROOT_SETTING,
Expand Down
9 changes: 9 additions & 0 deletions advanced_new_file/commands/copy_file_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ def entered_file_action(self, path):
if copy_success:
self.open_file(new_file)

def _try_prompt_if_dest_exists(self, target):
if self.settings.get(WARN_OVERWRITE_ON_COPY_SETTING, False):
if (os.path.exists(target)):
return sublime.ok_cancel_dialog(target + " already exists. " +
"Copy will overwrite " +
"existing file. Continue?")

def _copy_file(self, path):
if os.path.isdir(path) or re.search(r"(/|\\)$", path):
# use original name if a directory path has been passed in.
path = os.path.join(path, self.original_name)

window = self.window
copied = True
if not self._try_prompt_if_dest_exists(path):
return (False, path)
if self.get_argument_name():
self.copy_from_argument(path)
elif self.view is not None:
Expand Down
4 changes: 2 additions & 2 deletions advanced_new_file/commands/move_file_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def move_from_view(self, source_view, target):
def _try_prompt_if_dest_exists(self, target):
if self.settings.get(WARN_OVERWRITE_ON_MOVE_SETTING, False):
if (os.path.exists(target)):
return sublime.ok_cancel_dialog(target + "already exists. " +
"move will overwrite " +
return sublime.ok_cancel_dialog(target + " already exists. " +
"Move will overwrite " +
"existing file. Continue?")

return True
Expand Down