Skip to content

Commit

Permalink
split response view
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunihiko Kido committed Jul 27, 2015
1 parent 938ab33 commit ce8e2e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def show_input_panel(self, label, default, callback):
self.window.show_input_panel(label, default, callback, None, None)

def show_response(self, response, title=""):
title = title or self.__class__.__name__
title = title or self.command_name
text = json.dumps(response, indent=2, ensure_ascii=False)
self.window.run_command(
"show_response", {"title": title, "text": text})
Expand Down
25 changes: 25 additions & 0 deletions commands/show_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ class ShowResponseCommand(sublime_plugin.WindowCommand):
default_syntax = 'Packages/JavaScript/JSON.tmLanguage'

def run(self, title="", text=""):
request_view = self.window.active_view()
request_view_group, request_view_index = \
self.window.get_view_index(request_view)

self.window.run_command('set_layout', {
'cols': [0.0, 0.5, 1.0],
'rows': [0.0, 1.0],
'cells': [[0, 0, 1, 1], [1, 0, 2, 1]]
})

self.window.set_view_index(
request_view, request_view_group,
request_view_index)

self.window.focus_group(1)

panel = self.window.new_file()
panel.set_name('RESPONSE: {}'.format(title))
panel.set_scratch(True)
Expand All @@ -16,3 +32,12 @@ def run(self, title="", text=""):
panel.settings().set('word_wrap', False)
panel.run_command('append', {'characters': text})
panel.set_read_only(True)

views = self.window.views_in_group(self.window.active_group())
for view in views:
if panel.id() != view.id() and request_view.id() != view.id():
self.window.focus_view(view)
self.window.run_command("close_file")

self.window.focus_group(request_view_group)
self.window.focus_view(request_view)
7 changes: 4 additions & 3 deletions events.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def _update_status_bar(self, view):
doc_type=doc_type
)

view.set_status(
"elasticsearch-client",
"Elasticsearch: {base_url}".format(**options))
if view is not None:
view.set_status(
"elasticsearch-client",
"Elasticsearch: {base_url}".format(**options))

def on_new(self, view):
self.update_status_bar(view)
Expand Down

0 comments on commit ce8e2e1

Please sign in to comment.