Thejesh GN avatar Thejesh GN committed 3bde62a Draft Merge

Merged in rakeev/hg4subl (pull request #5)

Comments (0)

Files changed (2)

Side Bar.sublime-menu

+[
+    {
+        "caption": "Hg",
+        "children":
+        [
+            { "caption": "Diff", "command": "hg_diff_side", "args": {"paths": []} }
+            ,{ "caption": "Add", "command": "hg_add_side", "args": {"paths": []} }
+            ,{ "caption": "Remove", "command": "hg_remove_side", "args": {"paths": []} }
+            ,{ "caption": "Annotate", "command": "hg_annotate_side", "args": {"paths": []} }
+        ]
+    }
+]
         except subprocess.CalledProcessError, e:
             main_thread(self.on_done, e.returncode)
 
-class HgCommand(sublime_plugin.TextCommand):
+class HgCommand:
     def run_command(self, command, callback = None, show_status = True, filter_empty_args = True, **kwargs):
         if filter_empty_args:
             command = [arg for arg in command if arg]
         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)
 
     def panel(self, output, **kwargs):
         if not hasattr(self, 'output_view'):
-            self.output_view = self.view.window().get_output_panel("hg")
+            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)
         self.output_view.set_read_only(True)
-        self.view.window().run_command("show_panel", {"panel": "output.hg"})
+        self.window.run_command("show_panel", {"panel": "output.hg"})
+
+    def get_file_name(self):
+        return os.path.basename(self.view.file_name())
+    def get_file_location(self):
+        return os.path.dirname(self.view.file_name())
+
+class HgTextCommand(HgCommand, sublime_plugin.TextCommand):
+    def __init__(self, view):
+        sublime_plugin.TextCommand.__init__(self, view)
+        self.window = view.window()
 
     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())
-    def get_file_name(self):
-        return os.path.basename(self.view.file_name())
-    def get_file_location(self):
-        return os.path.dirname(self.view.file_name())
 
-class HgAnnotateCommand(HgCommand):
+class HgWindowCommand(HgCommand, sublime_plugin.WindowCommand):
+    def __init__(self, window):
+        sublime_plugin.WindowCommand.__init__(self, window)
+        self.view = window.active_view()
+
+class HgAnnotateCommand(HgTextCommand):
     def run(self, edit):
-        command = [get_hg(self.view), 'annotate', '-a', '-u', '-f','-d','-l','-n']
+        command = [get_hg(self.view), 'annotate', '-aufdqln']
 
         selection = self.view.sel()[0] # todo: multi-select support?
         if not selection.empty():
             command.extend(('-L', lines))
 
         command.append(self.get_file_name())
-        self.run_command(command, self.annotate_done)
-    def annotate_done(self, result):
-        self.scratch(result, title = "Hg annotate")
+        self.run_command(command, functools.partial(self.scratch, title = "Hg annotate"))
 
-class HgCustomCommand(HgCommand):
+class HgAnnotateSideCommand(HgWindowCommand):
+    def run(self, paths):
+        self.run_command([get_hg(self.view), 'annotate', '-aufdqln'] + paths, functools.partial(self.scratch, title = "Hg annotate"))
+
+class HgCustomCommand(HgTextCommand):
     def run(self, edit):
