From 4ffef76facb7e878d311a115aab890ab3b08e013 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Mon, 29 Mar 2010 16:00:24 +0000 Subject: [PATCH] 3740: Fix problems with add, delete and update of views when filter applied svn: r14968 --- src/gui/views/treemodels/flatbasemodel.py | 7 +++++-- src/gui/views/treemodels/treebasemodel.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/gui/views/treemodels/flatbasemodel.py b/src/gui/views/treemodels/flatbasemodel.py index a771e6d2a..005a294b4 100644 --- a/src/gui/views/treemodels/flatbasemodel.py +++ b/src/gui/views/treemodels/flatbasemodel.py @@ -601,10 +601,11 @@ class FlatBaseModel(gtk.GenericTreeModel): """ Delete a row, called after the object with handle is deleted """ + if self.node_map.get_path(handle) is None: + return # row is not currently displayed self.clear_cache(handle) data = self.map(handle) - delete_val = (map(conv_unicode_tosrtkey_ongtk, self.sort_func(data)), - handle) + delete_val = (self.node_map.get_sortkey(handle), handle) delete_path = self.node_map.delete(delete_val) #delete_path is an integer from 0 to n-1 if delete_path is not None: @@ -614,6 +615,8 @@ class FlatBaseModel(gtk.GenericTreeModel): """ Update a row, called after the object with handle is changed """ + if self.node_map.get_path(handle) is None: + return # row is not currently displayed self.clear_cache(handle) oldsortkey = self.node_map.get_sortkey(handle) newsortkey = map(conv_unicode_tosrtkey_ongtk, self.sort_func(self.map( diff --git a/src/gui/views/treemodels/treebasemodel.py b/src/gui/views/treemodels/treebasemodel.py index 852f257f3..ce823eb71 100644 --- a/src/gui/views/treemodels/treebasemodel.py +++ b/src/gui/views/treemodels/treebasemodel.py @@ -670,8 +670,11 @@ class TreeBaseModel(gtk.GenericTreeModel): Add a row to the model. """ cput = time.clock() - data = self.map(handle) - self.add_row(handle, data) + if not self.search or \ + (self.search and self.search.match(handle, self.db)): + #row needs to be added to the model + data = self.map(handle) + self.add_row(handle, data) _LOG.debug(self.__class__.__name__ + ' add_row_by_handle ' + str(time.clock() - cput) + ' sec') @@ -681,9 +684,11 @@ class TreeBaseModel(gtk.GenericTreeModel): Delete a row from the model. """ cput = time.clock() - self.clear_cache(handle) - node = self.get_node(handle) + if node is None: + return # row not currently displayed + + self.clear_cache(handle) parent = self.nodemap.node(node.parent) self.remove_node(node) @@ -706,6 +711,9 @@ class TreeBaseModel(gtk.GenericTreeModel): """ Update a row in the model. """ + if self.get_node(handle) is None: + return # row not currently displayed + self.delete_row_by_handle(handle) self.add_row_by_handle(handle)