11# -*- encoding: utf-8 -*-
2+ import os
3+
4+ import sublime
5+
26from ..libs .input_for_path import InputForPath
3- from ..libs .sublimefunctions import *
4- from .appcommand import AppCommand
7+ from ..libs .sublimefunctions import (
8+ get_template ,
9+ refresh_sidebar ,
10+ transform_aliases ,
11+ )
12+ from ..libs .pathhelper import user_friendly
13+ from .fmcommand import FmWindowCommand
514
615
7- class FmCreaterCommand (AppCommand ):
16+ class FmCreaterCommand (FmWindowCommand ):
817 """Create folder(s)/files that might be required and the
918 final ones if it doesn't exists. Finaly, opens the file"""
1019
1120 def run (self , abspath , input_path ):
1221 input_path = user_friendly (input_path )
1322 if input_path [- 1 ] == "/" :
14- return makedirs (abspath , exist_ok = True )
23+ return os . makedirs (abspath , exist_ok = True )
1524 if not os .path .isfile (abspath ):
16- makedirs (os .path .dirname (abspath ), exist_ok = True )
25+ os . makedirs (os .path .dirname (abspath ), exist_ok = True )
1726 with open (abspath , "w" ) as fp :
1827 pass
1928 template = get_template (abspath )
2029 else :
2130 template = None
22- window = get_window ()
23- view = window .open_file (abspath )
24- settings = view .settings ()
31+
32+ settings = self .window .open_file (abspath ).settings ()
2533 if template :
2634 settings .set ("fm_insert_snippet_on_load" , template )
27- refresh_sidebar (settings , window )
28- if get_settings ().get ("reveal_in_sidebar" ):
35+
36+ refresh_sidebar (settings , self .window )
37+
38+ if self .settings .get ("reveal_in_sidebar" ):
2939 settings .set ("fm_reveal_in_sidebar" , True )
30- sublime .set_timeout_async (
31- lambda : window .run_command ("reveal_in_side_bar" ), 500
40+ sublime .set_timeout (
41+ lambda : self . window .run_command ("reveal_in_side_bar" ), 500
3242 )
3343
3444
35- class FmCreateCommand (AppCommand ):
45+ class FmCreateCommand (FmWindowCommand ):
3646 def run (
3747 self ,
3848 paths = None ,
3949 initial_text = "" ,
4050 start_with_browser = False ,
4151 no_browser_action = False ,
4252 ):
43- self . settings = get_settings ()
44- self . window = sublime . active_window ()
53+ view = self . window . active_view ()
54+
4555 self .index_folder_separator = self .settings .get ("index_folder_" + "separator" )
4656 self .default_index = self .settings .get ("default_index" )
4757
4858 self .folders = self .window .folders ()
4959
50- self .view = get_view ()
51-
5260 self .know_where_to_create_from = paths is not None
5361
5462 if paths is not None :
@@ -64,8 +72,8 @@ def run(
6472 # it is going to be interactive, so it'll be
6573 # understood from the input itself
6674 create_from = None
67- elif self . view .file_name () is not None :
68- create_from = os .path .dirname (self . view .file_name ())
75+ elif view .file_name () is not None :
76+ create_from = os .path .dirname (view .file_name ())
6977 self .know_where_to_create_from = True
7078 else :
7179 # from home
@@ -97,10 +105,12 @@ def on_change(self, input_path, path_to_create_choosed_from_browsing):
97105 splited_input = input_path .split (self .index_folder_separator , 1 )
98106 if len (splited_input ) == 1 :
99107 index = self .default_index
100- elif isdigit (splited_input [0 ]):
101- index = int (splited_input [0 ])
102108 else :
103- return None , input_path
109+ try :
110+ index = int (splited_input [0 ])
111+ except ValueError :
112+ return None , input_path
113+
104114 return self .folders [index ], splited_input [- 1 ]
105115 return "~" , input_path
106116
0 commit comments