Skip to content

Commit dfccca2

Browse files
committed
Add setting to fallback to project directory when the 'current' default cannot be resolved
1 parent 643f89f commit dfccca2

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

AdvancedNewFile.sublime-settings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,9 @@
152152
"copy_default": "",
153153

154154
// Same as `rename_default`, but applied to cut to default command.
155-
"cut_to_file_default": ""
155+
"cut_to_file_default": "",
156+
157+
// If default_root is set to current, the project folder should be used as the default
158+
// rather than the home directory.
159+
"current_fallback_to_project": false
156160
}

README.md

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

187187
Same as `rename_default`, applied to cut to file command.
188188

189+
`current_fallback_to_project`:
190+
191+
If default_root is set to current, the project folder should be used as the default rather than the home directory.
192+
189193
### Project Specific Settings
190194
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.
191195

advanced_new_file/anf_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
APPEND_EXTENSION_ON_COPY_SETTING = "append_extension_on_copy"
3434
COPY_DEFAULT_SETTING = "copy_default"
3535
CUT_TO_FILE_DEFAULT_SETTING = "cut_to_file_default"
36+
CURRENT_FALLBACK_TO_PROJECT_SETTING = "current_fallback_to_project"
3637

3738
SETTINGS = [
3839
ALIAS_SETTING,
@@ -65,7 +66,9 @@
6566
RELATIVE_FALLBACK_INDEX_SETTING,
6667
APPEND_EXTENSION_ON_COPY_SETTING,
6768
COPY_DEFAULT_SETTING,
68-
CUT_TO_FILE_DEFAULT_SETTING
69+
CUT_TO_FILE_DEFAULT_SETTING,
70+
CURRENT_FALLBACK_TO_PROJECT_SETTING
71+
6972
]
7073

7174
NIX_ROOT_REGEX = r"^/"

advanced_new_file/commands/command_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ def __parse_path_setting(self, setting, index_setting):
106106
if filename is not None:
107107
root = os.path.dirname(filename)
108108
if root is None:
109-
root = os.path.expanduser("~/")
109+
if self.settings.get(CURRENT_FALLBACK_TO_PROJECT_SETTING, False):
110+
folder_index = self.__validate_folder_index(0)
111+
if folder_index == -1:
112+
root = os.path.expanduser("~/")
113+
else:
114+
root = os.path.expanduser("~/")
110115
elif setting == "project_folder":
111116
folder_index = self.settings.get(index_setting)
112117
folder_index = self.__validate_folder_index(folder_index)

0 commit comments

Comments
 (0)