Skip to content

Commit

Permalink
Merge pull request mtxr#134 from Coteh/dev/list_insert_saved_queries
Browse files Browse the repository at this point in the history
Add List and Insert Saved Queries
  • Loading branch information
tkopets authored Aug 29, 2017
2 parents e613858 + 0ce02b4 commit bb8a39c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },
{ "keys": ["ctrl+e", "ctrl+l"], "command": "st_list_queries"},
{ "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}}
{ "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}},
{ "keys": ["ctrl+e", "ctrl+i"], "command": "st_list_queries", "args": {"mode" : "insert"}}
]
5 changes: 5 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"command": "st_list_queries",
"args" : {"mode": "open"}
},
{
"caption": "ST: List and Insert Saved Queries",
"command": "st_list_queries",
"args" : {"mode": "insert"}
},
{
"caption": "ST: Format Current SQL File",
"command": "st_format"
Expand Down
16 changes: 16 additions & 0 deletions SQLTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ def toNewTab(content, name="", suffix="SQLTools Saved Query"):
resultContainer.run_command('append', {'characters': content})


def insertContent(content):
view = View()
# getting the settings local to this view/tab
settings = view.settings()
# saving the original settings for "auto_indent", or True if none set
autoIndent = settings.get('auto_indent', True)
# turn off automatic indenting otherwise the tabbing of the original
# string is not respected after a newline is encountered
settings.set('auto_indent', False)
view.run_command('insert', {'characters': content})
# restore "auto_indent" setting
settings.set('auto_indent', autoIndent)


def getOutputPlace(syntax=None, name="SQLTools Result"):
if not settings.get('show_result_on_window', True):
resultContainer = Window().find_output_panel(name)
Expand Down Expand Up @@ -559,6 +573,8 @@ def cb(index):
if mode == "run":
ST.conn.execute(query, createOutput(),
stream=settings.get('use_streams', False))
elif mode == "insert":
insertContent(query)
else:
toNewTab(query, alias)

Expand Down

0 comments on commit bb8a39c

Please sign in to comment.