Browse files

Add setting to specify what folder to use for root

  • Loading branch information...
1 parent bd82797 commit d3bfba175ed361e3e247829ed3e7962ebaebacd7 @skuroda committed Jan 14, 2013
Showing with 50 additions and 10 deletions.
  1. +26 −5 AdvancedNewFile.py
  2. +15 −4 AdvancedNewFile.sublime-settings
  3. +9 −1 README.md
View
31 AdvancedNewFile.py
@@ -11,10 +11,12 @@
"show_path",
"default_root",
"default_path",
+ "default_folder_index",
"os_specific_alias",
"ignore_case",
"alias_root",
- "alias_path"
+ "alias_path",
+ "alias_folder_index"
]
DEBUG = False
PLATFORM = sublime.platform().lower()
@@ -27,6 +29,7 @@
class AdvancedNewFileCommand(sublime_plugin.WindowCommand):
def run(self, is_python=False):
self.root = None
+ self.alias_root = None
self.top_level_split_char = ":"
self.is_python = is_python
self.view = self.window.active_view()
@@ -35,6 +38,8 @@ def run(self, is_python=False):
settings = get_settings(self.view)
self.aliases = self.get_aliases(settings)
self.show_path = settings.get("show_path")
+ self.default_folder_index = settings.get("default_folder_index")
+ self.alias_folder_index = settings.get("alias_folder_index")
default_root = self.get_default_root(settings.get("default_root"))
if default_root == "path":
self.root = os.path.expanduser(settings.get("default_path"))
@@ -53,11 +58,12 @@ def run(self, is_python=False):
if tmp != "":
path = tmp
- alias_root = self.get_default_root(settings.get("alias_root"))
+ alias_root = self.get_default_root(settings.get("alias_root"), True)
if alias_root == "path":
self.alias_root = os.path.expanduser(settings.get("alias_path"))
alias_root = ""
self.alias_root, tmp = self.split_path(alias_root, True)
+
# Get user input
self.show_filename_input(path)
@@ -70,15 +76,28 @@ def get_aliases(self, settings):
return aliases
- def get_default_root(self, string):
+ def get_default_root(self, string, is_alias=False):
root = ""
if string == "home":
root = "~/"
elif string == "current":
root = ":"
+ elif string == "project_folder":
+ if is_alias:
+ folder_index = self.alias_folder_index
+ else:
+ folder_index = self.default_folder_index
+ if len(self.window.folders()) <= folder_index:
+ if is_alias:
+ self.alias_folder_index = 0
+ else:
+ self.default_folder_index = 0
elif string == "top_folder":
- pass
+ if is_alias:
+ self.alias_folder_index = 0
+ else:
+ self.default_folder_index = 0
elif string == "path":
root = "path"
else:
@@ -108,9 +127,11 @@ def split_path(self, path="", is_alias=False):
elif root == None:
if is_alias:
root = self.alias_root
+ folder_index = self.alias_folder_index
else:
root = self.root
- root = root or self.window.folders()[0]
+ folder_index = self.default_folder_index
+ root = root or self.window.folders()[folder_index]
except IndexError:
root = os.path.expanduser("~")
if DEBUG:
View
19 AdvancedNewFile.sublime-settings
@@ -35,29 +35,40 @@
// This value specifies the default directory when using AdvancedNewFile.
// Note it must be one of these values:
- // top_folder - Default will be the top level folder in the window.
+ // project_folder - Default will be the folder index specified by the "default_folder_index" setting.
// current - Default will be the directory of the current view.
// home - Default will be the home folder (~/)
// path - Default will be defined by the setting "default_path"
// If the current view or top folder cannot be resolved, the home directory
// will be used.
- "default_root": "top_folder",
+ "default_root": "project_folder",
// A string specifying the default root to use. For this to be utilized,
// "default_root" must be set to "path"
"default_path": "~",
+ // An integer value representing a folder index to be used when "folder" is specified
+ // for "default_root". If an index outside of the range of existing folders is used,
+ // it will default to 0 (the top level folder).
+ "default_folder_index": 0,
+
+
// This value specifies the root that will be used when resolving relative paths
// defined in aliases. For more information about valid values, see "default_root".
- // Note that if "path" is used, "alias_path" must be set appropriately.
+ // Note that if "default_path" or "default_folder_index" is used,
+ // "alias_path" and "alias_folder_index" must be used for the respective entries.
"alias_root": "current",
// A string specifying the path to use for the alias root. For this to be
// utilized, "alias_root" must be set to "path"
"alias_path": "~",
+ // An integer value representing the folder index to use when "folder" is specified
+ // for "alias_root". If an index outside of the range of the existing folders is used,
+ // it will default to 0.
+ "alias_folder_index": 0,
+
// A boolean specifying if case should be ignored when building
// auto complete list.
"ignore_case": false
-
}
View
10 README.md
@@ -71,7 +71,7 @@ A boolean value used to determine if the path of the file to be created should b
This value is used to determine the default root when using AdvancedNewFile. It must be one of the following values:
-* `top_folder`- The default path will be the top level folder in the window. Note this is the Default value on a clean install.
+* `folder_index`- The default path will be the folder specified by the 'default_folder_index' setting.
* `current_view` - The default path will be the directory of the current active view.
* `home` - The default path will be your home directory.
* `path` - The default path will be defined by the setting `default_path`
@@ -82,6 +82,10 @@ If the current view's directory cannot be resolved, the top level folder in the
This path is used as the default if `path` has been specified for the setting `default_root`. This path should be absolute. If a relative path is specified, it will be relative to the AdvancedNewFile package directory.
+`default_folder_index`:
+
+An integer value representing a folder index to be used when "folder" is specified for "default_root". If an index outside of the range of existing folders is used, it will default to 0 (the top level folder).
+
`alias_root`:
This entry defines the root that will be used when resolving aliases defined as relative paths. For more information about valid entries, see `default_root`. Note that for path, `alias_path` will be specified.
@@ -90,6 +94,10 @@ This entry defines the root that will be used when resolving aliases defined as
This path is used as the default if `path` has been specified for the setting `alias_root`.
+`alias_folder_index`:
+
+An integer value representing the folder index to use when "folder" is specified for "alias_root". If an index outside of the range of the existing folders is used, it will default to 0.
+
`ignore_case`:
A boolean specifying if case should be ignored when building auto complete list.

0 comments on commit d3bfba1

Please sign in to comment.