|
1 | 1 | import sublime, sublime_plugin, sys, os |
2 | 2 |
|
3 | 3 | sys.path.append(os.path.dirname(__file__)) |
4 | | -from SQLToolsModels import Log, Settings, Connection, Selection, Window, View, Const, History |
| 4 | +from SQLToolsModels import Log, Settings, Connection, Selection, Window, View, Const, History, Storage |
5 | 5 |
|
6 | 6 | class ST(sublime_plugin.EventListener): |
7 | 7 | conn = None |
@@ -153,6 +153,50 @@ def run(self): |
153 | 153 | query = Selection.get() |
154 | 154 | ST.conn.execute(query, ST.display) |
155 | 155 |
|
| 156 | +class StSaveQuery(sublime_plugin.WindowCommand): |
| 157 | + def run(self): |
| 158 | + Storage.promptQueryAlias() |
| 159 | + |
| 160 | +class StListQueries(sublime_plugin.WindowCommand): |
| 161 | + def run(self): |
| 162 | + if not ST.conn: |
| 163 | + ST.showConnectionMenu() |
| 164 | + return |
| 165 | + |
| 166 | + queries = Storage.getSavedQueries().get('queries') |
| 167 | + |
| 168 | + if len(queries) == 0: |
| 169 | + sublime.message_dialog('No saved queries.') |
| 170 | + return |
| 171 | + |
| 172 | + queriesArray = [] |
| 173 | + for alias, query in queries.items(): |
| 174 | + print (alias, query) |
| 175 | + queriesArray.append([alias, query]) |
| 176 | + queriesArray.sort() |
| 177 | + try: |
| 178 | + Window().show_quick_panel(queriesArray, lambda index: ST.conn.execute(queriesArray[index][1], ST.display) if index != -1 else None) |
| 179 | + except Exception: |
| 180 | + pass |
| 181 | + |
| 182 | +class StRemoveSavedQuery(sublime_plugin.WindowCommand): |
| 183 | + def run(self): |
| 184 | + queries = Storage.getSavedQueries().get('queries') |
| 185 | + |
| 186 | + if len(queries) == 0: |
| 187 | + sublime.message_dialog('No saved queries.') |
| 188 | + return |
| 189 | + |
| 190 | + queriesArray = [] |
| 191 | + for alias, query in queries.items(): |
| 192 | + print (alias, query) |
| 193 | + queriesArray.append([alias, query]) |
| 194 | + queriesArray.sort() |
| 195 | + try: |
| 196 | + Window().show_quick_panel(queriesArray, lambda index: Storage.removeQuery(queriesArray[index][0]) if index != -1 else None) |
| 197 | + except Exception: |
| 198 | + pass |
| 199 | + |
156 | 200 | class StFormat(sublime_plugin.TextCommand): |
157 | 201 | def run(self, edit): |
158 | 202 | Selection.formatSql(edit) |
|
0 commit comments