meld r1105 - trunk



Author: kaiw
Date: Sun Dec 28 10:43:19 2008
New Revision: 1105
URL: http://svn.gnome.org/viewvc/meld?rev=1105&view=rev

Log:
Handle sensitivity setting for all ListWidget actions, and rely on the sensitivity setting to manage preconditions

Modified:
   trunk/meldapp.py

Modified: trunk/meldapp.py
==============================================================================
--- trunk/meldapp.py	(original)
+++ trunk/meldapp.py	Sun Dec 28 10:43:19 2008
@@ -138,7 +138,23 @@
                 addTextCol(c[0], i)
             elif c[1] == type(0):
                 addToggleCol( c[0], 1)
+        view.get_selection().connect('changed', self._update_sensitivity)
+        view.get_model().connect('row-inserted', self._update_sensitivity)
+        view.get_model().connect('rows-reordered', self._update_sensitivity)
+        self._update_sensitivity()
         self._update_filter_model()
+
+    def _update_sensitivity(self, *args):
+        (model, iter, path) = self._get_selected()
+        if not iter:
+            self.item_delete.set_sensitive(False)
+            self.item_up.set_sensitive(False)
+            self.item_down.set_sensitive(False)
+        else:
+            self.item_delete.set_sensitive(True)
+            self.item_up.set_sensitive(path > 0)
+            self.item_down.set_sensitive(path < len(model) - 1)
+
     def on_item_new_clicked(self, button):
         model = self.treeview.get_model()
         model.append([_("label"), 0, _("pattern")])
@@ -152,20 +168,14 @@
         return (model, iter, path)
     def on_item_delete_clicked(self, button):
         (model, iter, path) = self._get_selected()
-        if not iter:
-            return
         model.remove(iter)
         self._update_filter_string()
     def on_item_up_clicked(self, button):
         (model, iter, path) = self._get_selected()
-        if not iter or path <= 0:
-            return
         model.swap(iter, model.get_iter(path - 1))
         self._update_filter_string()
     def on_item_down_clicked(self, button):
         (model, iter, path) = self._get_selected()
-        if not iter or path >= len(model) - 1:
-            return
         model.swap(iter, model.get_iter(path + 1))
         self._update_filter_string()
     def on_items_revert_clicked(self, button):



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