From 0ec49507edcbf6956365df321444b413f1f92934 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Sat, 9 Jan 2010 16:16:52 +0000 Subject: [PATCH] Renable enter to expand nodes on the treeviews svn: r14005 --- src/gui/views/listview.py | 68 ++++++++++++++++++++++++++++--- src/plugins/view/personview.py | 10 ++++- src/plugins/view/placetreeview.py | 11 ++++- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/gui/views/listview.py b/src/gui/views/listview.py index eeea0e314..831320e54 100644 --- a/src/gui/views/listview.py +++ b/src/gui/views/listview.py @@ -61,9 +61,17 @@ import Utils from QuestionDialog import QuestionDialog, QuestionDialog2 from TransUtils import sgettext as _ +#---------------------------------------------------------------- +# +# Constants +# +#---------------------------------------------------------------- + NAVIGATION_NONE = -1 NAVIGATION_PERSON = 0 +LISTFLAT = 0 +LISTTREE = 1 #---------------------------------------------------------------- # @@ -101,6 +109,12 @@ class ListView(NavigationView): self.markup_required = markup dbstate.connect('database-changed', self.change_db) + def type_list(self): + """ + set the listtype, this governs eg keybinding + """ + return LISTFLAT + #################################################################### # Build interface #################################################################### @@ -124,7 +138,12 @@ class ListView(NavigationView): self.list.set_headers_clickable(True) self.list.set_fixed_height_mode(True) self.list.connect('button-press-event', self._button_press) - self.list.connect('key-press-event', self._key_press) + if self.type_list() == LISTFLAT: + # Flat list + self.list.connect('key-press-event', self._key_press) + else: + # Tree + self.list.connect('key-press-event', self._key_press_tree) if self.drag_info(): self.list.connect('drag_data_get', self.drag_data_get) self.list.connect('drag_begin', self.drag_begin) @@ -364,7 +383,7 @@ class ListView(NavigationView): if not handle or handle in self.selected_handles(): return - if self.model.get_flags() & gtk.TREE_MODEL_LIST_ONLY: + if self.type_list() == LISTFLAT: # Flat try: path = self.model.on_get_path(handle) @@ -376,8 +395,10 @@ class ListView(NavigationView): node = self.model.get_node(handle) if node: parent_node = self.model.on_iter_parent(node) - parent_path = self.model.on_get_path(parent_node) - self.list.expand_row(parent_path, 0) + if parent_node: + parent_path = self.model.on_get_path(parent_node) + if parent_path: + self.list.expand_row(parent_path, False) path = self.model.on_get_path(node) if path: @@ -739,7 +760,44 @@ class ListView(NavigationView): self.edit(obj) return True return False - + + def _key_press_tree(self, obj, event): + """ + Overwrite of listview key press + """ + if not self.dbstate.open: + return False + if not event.state or event.state in (gtk.gdk.MOD2_MASK, ): + if event.keyval in (gtk.keysyms.Return, gtk.keysyms.KP_Enter): + store, paths = self.selection.get_selected_rows() + if paths: + firstsel = paths[0] + firstnode = self.model.on_get_iter(firstsel) + if len(paths)==1 and firstnode.handle is None: + return self.expand_collapse_tree() + else: + self.edit(obj) + return True + return False + + def expand_collapse_tree(self): + """ + Expand or collapse the selected group node. + Return True if change done, False otherwise + """ + store, paths = self.selection.get_selected_rows() + if paths: + firstsel = paths[0] + firstnode = self.model.on_get_iter(firstsel) + if firstnode.handle: + return False + if self.list.row_expanded(firstsel): + self.list.collapse_row(firstsel) + else: + self.list.expand_row(firstsel, False) + return True + return False + def key_delete(self): self.remove(None) diff --git a/src/plugins/view/personview.py b/src/plugins/view/personview.py index 938dce197..91dfafa86 100644 --- a/src/plugins/view/personview.py +++ b/src/plugins/view/personview.py @@ -47,7 +47,7 @@ _LOG = logging.getLogger(".gui.personview") #------------------------------------------------------------------------- import gen.lib from gui.views.navigationview import NAVIGATION_PERSON -from gui.views.listview import ListView +from gui.views.listview import ListView, LISTTREE from gui.views.treemodels import PeopleModel import Utils from BasicUtils import name_displayer @@ -121,7 +121,13 @@ class PersonView(ListView): } config.connect("interface.filter", self.filter_toggle) - + + def type_list(self): + """ + set the listtype, this governs eg keybinding + """ + return LISTTREE + def column_ord_setfunc(self, clist): self.dbstate.db.set_person_column_order(clist) diff --git a/src/plugins/view/placetreeview.py b/src/plugins/view/placetreeview.py index 5f9779f4a..e7a051907 100644 --- a/src/plugins/view/placetreeview.py +++ b/src/plugins/view/placetreeview.py @@ -28,6 +28,7 @@ Place Tree View # Gramps modules # #------------------------------------------------------------------------- +from gui.views.listview import LISTTREE from gui.views.placebaseview import PlaceBaseView from gui.views.treemodels import PlaceTreeModel import gen.lib @@ -55,6 +56,12 @@ class PlaceTreeView(PlaceBaseView): PlaceBaseView.__init__(self, dbstate, uistate, _('Tree'), PlaceTreeModel) + def type_list(self): + """ + set the listtype, this governs eg keybinding + """ + return LISTTREE + def get_viewtype_stock(self): """ Override the default icon. Set for hierarchical view. @@ -67,9 +74,9 @@ class PlaceTreeView(PlaceBaseView): """ PlaceBaseView.define_actions(self) - self._add_action('OpenBranch', None, _("Expand Rows"), + self._add_action('OpenBranch', None, _("Expand this Entire Group"), callback=self.open_branch) - self._add_action('CloseBranch', None, _("Collapse Rows"), + self._add_action('CloseBranch', None, _("Collapse this Entire Group"), callback=self.close_branch) self._add_action('OpenAllNodes', None, _("Expand all Nodes"), callback=self.open_all_nodes)