-        self.view.window().show_input_panel("Hg", "",
+        self.window.show_input_panel("Hg", "",
             self.on_done, None, None)
 
     def on_done(self, command):
     def cmd_done(self, result):
         self.scratch(result, title = "Hg Custom Command")
 
-class HgPushCommand(HgCommand):
+class HgPushCommand(HgTextCommand):
     def run(self, edit):
         command = [get_hg(self.view), 'push']
         self.run_command(command)
 
-class HgPullCommand(HgCommand):
+class HgPullCommand(HgTextCommand):
     def run(self, edit):
         command = [get_hg(self.view), 'pull', '--update', 'default']
         self.run_command(command)
 
-class HgLogCommand(HgCommand):
+class HgLogCommand(HgTextCommand):
     def run(self, edit):
         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.view.window().show_quick_panel(self.results, self.panel_done)
+        self.window.show_quick_panel(self.results, self.panel_done)
 
     def panel_done(self, picked):
         if picked == -1:
     def get_file_name(self):
         return ''
 
-class HgDiffCommand(HgCommand):
+class HgDiffCommand(HgTextCommand):
     def run(self, edit):
-        self.run_command([get_hg(self.view), 'diff', '', self.get_file_name()], self.diff_done)
-
-    def diff_done(self, result):
-        self.scratch(result, title = "Hg Diff")
+        self.run_command([get_hg(self.view), 'diff', self.get_file_name()], functools.partial(self.scratch, title = "Hg Diff"))
 
 class HgDiffAllCommand(HgDiffCommand):
     def get_file_name(self):
         return ''
 
-class HgCommitCommand(HgCommand):
+class HgDiffSideCommand(HgWindowCommand):
+    def run(self, paths):
+        self.run_command([get_hg(self.view), 'diff'] + paths, functools.partial(self.scratch, title = "Hg Diff"))
+
+class HgCommitCommand(HgTextCommand):
     def run(self, edit):
-        self.view.window().show_input_panel("Message", "", self.on_input, None, None)
+        self.window.show_input_panel("Message", "", self.on_input, None, None)
 
     def on_input(self, message):
         if message.strip() == "":
             return
         self.run_command([get_hg(self.view), 'commit', '-m', message])
 
-class HgStatusCommand(HgCommand):
+class HgStatusCommand(HgTextCommand):
     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.view.window().show_quick_panel(self.results, self.panel_done, sublime.MONOSPACE_FONT)
+        self.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
         return True
     def panel_followup(self, picked_file):
         self.run_command([get_hg(self.view), 'add', picked_file], working_dir = hg_root(self.get_file_location()))
 
-class HgAdd(HgCommand):
+class HgAdd(HgTextCommand):
     def run(self, edit):
         self.run_command([get_hg(self.view), 'add', self.get_file_name()])
 
-class HgRemove(HgCommand):
+class HgAddSide(HgWindowCommand):
+    def run(self, paths):
+        self.run_command([get_hg(self.view), 'add'] + paths)
+
+class HgRemove(HgTextCommand):
     def run(self, edit):
         self.run_command([get_hg(self.view), 'remove', '-f', self.get_file_name()])
 
-class HgShelveCommand(HgCommand):
+class HgRemoveSide(HgWindowCommand):
+    def run(self, paths):
+        self.run_command([get_hg(self.view), 'remove', '-f'] + paths)
+
+class HgShelveCommand(HgTextCommand):
     def run(self, edit):
         self.run_command([get_hg(self.view), 'shelve'])
 
-class HgUnshelveCommand(HgCommand):
+class HgUnshelveCommand(HgTextCommand):
     def run(self, edit):
         self.run_command([get_hg(self.view), 'unshelve'])
 
-class hgBranchCommand(HgCommand):
+class hgBranchCommand(HgTextCommand):
     def run(self, edit):
         self.run_command([get_hg(self.view), 'branches'], self.branch_done)
     def branch_done(self, result):
         self.results = result.rstrip().split('\n')
-        self.view.window().show_quick_panel(self.results, self.panel_done, sublime.MONOSPACE_FONT)
+        self.window.show_quick_panel(self.results, self.panel_done, sublime.MONOSPACE_FONT)
     def panel_done(self, picked):
         if picked == -1:
             return
 # auto download and updating.
 #-----------------------------------------------------------#
 
-class hg4sublUpdate(HgCommand):
+class hg4sublUpdate(HgTextCommand):
     def run(self,edit):
         package_names = os.listdir(sublime.packages_path())
         for path in package_names:
                     error.output = output
                     raise error
                 self.panel(output)
-
-
-
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.