@@ -388,66 +388,73 @@ def cb(index):
388388 Window ().show_quick_panel (history .all (), cb )
389389
390390
391- # class StSaveQuery(WindowCommand):
392- # @staticmethod
393- # def run():
394- # STM.Storage.promptQueryAlias()
395-
396-
397- # class StListQueries(WindowCommand):
398- # @staticmethod
399- # def run(mode="run"):
400- # if not ST.conn:
401- # ST.selectConnection()
402- # return
403-
404- # queries = STM.Storage.getSavedQueries().get('queries')
405-
406- # if len(queries) == 0:
407- # sublime.message_dialog('No saved queries.')
408- # return
409-
410- # options = []
411- # for alias, query in queries.items():
412- # options.append([alias, query])
413- # options.sort()
414-
415- # def cb(index):
416- # if index < 0:
417- # return None
418-
419- # param2 = output if mode == "run" else options[index][0]
420- # func = ST.conn.execute if mode == "run" else ST.toNewTab
421- # return func(options[index][1], param2)
422-
423- # try:
424- # Window().show_quick_panel(options, cb)
425- # except Exception:
426- # pass
427-
428-
429- # class StRemoveSavedQuery(WindowCommand):
430- # @staticmethod
431- # def run():
432- # queries = STM.Storage.getSavedQueries().get('queries')
433-
434- # if len(queries) == 0:
435- # sublime.message_dialog('No saved queries.')
436- # return
437-
438- # queriesArray = []
439- # for alias, query in queries.items():
440- # queriesArray.append([alias, query])
441- # queriesArray.sort()
442-
443- # def cb(index):
444- # if index < 0:
445- # return None
446- # return STM.Storage.removeQuery(queriesArray[index][0])
447- # try:
448- # Window().show_quick_panel(queriesArray, cb)
449- # except Exception:
450- # pass
391+ class StSaveQuery (WindowCommand ):
392+ @staticmethod
393+ def run ():
394+ query = getSelection ()
395+
396+ def cb (alias ):
397+ queries .add (alias , query )
398+ Window ().show_input_panel ('Query alias' , '' , cb , None , None )
399+
400+
401+ class StListQueries (WindowCommand ):
402+ @staticmethod
403+ def run (mode = "run" ):
404+ if not ST .conn :
405+ ST .selectConnection (functionsCallback = lambda : Window ().run_command ('st_list_queries' ))
406+ return
407+
408+ queriesList = queries .all ()
409+ if len (queriesList ) == 0 :
410+ sublime .message_dialog ('No saved queries.' )
411+ return
412+
413+ options = []
414+ for alias , query in queriesList .items ():
415+ options .append ([str (alias ), str (query )])
416+ options .sort ()
417+
418+ def cb (index ):
419+ if index < 0 :
420+ return None
421+
422+ param2 = output if mode == "run" else options [index ][0 ]
423+ func = ST .conn .execute if mode == "run" else ST .toNewTab
424+ return func (options [index ][1 ], param2 )
425+
426+ try :
427+ Window ().show_quick_panel (options , cb )
428+ except Exception :
429+ pass
430+
431+
432+ class StRemoveSavedQuery (WindowCommand ):
433+ @staticmethod
434+ def run ():
435+ if not ST .conn :
436+ ST .selectConnection (functionsCallback = lambda : Window ().run_command ('st_remove_saved_query' ))
437+ return
438+
439+ queriesList = queries .all ()
440+ if len (queriesList ) == 0 :
441+ sublime .message_dialog ('No saved queries.' )
442+ return
443+
444+ options = []
445+ for alias , query in queriesList .items ():
446+ options .append ([str (alias ), str (query )])
447+ options .sort ()
448+
449+ def cb (index ):
450+ if index < 0 :
451+ return None
452+
453+ return queries .delete (options [index ][0 ])
454+ try :
455+ Window ().show_quick_panel (options , cb )
456+ except Exception :
457+ pass
451458
452459
453460def Window ():
0 commit comments