Skip to content

Commit

Permalink
Add setting to fallback to project directory when the 'current' defau…
Browse files Browse the repository at this point in the history
…lt cannot be resolved
  • Loading branch information
skuroda committed Dec 14, 2014
1 parent 643f89f commit dfccca2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion AdvancedNewFile.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,9 @@
"copy_default": "",

// Same as `rename_default`, but applied to cut to default command.
"cut_to_file_default": ""
"cut_to_file_default": "",

// If default_root is set to current, the project folder should be used as the default
// rather than the home directory.
"current_fallback_to_project": false
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ Same as `rename_default`, applied to copy command.

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

`current_fallback_to_project`:

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

### Project Specific Settings
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.

Expand Down
5 changes: 4 additions & 1 deletion advanced_new_file/anf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
APPEND_EXTENSION_ON_COPY_SETTING = "append_extension_on_copy"
COPY_DEFAULT_SETTING = "copy_default"
CUT_TO_FILE_DEFAULT_SETTING = "cut_to_file_default"
CURRENT_FALLBACK_TO_PROJECT_SETTING = "current_fallback_to_project"

SETTINGS = [
ALIAS_SETTING,
Expand Down Expand Up @@ -65,7 +66,9 @@
RELATIVE_FALLBACK_INDEX_SETTING,
APPEND_EXTENSION_ON_COPY_SETTING,
COPY_DEFAULT_SETTING,
CUT_TO_FILE_DEFAULT_SETTING
CUT_TO_FILE_DEFAULT_SETTING,
CURRENT_FALLBACK_TO_PROJECT_SETTING

]

NIX_ROOT_REGEX = r"^/"
Expand Down
7 changes: 6 additions & 1 deletion advanced_new_file/commands/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ def __parse_path_setting(self, setting, index_setting):
if filename is not None:
root = os.path.dirname(filename)
if root is None:
root = os.path.expanduser("~/")
if self.settings.get(CURRENT_FALLBACK_TO_PROJECT_SETTING, False):
folder_index = self.__validate_folder_index(0)
if folder_index == -1:
root = os.path.expanduser("~/")
else:
root = os.path.expanduser("~/")
elif setting == "project_folder":
folder_index = self.settings.get(index_setting)
folder_index = self.__validate_folder_index(folder_index)
Expand Down

0 comments on commit dfccca2

Please sign in to comment.