[meld] Improve popup right-click behaviour in tree views (closes bgo#669828)



commit fbbb8900131b00219c805bd14ed2120b07f3c74d
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Feb 12 11:58:14 2012 +1000

    Improve popup right-click behaviour in tree views (closes bgo#669828)
    
    Existing behaviour when right-clicking on an unselected row was to not
    select the row, but show a context menu for the other currently
    selected rows, which is inconsistent with Nautilus, among others.
    
    This patch changes our behaviour to be more consistent with other file
    management tools, in both Meld's directory and VC comparison views.
    Right clicking an unselected file now selects it, moves the cursor to
    it, and opens the context menu. The existing right-click behaviour for
    already-selected files should be preserved.

 meld/dirdiff.py |   30 ++++++++++++++++--------------
 meld/vcview.py  |   11 ++++++++++-
 2 files changed, 26 insertions(+), 15 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 274b0ae..3ea9cbd 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -975,22 +975,24 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
         return True
 
     def on_treeview_button_press_event(self, treeview, event):
-        # unselect other panes
-        for t in filter(lambda x:x!=treeview, self.treeview[:self.num_panes]):
+        # Unselect any selected files in other panes
+        for t in [v for v in self.treeview[:self.num_panes] if v != treeview]:
             t.get_selection().unselect_all()
+
         if event.button == 3:
-            try:
-                path, col, cellx, celly = treeview.get_path_at_pos( int(event.x), int(event.y) )
-            except TypeError:
-                pass # clicked outside tree
-            else:
-                treeview.grab_focus()
-                selected = self._get_selected_paths( self.treeview.index(treeview) )
-                if len(selected) <= 1 and event.state == 0:
-                    treeview.set_cursor( path, col, 0)
-                self.popup_in_pane(self.treeview.index(treeview), event)
-            return event.state==0
-        return 0
+            treeview.grab_focus()
+            path = treeview.get_path_at_pos(int(event.x), int(event.y))
+            selection = treeview.get_selection()
+            model, rows = selection.get_selected_rows()
+
+            if path[0] not in rows:
+                selection.unselect_all()
+                selection.select_path(path[0])
+                treeview.set_cursor(path[0])
+
+            self.popup_in_pane(self.treeview.index(treeview), event)
+            return True
+        return False
 
     def get_state_traversal(self, diffmapindex):
         def tree_state_iter():
diff --git a/meld/vcview.py b/meld/vcview.py
index 8eeeaf5..8620640 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -425,8 +425,17 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
         self.popup_menu.popup(None, None, None, 0, time)
         return True
 
-    def on_button_press_event(self, text, event):
+    def on_button_press_event(self, treeview, event):
         if event.button == 3:
+            path = treeview.get_path_at_pos(int(event.x), int(event.y))
+            selection = treeview.get_selection()
+            model, rows = selection.get_selected_rows()
+
+            if path[0] not in rows:
+                selection.unselect_all()
+                selection.select_path(path[0])
+                treeview.set_cursor(path[0])
+
             self.popup_menu.popup(None, None, None, event.button, event.time)
             return True
         return False



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