23
23
24
24
25
25
class AdvancedNewFileBase (object ):
26
- static_input_panel_view = None
27
-
28
26
def __init__ (self , window ):
29
27
super ()
30
28
self .window = window
@@ -270,6 +268,38 @@ def __translate_alias(self, path):
270
268
def input_panel_caption (self ):
271
269
return ""
272
270
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
+
273
303
def show_filename_input (self , initial ):
274
304
caption = self .input_panel_caption ()
275
305
@@ -286,8 +316,8 @@ def show_filename_input(self, initial):
286
316
self .input_panel_view .settings ().set ("anf_panel" , True )
287
317
if self .settings .get (CURSOR_BEFORE_EXTENSION_SETTING ):
288
318
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 )
291
321
292
322
def __update_filename_input (self , path_in ):
293
323
new_content = path_in
@@ -296,9 +326,9 @@ def __update_filename_input(self, path_in):
296
326
if self .view is not None :
297
327
self .view .erase_status ("AdvancedNewFile2" )
298
328
299
- input_view = AdvancedNewFileBase . static_input_panel_view
329
+ input_view = self . get_input_view ()
300
330
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 ()
302
332
new_content = self .completion_input (path_in .replace ("\n " , "" ).replace ("\t " , "" ), candidate )
303
333
elif path_in .endswith ("\n " ):
304
334
path_in = path_in .replace ("\n " , "" )
@@ -312,25 +342,41 @@ def __update_filename_input(self, path_in):
312
342
self .window .run_command ("hide_panel" , {"cancel" : True })
313
343
return
314
344
else :
315
- completion_list = self .completion . hint (path_in )
345
+ completion_list = self .get_completion_list (path_in )
316
346
if completion_list :
317
347
candidate = completion_list [0 ]
318
348
completion_list .remove (candidate )
319
349
else :
320
350
candidate = ''
321
351
322
-
323
352
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 )
325
357
if input_view and new_content != path_in :
326
358
input_view .run_command ("anf_replace" , {"content" : new_content })
327
359
else :
328
360
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
+
330
365
if self .settings .get (SHOW_PATH_SETTING , False ):
331
366
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 )
334
380
335
381
def completion_input (self , path_in , candidate ):
336
382
pattern = r"(.*[/\\:])(.*)"
@@ -403,7 +449,9 @@ def clear(self):
403
449
if self .view is not None :
404
450
self .view .erase_status ("AdvancedNewFile" )
405
451
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 ()
407
455
408
456
def create (self , filename ):
409
457
base , filename = os .path .split (filename )
@@ -455,7 +503,10 @@ def get_cursor_path(self):
455
503
break
456
504
if (re .match (".*string.quoted.double" , syntax ) or
457
505
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 ))
459
510
path = re .sub ('^"|\' ' , '' , re .sub ('"|\' $' , '' , path .strip ()))
460
511
break
461
512
@@ -507,9 +558,6 @@ def __place_cursor_before_extension(self, view):
507
558
cursors .clear ()
508
559
cursors .add (sublime .Region (initial_position , initial_position ))
509
560
510
- def get_status_line (self ):
511
- return self .view .get_status ("AdvancedNewFile" )
512
-
513
561
def update_status_message (self , creation_path ):
514
562
if self .view is not None :
515
563
self .view .set_status ("AdvancedNewFile" , creation_path )
@@ -522,25 +570,6 @@ def get_status_prefix(self):
522
570
def create_status_line (self , creation_path , candidate , completion_list ):
523
571
return creation_path + '|' + candidate + str (completion_list )
524
572
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
-
544
573
def next_candidate (self , candidate , completion_list ):
545
574
if candidate and completion_list :
546
575
# replace the candidate with the first, and append the old candidate to the last
0 commit comments