Skip to content

Commit

Permalink
Fall back to active_window if view.window() is None
Browse files Browse the repository at this point in the history
Fun discovery: if you switch tabs while a command is working,
self.view.window() is None. (Admittedly this is a consequence
of my deciding to do async command processing... but, hey,
got to live with that now.)
I did try tracking the window used at the start of the command
and using it instead of view.window() later, but that results
panels on a non-visible window, which is especially useless in
the case of the quick panel.
So, this is not necessarily ideal, but it does work.
  • Loading branch information
kemayo committed Sep 29, 2011
1 parent fcd3970 commit 332a942
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions git.py
Expand Up @@ -115,7 +115,7 @@ def _output_to_view(self, output_file, output, clear=False,
output_file.end_edit(edit)

def scratch(self, output, title=False, **kwargs):
scratch_file = self.view.window().new_file()
scratch_file = self.window().new_file()
if title:
scratch_file.set_name(title)
scratch_file.set_scratch(True)
Expand All @@ -125,11 +125,26 @@ def scratch(self, output, title=False, **kwargs):

def panel(self, output, **kwargs):
if not hasattr(self, 'output_view'):
self.output_view = self.view.window().get_output_panel("git")
self.output_view = self.window().get_output_panel("git")
self.output_view.set_read_only(False)
self._output_to_view(self.output_view, output, clear=True, **kwargs)
self.output_view.set_read_only(True)
self.view.window().run_command("show_panel", {"panel": "output.git"})
self.window().run_command("show_panel", {"panel": "output.git"})

def window(self):
# Fun discovery: if you switch tabs while a command is working,
# self.view.window() is None. (Admittedly this is a consequence
# of my deciding to do async command processing... but, hey,
# got to live with that now.)
# I did try tracking the window used at the start of the command
# and using it instead of view.window() later, but that results
# panels on a non-visible window, which is especially useless in
# the case of the quick panel.
# So, this is not necessarily ideal, but it does work.
return self.view.window() or sublime.active_window()

def quick_panel(self, *args, **kwargs):
self.window().show_quick_panel(*args, **kwargs)

def is_enabled(self):
# First, is this actually a file on the file system?
Expand Down Expand Up @@ -181,7 +196,7 @@ def run(self, edit):

def log_done(self, result):
self.results = [r.split('\a', 2) for r in result.strip().split('\n')]
self.view.window().show_quick_panel(self.results, self.panel_done)
self.quick_panel(self.results, self.panel_done)

def panel_done(self, picked):
if 0 > picked < len(self.results):
Expand Down Expand Up @@ -224,7 +239,7 @@ def get_file_name(self):

class GitQuickCommitCommand(GitCommand):
def run(self, edit):
self.view.window().show_input_panel("Message", "",
self.window().show_input_panel("Message", "",
self.on_input, None, None)

def on_input(self, message):
Expand Down Expand Up @@ -291,7 +306,7 @@ def status_done(self, result):
"# Just close the window to accept your message.",
result.strip()
])
msg = self.view.window().new_file()
msg = self.window().new_file()
msg.set_scratch(True)
msg.set_name("GIT_COMMIT_MESSAGE")
self._output_to_view(msg, template)
Expand Down Expand Up @@ -339,7 +354,7 @@ def status_done(self, result):
self.show_status_list()

def show_status_list(self):
self.view.window().show_quick_panel(self.results, self.panel_done,
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)

def status_filter(self, item):
Expand Down Expand Up @@ -371,7 +386,7 @@ def status_filter(self, item):

def show_status_list(self):
self.results.insert(0, [" + All Files", "apart from untracked files"])
self.view.window().show_quick_panel(self.results, self.panel_done,
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)

def panel_followup(self, picked_file, picked_index):
Expand Down Expand Up @@ -402,7 +417,7 @@ def run(self, edit):

def branch_done(self, result):
self.results = result.rstrip().split('\n')
self.view.window().show_quick_panel(self.results, self.panel_done,
self.quick_panel(self.results, self.panel_done,
sublime.MONOSPACE_FONT)

def panel_done(self, picked):
Expand Down

0 comments on commit 332a942

Please sign in to comment.