From fe5b0aa03dccf1c38f00d0c0658ff3da6f2dadd4 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Sun, 16 Sep 2007 12:14:16 +0000 Subject: [PATCH] Only show unattached notes in note view svn: r8981 --- ChangeLog | 4 +++ src/DisplayModels/_BaseModel.py | 8 +++++ src/DisplayModels/_NoteModel.py | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8554babe5..a7ffee923 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-09-16 Benny Malengier + * src/DisplayModels/_BaseModel.py: Add comments + * src/DisplayModels/_NoteModel.py: Only show unattached notes in note view + 2007-09-16 Zsolt Foldvari * src/BaseDoc.py (PaperStyle): Allow custom margin setting in __init__. diff --git a/src/DisplayModels/_BaseModel.py b/src/DisplayModels/_BaseModel.py index e471b2bd8..93c063307 100644 --- a/src/DisplayModels/_BaseModel.py +++ b/src/DisplayModels/_BaseModel.py @@ -221,6 +221,10 @@ class BaseModel(gtk.GenericTreeModel): return [ x[1] for x in self.sort_data ] def _rebuild_search(self,ignore=None): + """ function called when view must be build, given a search text + in the top search bar + Remark: this method is overridden in NoteModel ! + """ self.total = 0 if self.db.is_open(): if self.search and self.search.text: @@ -237,6 +241,10 @@ class BaseModel(gtk.GenericTreeModel): self.node_map.clear_map() def _rebuild_filter(self, ignore=None): + """ function called when view must be build, given filter options + in the filter sidebar + Remark: this method is overridden in NoteModel ! + """ self.total = 0 if self.db.is_open(): if self.search: diff --git a/src/DisplayModels/_NoteModel.py b/src/DisplayModels/_NoteModel.py index f586bca56..29b899b8e 100644 --- a/src/DisplayModels/_NoteModel.py +++ b/src/DisplayModels/_NoteModel.py @@ -81,6 +81,61 @@ class NoteModel(BaseModel): BaseModel.__init__(self, db, scol, order, search=search, skip=skip, sort_map=sort_map) + def __unattached_note(self, handle): + """ function that returns true if note is not attached to another + object + """ + if handle : + return len([x for x in self.db.find_backlink_handles(handle)]) == 0 + return False + + def _rebuild_search(self,ignore=None): + """ function called when view must be build, given a search text + in the top search bar + Remark: this method is overrides BaseModel as only unattached notes + must be shown + """ + self.total = 0 + if self.db.is_open(): + if self.search and self.search.text: + dlist = [h for h in self.sort_keys()\ + if self.search.match(h) and \ + h not in self.skip and h != ignore and \ + self.__unattached_note(h)] + else: + dlist = [h for h in self.sort_keys() \ + if h not in self.skip and h != ignore and \ + self.__unattached_note(h)] + self.displayed = len(dlist) + self.node_map.set_path_map(dlist) + else: + self.displayed = 0 + self.node_map.clear_map() + + def _rebuild_filter(self, ignore=None): + """ function called when view must be build, given filter options + in the filter sidebar + Remark: this method is overrides BaseModel as only unattached notes + must be shown + """ + self.total = 0 + if self.db.is_open(): + if self.search: + dlist = self.search.apply(self.db, + [ k for k in self.sort_keys()\ + if k != ignore and \ + self.__unattached_note(h)]) + else: + dlist = [ k for k in self.sort_keys() \ + if k != ignore and \ + self.__unattached_note(h)] + + self.displayed = len(dlist) + self.node_map.set_path_map(dlist) + else: + self.displayed = 0 + self.node_map.clear_map() + def on_get_n_columns(self): return len(self.fmap)+1