AdvancedNewFile icon indicating copy to clipboard operation
AdvancedNewFile copied to clipboard

Suggestion to inform users that default_root behaviour has changed.

Open btsai opened this issue 10 years ago • 5 comments

Hi Scott,

I just figured out that default_root: project_root no longer works, and that as of 1.5.1 you need to set up individual settings for default_root in for each of the new, move, copy commands:

new_file_default_root rename_file_default_root copy_file_default_root

https://github.com/skuroda/Sublime-AdvancedNewFile/commit/be84395c78a33bdcb552c4fc413bbfc0af5fbd2e#diff-0994d3f547d1105beb6a24ace4f44472R412

Here in command_base.py, could I suggest that you check for existence of the above keys in settings, and if not, then use the original default_root settings? This would allow the current installations to continue to work as is but allow fine tuning of roots if needed.

My Python has pretty much gone by the wayside as I haven't touched it since my 2 week stint last year, but something like this (excuse the Ruby-like code). I can't remember if self.settings.get returns nil or blank string, but something along these lines.

    def _get_default_root(self):
        root_setting_value = self.get_default_root_setting()
        root_setting = self.settings.get(root_setting_value) || self.settings.get(DEFAULT_ROOT_SETTING)
        if root_setting == DEFAULT_ROOT_SETTING:
            return self.settings.get(DEFAULT_ROOT_SETTING)
        return root_setting

Keep up the great work! I use ANF every single day I code!

Brian

btsai avatar Dec 27 '14 23:12 btsai

Did you mean "project_folder" for the setting. I believe I set the settings to default to the old default. I'll verify when i get back to my computer though. Was there a particular command you were having issues with or was it all of them. I believe the setting for failing back is "default_root" for the value.

skuroda avatar Dec 27 '14 23:12 skuroda

Ah, and perhaps update the Readme.md and the default AdvancedNewFile.sublime_settings.

Probably something along these lines?

sublime_settings:

    // These value specify the default directory when using AdvancedNewFile new, move, and copy commands.
    // Each command can define its own default root, and if not defined, will default to the "default_root" setting.
    //
    // Note it must be one of these values:
    //  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": "project_folder",
    "new_file_default_root": "project_folder",        // new file default root
    "rename_file_default_root": "project_folder",     // move file default root
    "copy_file_default_root": "project_folder",       // copy file default root

Readme.md

`default_root`:
`new_file_default_root`:
`rename_file_default_root`:
`copy_file_default_root`:

These value specify the default directory when using AdvancedNewFile new, move, and copy commands.  
Each command can define its own default root, and if not defined, will default to the "default_root" setting.  

The setting must be one of the following values:
* `project_folder`- The default path will be the folder specified by the 'default_folder_index' setting.
* `current` - 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`

Lastly, I honestly hadn't been able to figure out what this setting does / means from the current description.

`` // 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,


I'm probably thicker than most, so I had to read through command_base.py and then look up .folders() on the Sublime API page (yeah, even though I used it last year, I forgot what it returned). I think maybe a description like this would be helpful for your users:

// When 'project_folder' is specified for a default_root, you can specify which folder in your project to use.
// If your project only has one folder added, use '0'.
// If your project has multiple folders, use the 0-based index of your desired folder.
// 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,

Thanks again and Happy New Year,

Brian

btsai avatar Dec 27 '14 23:12 btsai

Hi Scott,

The command i constantly use is 'new', and all of a sudden it stopped rooting at the project level, but instead defaulted to ~.

When discovered you had put out 1.5.1 and I looked through your commits, I came to the above realization. Then I set 'project_folder' as the 'new_file_default_root' setting and it works fine now.

Cheers,

btsai avatar Dec 27 '14 23:12 btsai

Hmm unsure why it fell back to home. That should only happen if there it can't resolve. Anyways, I'll be sure to update the readme. Documentation isn't a strong suit for me, so thanks for the recommendation. Glad the plugin has been making things easier for you. Happy new year to you too.

skuroda avatar Dec 27 '14 23:12 skuroda

Ah, I see you did put something into the update readme, for some reason that didn't show up on mine, or else I closed it without noticing.

If it defaults to default_root when there are no subclass settings, then no worries, that would be a good expected behaviour.

Cheers,

btsai avatar Dec 27 '14 23:12 btsai