Skip to content

Commit 81161ca

Browse files
committed
Move new file behavior to be command specific
1 parent 38db0e1 commit 81161ca

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

AdvancedNewFile.sublime-settings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,9 @@
172172

173173
// Same as `default_root` for copy file commands. In addition to the valid values listed
174174
// for `default_root`, "default_root" will use the value for that setting.
175-
"copy_file_default_root": "default_root"
175+
"copy_file_default_root": "default_root",
176+
177+
// On empty input of file name, execute an alternative action.
178+
// Currently only implemented for the new file command, which will open a new unnamed file.
179+
"empty_filename_action": false
176180
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ Same as `default_root` for rename file commands. In addition to the valid values
203203
`copy_file_default_root`:
204204
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.
205205

206+
`empty_filename_action`:
207+
On empty input of file name, execute an alternative action. Currently only implemented for the new file command, which will open a new unnamed file. Default value is `false`
208+
206209
### Project Specific Settings
207210
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.
208211

advanced_new_file/anf_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
NEW_FILE_DEFAULT_ROOT_SETTING = "new_file_default_root"
3939
RENAME_FILE_DEFAULT_ROOT_SETTING = "rename_file_default_root"
4040
COPY_FILE_DEFAULT_ROOT_SETTING = "copy_file_default_root"
41+
DEFAULT_NEW_FILE = "empty_filename_action"
4142

4243

4344
SETTINGS = [
@@ -76,7 +77,8 @@
7677
WARN_OVERWRITE_ON_MOVE_SETTING,
7778
NEW_FILE_DEFAULT_ROOT_SETTING,
7879
RENAME_FILE_DEFAULT_ROOT_SETTING,
79-
COPY_FILE_DEFAULT_ROOT_SETTING
80+
COPY_FILE_DEFAULT_ROOT_SETTING,
81+
DEFAULT_NEW_FILE
8082
]
8183

8284
NIX_ROOT_REGEX = r"^/"

advanced_new_file/commands/command_base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,14 @@ def update_status_message(self, creation_path):
301301
def entered_file_action(self, path):
302302
pass
303303

304+
def empty_file_action(self):
305+
pass
306+
304307
def on_done(self, input_string):
305308
if len(input_string) != 0:
306309
self.entered_filename(input_string)
307-
else:
308-
self.window.new_file()
310+
elif self.settings.get(DEFAULT_NEW_FILE, False):
311+
self.empty_file_action()
309312

310313
self.clear()
311314
self.refresh_sidebar()

advanced_new_file/commands/new_file_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def update_status_message(self, creation_path):
119119
def get_default_root_setting(self):
120120
return NEW_FILE_DEFAULT_ROOT_SETTING
121121

122+
def empty_file_action(self):
123+
self.window.new_file()
124+
122125

123126
class AdvancedNewFileNewAtCommand(sublime_plugin.WindowCommand):
124127
def run(self, dirs):

0 commit comments

Comments
 (0)