[PATCH] Handle VC plugins not implemented methods



The attached patch implements the greying of the
buttons attached to not implemented methods from
a VC plugin.

Crude, but working, I looked at inspect module, but
preferred the simple way of specifying the arguments.

Tested with RCS, SVN, git, and switching between
them to see button state toggling between sensitive
and not.

-- 
Vincent Legoll
Index: vcview.py
===================================================================
--- vcview.py	(revision 1326)
+++ vcview.py	(working copy)
@@ -200,6 +200,23 @@
         self.combobox_vcs.show()
         self.combobox_vcs.connect("changed", self.on_vc_change)
 
+    def update_action_buttons(self):
+        action_button_map = {
+                             "VcCommit": ("commit_command", ("",)),
+                             "VcUpdate": ("update_command", ()),
+                             "VcAdd": ("add_command", ()),
+                             "VcRemove": ("remove_command", ()),
+                             "VcCompare": ("diff_command", ()),
+                             "VcRevert": ("revert_command", ()),
+                             }
+        for action, (meth_name, args) in action_button_map.items():
+            button = self.actiongroup.get_action(action)
+            try:
+                getattr(self.vc, meth_name)(*args)
+                button.props.sensitive = True
+            except NotImplementedError:
+                button.props.sensitive = False
+
     def choose_vc(self, vcs):
         """Display VC plugin(s) that can handle the location"""
         self.combobox_vcs.lock = True
@@ -218,6 +235,7 @@
         if not cb.lock:
             self.vc = cb.get_model()[cb.get_active_iter()][1]
             self._set_location(self.vc.root)
+            self.update_action_buttons()
 
     def set_location(self, location):
         self.choose_vc(vc.get_vcs(os.path.abspath(location or ".")))


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