2323
2424
2525class AdvancedNewFileBase (object ):
26- static_input_panel_view = None
27-
2826 def __init__ (self , window ):
2927 super ()
3028 self .window = window
@@ -270,6 +268,38 @@ def __translate_alias(self, path):
270268 def input_panel_caption (self ):
271269 return ""
272270
271+ def get_active_window_settings (self ):
272+ return sublime .active_window ().settings ()
273+
274+ def set_input_view (self , input_view ):
275+ self .get_active_window_settings ().set ("anf_input_view" , input_view .id ())
276+
277+ def get_input_view (self ):
278+ return sublime .View (self .get_active_window_settings ().get ("anf_input_view" ))
279+
280+
281+ def get_active_view_settings (self ):
282+ view = self .get_input_view ()
283+ if view :
284+ return view .settings ()
285+ else :
286+ return self .get_active_window_settings ()
287+
288+ def clear_input_view (self ):
289+ self .get_active_view_settings ().erase ("anf_input_view" )
290+
291+ def set_input_view_content (self , content ):
292+ self .get_active_view_settings ().set ("anf_input_view_content" , content )
293+
294+ def get_input_view_content (self ):
295+ return self .get_active_view_settings ().get ("anf_input_view_content" )
296+
297+ def clear_input_view_content (self ):
298+ self .get_active_view_settings ().erase ("anf_input_view_content" )
299+
300+ def clear_input_view_project_files (self ):
301+ self .get_active_view_settings ().erase ("anf_input_view_project_files" )
302+
273303 def show_filename_input (self , initial ):
274304 caption = self .input_panel_caption ()
275305
@@ -286,8 +316,8 @@ def show_filename_input(self, initial):
286316 self .input_panel_view .settings ().set ("anf_panel" , True )
287317 if self .settings .get (CURSOR_BEFORE_EXTENSION_SETTING ):
288318 self .__place_cursor_before_extension (self .input_panel_view )
289- AdvancedNewFileBase . static_input_panel_view = self .input_panel_view
290- self .__update_filename_input ('' )
319+ self . set_input_view ( self .input_panel_view )
320+ self .__update_filename_input (initial )
291321
292322 def __update_filename_input (self , path_in ):
293323 new_content = path_in
@@ -296,9 +326,9 @@ def __update_filename_input(self, path_in):
296326 if self .view is not None :
297327 self .view .erase_status ("AdvancedNewFile2" )
298328
299- input_view = AdvancedNewFileBase . static_input_panel_view
329+ input_view = self . get_input_view ()
300330 if path_in .endswith ("\t " ):
301- creation_path , candidate , completion_list = self .parse_status_line ( self . get_status_line ()) # type: ignore
331+ creation_path , candidate , completion_list = self .get_input_view_content ()
302332 new_content = self .completion_input (path_in .replace ("\n " , "" ).replace ("\t " , "" ), candidate )
303333 elif path_in .endswith ("\n " ):
304334 path_in = path_in .replace ("\n " , "" )
@@ -312,25 +342,41 @@ def __update_filename_input(self, path_in):
312342 self .window .run_command ("hide_panel" , {"cancel" : True })
313343 return
314344 else :
315- completion_list = self .completion . hint (path_in )
345+ completion_list = self .get_completion_list (path_in )
316346 if completion_list :
317347 candidate = completion_list [0 ]
318348 completion_list .remove (candidate )
319349 else :
320350 candidate = ''
321351
322-
323352 if input_view :
324- input_view .hide_popup ()
353+ try :
354+ input_view .hide_popup ()
355+ except Exception as e :
356+ print ("hide_popup" , e )
325357 if input_view and new_content != path_in :
326358 input_view .run_command ("anf_replace" , {"content" : new_content })
327359 else :
328360 base , path = self .split_path (path_in )
329- status_line = generate_creation_path (self .settings , base , path , True ) + '|' + candidate + str (completion_list )
361+ creation_path = generate_creation_path (self .settings , base , path , True )
362+ status_line = self .create_status_line (creation_path , candidate , completion_list )
363+ self .set_input_view_content ((creation_path , candidate , completion_list ))
364+
330365 if self .settings .get (SHOW_PATH_SETTING , False ):
331366 self .update_status_message (status_line )
332- if input_view and candidate and not new_content .endswith (candidate ):
333- input_view .show_popup ('<strong>' + candidate + '</strong><br/>' + '<br/>' .join (completion_list ))
367+ if not new_content .endswith (candidate ):
368+ self .show_input_popup (candidate , completion_list )
369+
370+ def show_input_popup (self , candidate , completion_list ):
371+ try :
372+ input_view = self .get_input_view ()
373+ if input_view and candidate :
374+ input_view .show_popup ('<strong>' + candidate + '</strong><br/>' + '<br/>' .join (completion_list ), max_width = 1024 )
375+ except Exception as e :
376+ print ("show_popup" , e )
377+
378+ def get_completion_list (self , path_in ):
379+ return self .completion .complete_for_folder (path_in )
334380
335381 def completion_input (self , path_in , candidate ):
336382 pattern = r"(.*[/\\:])(.*)"
@@ -403,7 +449,9 @@ def clear(self):
403449 if self .view is not None :
404450 self .view .erase_status ("AdvancedNewFile" )
405451 self .view .erase_status ("AdvancedNewFile2" )
406- AdvancedNewFileBase .static_input_panel_view = None
452+ self .clear_input_view ()
453+ self .clear_input_view_content ()
454+ self .clear_input_view_project_files ()
407455
408456 def create (self , filename ):
409457 base , filename = os .path .split (filename )
@@ -455,7 +503,10 @@ def get_cursor_path(self):
455503 break
456504 if (re .match (".*string.quoted.double" , syntax ) or
457505 re .match (".*string.quoted.single" , syntax )):
458- path = view .substr (view .extract_scope (region .begin ()))
506+ point = region .begin ()
507+ if (re .match (".*punctuation.definition.string.end" , syntax )):
508+ point -= 1
509+ path = view .substr (view .extract_scope (point ))
459510 path = re .sub ('^"|\' ' , '' , re .sub ('"|\' $' , '' , path .strip ()))
460511 break
461512
@@ -507,9 +558,6 @@ def __place_cursor_before_extension(self, view):
507558 cursors .clear ()
508559 cursors .add (sublime .Region (initial_position , initial_position ))
509560
510- def get_status_line (self ):
511- return self .view .get_status ("AdvancedNewFile" )
512-
513561 def update_status_message (self , creation_path ):
514562 if self .view is not None :
515563 self .view .set_status ("AdvancedNewFile" , creation_path )
@@ -522,25 +570,6 @@ def get_status_prefix(self):
522570 def create_status_line (self , creation_path , candidate , completion_list ):
523571 return creation_path + '|' + candidate + str (completion_list )
524572
525- def parse_status_line (self , status_line ):
526- # Creating file at AdvancedNewFile/advanced_new_file/commands/|__init__.py['command_base.py']
527- if status_line :
528- status_line = status_line .strip ()
529- index1 = status_line .rindex ('[' )
530- completion_list = status_line [index1 :]
531- try :
532- completion_list = json .loads (completion_list .replace ("'" , '"' ))
533- except Exception as e :
534- print ("completion_list" , completion_list , e )
535- raise e
536- index2 = status_line .rindex ('|' )
537- candidate = status_line [index2 + 1 :index1 ]
538- # TODO: prefix_len = len(self.get_status_prefix())
539- creation_path = status_line [0 :index2 ]
540- return (creation_path , candidate , completion_list )
541- else :
542- return ('' , '' , [])
543-
544573 def next_candidate (self , candidate , completion_list ):
545574 if candidate and completion_list :
546575 # replace the candidate with the first, and append the old candidate to the last
0 commit comments