Commits

Fredrik Ehnbom committed 0a8a0a1

Sublime Text 3 compatibility tweaks

Comments (0)

Files changed (1)

             # if sublime's python gets bumped to 2.7 we can just do:
             # output = subprocess.check_output(self.command)
             main_thread(self.on_done, _make_text_safeish(output, self.fallback_encoding))
-        except subprocess.CalledProcessError, e:
+        except subprocess.CalledProcessError as e:
             main_thread(self.on_done, e.returncode)
 
+class HgOutputToView(sublime_plugin.TextCommand):
+    def run(self, edit, output, clear = False, syntax = "Packages/Diff/Diff.tmLanguage"):
+        output_file = self.view
+        output_file.set_syntax_file(syntax)
+        if clear:
+            region = sublime.Region(0, self.output_view.size())
+            output_file.erase(edit, region)
+        output_file.insert(edit, 0, output)
+
 class HgCommand:
     def run_command(self, command, callback = None, show_status = True, filter_empty_args = True, **kwargs):
         if filter_empty_args:
             return
         self.panel(result)
 
-    def _output_to_view(self, output_file, output, clear = False, syntax = "Packages/Diff/Diff.tmLanguage"):
-        output_file.set_syntax_file(syntax)
-        edit = output_file.begin_edit()
-        if clear:
-            region = sublime.Region(0, self.output_view.size())
-            output_file.erase(edit, region)
-        output_file.insert(edit, 0, output)
-        output_file.end_edit(edit)
-
     def scratch(self, output, title = False, **kwargs):
         scratch_file = self.window.new_file()
         if title:
             scratch_file.set_name(title)
         scratch_file.set_scratch(True)
-        self._output_to_view(scratch_file, output, **kwargs)
+        kwargs["output"] = output
+        scratch_file.run_command("hg_output_to_view", kwargs)
         scratch_file.set_read_only(True)
         return scratch_file
 
         if not hasattr(self, 'output_view'):
             self.output_view = self.window.get_output_panel("hg")
         self.output_view.set_read_only(False)
-        self._output_to_view(self.output_view, output, clear = True, **kwargs)
+        kwargs["output"] = output.decode("utf-8")
+        self.output_view.run_command("hg_output_to_view", kwargs)
         self.output_view.set_read_only(True)
         self.window.run_command("show_panel", {"panel": "output.hg"})
 
     def is_enabled(self):
         # First, is this actually a file on the file system?
         if self.view.file_name() and len(self.view.file_name()) > 0:
-            return hg_root(self.get_file_location())
+            return hg_root(self.get_file_location()) != None
+        else:
+            return False
 
     def get_window(self):
         return self.view.window() or sublime.active_window()
         self.run_command([get_hg(self.view), 'log', '-v','--', self.get_file_name()], self.log_done)
 
     def log_done(self, result):
-        self.results = [r.strip().split("\n") for r in result.strip().split('\n\n')]
+        self.results = [r.strip().split("\n", 4) for r in result.strip().split('\n\n')]
         self.get_window().show_quick_panel(self.results, self.panel_done)
 
     def panel_done(self, picked):
     def run(self, edit):
         self.run_command([get_hg(self.view), 'status',], self.status_done)
     def status_done(self, result):
-        self.results = filter(self.status_filter, result.rstrip().split('\n'))
+        self.results = list(filter(self.status_filter, result.rstrip().split('\n')))
         self.get_window().show_quick_panel(self.results, self.panel_done, sublime.MONOSPACE_FONT)
     def status_filter(self, item):
         # for this class we don't actually care