Zim

Merge lp:~fmos/zim/tags into lp:~jaap.karssenberg/zim/pyzim

Proposed by Fabian Stanke
Status: Merged
Merged at revision: 676
Proposed branch: lp:~fmos/zim/tags
Merge into: lp:~jaap.karssenberg/zim/pyzim
Diff against target: 68 lines (+52/-0)
1 file modified
zim/plugins/tags.py (+52/-0)
To merge this branch: bzr merge lp:~fmos/zim/tags
Reviewer Review Type Date Requested Status
Jaap Karssenberg Approve
Review via email: mp+181962@code.launchpad.net

Description of the change

Overrides PageTreeView.select_page with TagsPageTreeView.select_page to change page selection only if necessary.

To post a comment you must log in.
Revision history for this message
Fabian Stanke (fmos) wrote :

In principle the change in select_page could also be made globally, i.e. to PageTreeView.select_page.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Merged in pyzim-refactor

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'zim/plugins/tags.py'
2--- zim/plugins/tags.py 2013-04-30 13:48:57 +0000
3+++ zim/plugins/tags.py 2013-08-24 16:55:31 +0000
4@@ -48,6 +48,7 @@
5 '''
6
7 def select_page(self, path):
8+ '''Since there may be duplicates of each page, highlight all of them'''
9 oldpath = self.selected_page
10 self.selected_page = path
11
12@@ -630,6 +631,57 @@
13 data = pack_urilist((link,))
14 selectiondata.set(INTERNAL_PAGELIST_TARGET_NAME, 8, data)
15
16+ def select_page(self, path, vivificate=False):
17+ '''Select a page in the treeview if the page is not already selected
18+
19+ @param path: a notebook L{Path} object for the page
20+ @keyword vivificate: when C{True} the path is created
21+ temporarily when it did not yet exist
22+
23+ @returns: a gtk TreePath (tuple of intergers) or C{None}
24+ '''
25+ #~ print '!! SELECT', path
26+ model = self.get_model()
27+ if model is None:
28+ return None # index not yet initialized ...
29+
30+ # change selection only if necessary
31+ selected_path = self.get_selected_path()
32+ if path == selected_path:
33+ _, iter = self.get_selection().get_selected()
34+ treepath = model.get_path(iter)
35+ logger.debug('Already selected: "%s"', treepath)
36+ else:
37+ treepath = model.get_treepath(path)
38+ if treepath:
39+ # path existed, now select it
40+ self.select_treepath(treepath)
41+ elif vivificate:
42+ # path does not exist, but we can create it
43+ path = model.index.touch(path)
44+ treepath = model.get_treepath(path)
45+ assert treepath, 'BUG: failed to touch placeholder'
46+ self.select_treepath(treepath)
47+ else:
48+ # path does not exist and we are not going to create it
49+ return None
50+
51+ rowreference = gtk.TreeRowReference(model, treepath)
52+ # make reference before cleanup - path may change
53+
54+ if self._cleanup and self._cleanup.valid():
55+ mytreepath = self._cleanup.get_path()
56+ if mytreepath != treepath:
57+ indexpath = model.get_indexpath( model.get_iter(mytreepath) )
58+ #~ print '!! CLEANUP', indexpath
59+ model.index.cleanup(indexpath)
60+
61+ self._cleanup = rowreference
62+
63+ model.select_page(path) # highlight in model
64+
65+ return treepath
66+
67 # Need to register classes defining gobject signals
68 gobject.type_register(TagsPageTreeView)
69