Re: [PATCH] Handle VC plugins not implemented methods



On Sun, Apr 5, 2009 at 7:57 AM, Kai Willadsen <kai willadsen gmail com> wrote:
> Should action_button_map be a class member instead? Also, the
> VcAddBinary action isn't handled. Finally, the variable naming of
> 'button' is a little misleading. Some of the Actions aren't buttons at
> all (e.g., VcAddBinary only appears in the context menu) and might in
> the future also be menu items, etc. so I'd suggest a more generic
> 'action' or something here.
>
> Otherwise, this looks good to me. There are several places that our
> sensitivity handling could be better, and this fixes one of the more
> important ones.

Thanks again for your valuable feedback, the attached patch
should fix the problems you noted.

-- 
Vincent Legoll
Index: vcview.py
===================================================================
--- vcview.py	(revision 1327)
+++ vcview.py	(working copy)
@@ -105,6 +105,16 @@
 #
 ################################################################################
 class VcView(melddoc.MeldDoc, gnomeglade.Component):
+    # Map action names to VC commands and required arguments list
+    action_vc_cmds_map = {
+                         "VcCompare": ("diff_command", ()),
+                         "VcCommit": ("commit_command", ("",)),
+                         "VcUpdate": ("update_command", ()),
+                         "VcAdd": ("add_command", ()),
+                         "VcAddBinary": ("add_command", ()),
+                         "VcRemove": ("remove_command", ()),
+                         "VcRevert": ("revert_command", ()),
+                         }
 
     def __init__(self, prefs):
         melddoc.MeldDoc.__init__(self, prefs)
@@ -200,6 +210,17 @@
         self.combobox_vcs.show()
         self.combobox_vcs.connect("changed", self.on_vc_change)
 
+    def update_actions_sensitivity(self):
+        """Disable actions that use not implemented VC plugin methods
+        """
+        for action_name, (meth_name, args) in self.action_vc_cmds_map.items():
+            action = self.actiongroup.get_action(action_name)
+            try:
+                getattr(self.vc, meth_name)(*args)
+                action.props.sensitive = True
+            except NotImplementedError:
+                action.props.sensitive = False
+
     def choose_vc(self, vcs):
         """Display VC plugin(s) that can handle the location"""
         self.combobox_vcs.lock = True
@@ -218,6 +239,7 @@
         if not cb.lock:
             self.vc = cb.get_model()[cb.get_active_iter()][1]
             self._set_location(self.vc.root)
+            self.update_actions_sensitivity()
 
     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]