[accerciser: 1/2] treeview: Use filtered path to select correct entry




commit c2a3e9f1eb1fcd6eb059f1f2fe6e629b86521335
Author: Michael Weghorn <m weghorn posteo de>
Date:   Mon Jul 4 16:29:22 2022 +0200

    treeview: Use filtered path to select correct entry
    
    The gtk.TreeView methods called in `_selectExistingPath` operate
    on `AccessibleTreeView`'s model, which is the filtered model
    (`self.filter`, s. the call to `self.set_model(self.filter)` in the
    `AccessibleTreeView` constructor).
    
    Since the path to the unfiltered model (`self.model`) gets passed
    as a parameter, convert this to the filtered path before using it to
    select an item.
    
    This fixes navigating to a bookmark when
    "View" -> "Show applications without children"
    is disabled (the default), which was otherwise using
    a too large row index in the path if any hidden applications had
    a lower row index than the bookmarked application.

 src/lib/accerciser/accessible_treeview.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/src/lib/accerciser/accessible_treeview.py b/src/lib/accerciser/accessible_treeview.py
index 18089d2..ed4b650 100644
--- a/src/lib/accerciser/accessible_treeview.py
+++ b/src/lib/accerciser/accessible_treeview.py
@@ -875,19 +875,24 @@ class AccessibleTreeView(gtk.TreeView, ToolsAccessor):
       self._selectExistingPath(self._path_to_expand)
       self._path_to_expand = None
 
-  def _selectExistingPath(self, path):
+  def _selectExistingPath(self, model_path):
     '''
     Select a path that already exists. Expand, scroll, and select.
     
-    @param path: Path to select.
+    @param model_path: Path to select, referring to the unfiltered model.
     @type path: tuple
     '''
-    tree_path = gtk.TreePath(path[:-1])
-    if len(path) > 1:
+    iter = self.model.get_iter(model_path)
+    (res, filter_iter) = self.filter.convert_child_iter_to_iter(iter)
+    if not res:
+        return
+    filter_path = self.filter.get_path(filter_iter)
+    tree_path = gtk.TreePath(filter_path[:-1])
+    if len(filter_path) > 1:
       self.expand_to_path(tree_path)
-    self.scroll_to_cell(path)
+    self.scroll_to_cell(filter_path)
     selection = self.get_selection()
-    selection.select_path(path)
+    selection.select_path(filter_path)
     
 
   def _onStartPop(self, model):


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