Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit bb8a39c

Browse files
authored
Merge pull request #134 from Coteh/dev/list_insert_saved_queries
Add List and Insert Saved Queries
2 parents e613858 + 0ce02b4 commit bb8a39c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Default (Windows).sublime-keymap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
1212
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },
1313
{ "keys": ["ctrl+e", "ctrl+l"], "command": "st_list_queries"},
14-
{ "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}}
14+
{ "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}},
15+
{ "keys": ["ctrl+e", "ctrl+i"], "command": "st_list_queries", "args": {"mode" : "insert"}}
1516
]

Default.sublime-commands

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"command": "st_list_queries",
5454
"args" : {"mode": "open"}
5555
},
56+
{
57+
"caption": "ST: List and Insert Saved Queries",
58+
"command": "st_list_queries",
59+
"args" : {"mode": "insert"}
60+
},
5661
{
5762
"caption": "ST: Format Current SQL File",
5863
"command": "st_format"

SQLTools.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ def toNewTab(content, name="", suffix="SQLTools Saved Query"):
139139
resultContainer.run_command('append', {'characters': content})
140140

141141

142+
def insertContent(content):
143+
view = View()
144+
# getting the settings local to this view/tab
145+
settings = view.settings()
146+
# saving the original settings for "auto_indent", or True if none set
147+
autoIndent = settings.get('auto_indent', True)
148+
# turn off automatic indenting otherwise the tabbing of the original
149+
# string is not respected after a newline is encountered
150+
settings.set('auto_indent', False)
151+
view.run_command('insert', {'characters': content})
152+
# restore "auto_indent" setting
153+
settings.set('auto_indent', autoIndent)
154+
155+
142156
def getOutputPlace(syntax=None, name="SQLTools Result"):
143157
if not settings.get('show_result_on_window', True):
144158
resultContainer = Window().find_output_panel(name)
@@ -559,6 +573,8 @@ def cb(index):
559573
if mode == "run":
560574
ST.conn.execute(query, createOutput(),
561575
stream=settings.get('use_streams', False))
576+
elif mode == "insert":
577+
insertContent(query)
562578
else:
563579
toNewTab(query, alias)
564580

0 commit comments

Comments
 (0)