Skip to content

Commit be84395

Browse files
committed
Add default root setting for each command
1 parent 91ff807 commit be84395

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

AdvancedNewFile.sublime-settings

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,17 @@
160160

161161
// If a warning should be displayed when trying to overwrite an existing file using
162162
// the move command.
163-
"warn_overwrite_on_move": false
163+
"warn_overwrite_on_move": false,
164+
165+
// Same as `default_root` for new file commands. In addition to the valid values listed
166+
// for `default_root`, "default_root" will use the value for that setting.
167+
"new_file_default_root": "default_root",
168+
169+
// Same as `default_root` for rename file commands. In addition to the valid values listed
170+
// for `default_root`, "default_root" will use the value for that setting.
171+
"rename_file_default_root": "default_root",
172+
173+
// Same as `default_root` for copy file commands. In addition to the valid values listed
174+
// for `default_root`, "default_root" will use the value for that setting.
175+
"copy_file_default_root": "default_root"
164176
}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ If default_root is set to current, the project folder should be used as the defa
194194

195195
If a warning should be displayed when trying to overwrite an existing file using the move command.
196196

197+
`new_file_default_root`:
198+
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.
199+
200+
`rename_file_default_root`:
201+
Same as `default_root` for rename file commands. In addition to the valid values listed for `default_root`, "default_root" will use the value for that setting.
202+
203+
`copy_file_default_root`:
204+
Same as `default_root` for copy file commands. In addition to the valid values listed for `default_root`, "default_root" will use the value for that setting.
205+
197206
### Project Specific Settings
198207
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.
199208

advanced_new_file/anf_util.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
CUT_TO_FILE_DEFAULT_SETTING = "cut_to_file_default"
3636
CURRENT_FALLBACK_TO_PROJECT_SETTING = "current_fallback_to_project"
3737
WARN_OVERWRITE_ON_MOVE_SETTING = "warn_overwrite_on_move"
38+
NEW_FILE_DEFAULT_ROOT_SETTING = "new_file_default_root"
39+
RENAME_FILE_DEFAULT_ROOT_SETTING = "rename_file_default_root"
40+
COPY_FILE_DEFAULT_ROOT_SETTING = "copy_file_default_root"
41+
3842

3943
SETTINGS = [
4044
ALIAS_SETTING,
@@ -69,8 +73,10 @@
6973
COPY_DEFAULT_SETTING,
7074
CUT_TO_FILE_DEFAULT_SETTING,
7175
CURRENT_FALLBACK_TO_PROJECT_SETTING,
72-
WARN_OVERWRITE_ON_MOVE_SETTING
73-
76+
WARN_OVERWRITE_ON_MOVE_SETTING,
77+
NEW_FILE_DEFAULT_ROOT_SETTING,
78+
RENAME_FILE_DEFAULT_ROOT_SETTING,
79+
COPY_FILE_DEFAULT_ROOT_SETTING
7480
]
7581

7682
NIX_ROOT_REGEX = r"^/"

advanced_new_file/commands/command_base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, window):
3030
self.platform = NixPlatform()
3131

3232
def __generate_default_root(self):
33-
root_setting = self.settings.get(DEFAULT_ROOT_SETTING)
33+
root_setting = self._get_default_root()
3434
path, folder_index = self.__parse_path_setting(
3535
root_setting, DEFAULT_FOLDER_INDEX_SETTING)
3636
if path is None and folder_index is None:
@@ -433,6 +433,17 @@ def _find_open_file(self, file_name):
433433
return view
434434
return None
435435

436+
## Should be overridden by sub class
437+
def get_default_root_setting(self):
438+
return DEFAULT_ROOT_SETTING
439+
440+
def _get_default_root(self):
441+
root_setting_value = self.get_default_root_setting()
442+
root_setting = self.settings.get(root_setting_value)
443+
if root_setting == DEFAULT_ROOT_SETTING:
444+
return self.settings.get(DEFAULT_ROOT_SETTING)
445+
return root_setting
446+
436447
def test_split(s, comments=False, posix=True):
437448
is_str = False
438449
if type(s) is str:

advanced_new_file/commands/copy_file_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def get_status_prefix(self):
8686
def get_append_extension_setting(self):
8787
return APPEND_EXTENSION_ON_COPY_SETTING
8888

89+
def get_default_root_setting(self):
90+
return COPY_FILE_DEFAULT_ROOT_SETTING
91+
8992

9093
class AdvancedNewFileCopyAtCommand(sublime_plugin.WindowCommand):
9194
def run(self, files):

advanced_new_file/commands/move_file_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def _move_action(self, from_file, to_file):
120120
def get_status_prefix(self):
121121
return "Moving file to"
122122

123+
def get_default_root_setting(self):
124+
return RENAME_FILE_DEFAULT_ROOT_SETTING
125+
123126

124127
class AdvancedNewFileMoveAtCommand(sublime_plugin.WindowCommand):
125128
def run(self, files):

advanced_new_file/commands/new_file_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def update_status_message(self, creation_path):
116116
else:
117117
sublime.status_message("Creating file at %s" % creation_path)
118118

119+
def get_default_root_setting(self):
120+
return NEW_FILE_DEFAULT_ROOT_SETTING
121+
119122

120123
class AdvancedNewFileNewAtCommand(sublime_plugin.WindowCommand):
121124
def run(self, dirs):

0 commit comments

Comments
 (0)