[meld] vcview: Add rough command() API for taking VC actions from other tabs



commit 2add00516bb1201056ab423e5c68eb68a0d59971
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Apr 22 07:33:15 2014 +1000

    vcview: Add rough command() API for taking VC actions from other tabs
    
    The idea here is simply that file tabs should be able to run actions
    using their parent VC, without being exposed to the whole task
    infrastructure and meld.vc shim layer.

 meld/vcview.py |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/meld/vcview.py b/meld/vcview.py
index 5c1d109..940f138 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -17,6 +17,7 @@
 from __future__ import print_function
 
 import atexit
+import logging
 import tempfile
 import shutil
 import os
@@ -43,6 +44,8 @@ from meld.conf import _
 from meld.settings import settings
 from meld.vc import _null
 
+log = logging.getLogger(__name__)
+
 
 def _commonprefix(files):
     if len(files) != 1:
@@ -152,6 +155,11 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         "VcRevert": ("revert_command", ()),
     }
 
+    # Map for inter-tab command() calls
+    command_map = {
+        'resolve': 'resolve',
+    }
+
     state_actions = {
         "flatten": ("VcFlatten", None),
         "modified": ("VcShowModified", entry_modified),
@@ -628,6 +636,19 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
             self.refresh_partial(workdir)
         yield workdir, r
 
+    def has_command(self, command):
+        return command in self.command_map
+
+    def command(self, command, files):
+        if not self.has_command(command):
+            log.error("Couldn't understand command %s", command)
+
+        if not isinstance(files, list):
+            log.error("Invalid files argument to '%s': %r", command, files)
+
+        command = getattr(self.vc, self.command_map[command])
+        command(self._command, files)
+
     def _command(self, command, files, refresh=1, working_dir=None):
         """Run 'command' on 'files'.
         """


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]