Renable enter to expand nodes on the treeviews

svn: r14005
This commit is contained in:
Benny Malengier 2010-01-09 16:16:52 +00:00
parent 08c8edb43d
commit 0ec49507ed
3 changed files with 80 additions and 9 deletions

View File

@ -61,9 +61,17 @@ import Utils
from QuestionDialog import QuestionDialog, QuestionDialog2 from QuestionDialog import QuestionDialog, QuestionDialog2
from TransUtils import sgettext as _ from TransUtils import sgettext as _
#----------------------------------------------------------------
#
# Constants
#
#----------------------------------------------------------------
NAVIGATION_NONE = -1 NAVIGATION_NONE = -1
NAVIGATION_PERSON = 0 NAVIGATION_PERSON = 0
LISTFLAT = 0
LISTTREE = 1
#---------------------------------------------------------------- #----------------------------------------------------------------
# #
@ -101,6 +109,12 @@ class ListView(NavigationView):
self.markup_required = markup self.markup_required = markup
dbstate.connect('database-changed', self.change_db) dbstate.connect('database-changed', self.change_db)
def type_list(self):
"""
set the listtype, this governs eg keybinding
"""
return LISTFLAT
#################################################################### ####################################################################
# Build interface # Build interface
#################################################################### ####################################################################
@ -124,7 +138,12 @@ class ListView(NavigationView):
self.list.set_headers_clickable(True) self.list.set_headers_clickable(True)
self.list.set_fixed_height_mode(True) self.list.set_fixed_height_mode(True)
self.list.connect('button-press-event', self._button_press) 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(): if self.drag_info():
self.list.connect('drag_data_get', self.drag_data_get) self.list.connect('drag_data_get', self.drag_data_get)
self.list.connect('drag_begin', self.drag_begin) self.list.connect('drag_begin', self.drag_begin)
@ -364,7 +383,7 @@ class ListView(NavigationView):
if not handle or handle in self.selected_handles(): if not handle or handle in self.selected_handles():
return return
if self.model.get_flags() & gtk.TREE_MODEL_LIST_ONLY: if self.type_list() == LISTFLAT:
# Flat # Flat
try: try:
path = self.model.on_get_path(handle) path = self.model.on_get_path(handle)
@ -376,8 +395,10 @@ class ListView(NavigationView):
node = self.model.get_node(handle) node = self.model.get_node(handle)
if node: if node:
parent_node = self.model.on_iter_parent(node) parent_node = self.model.on_iter_parent(node)
parent_path = self.model.on_get_path(parent_node) if parent_node:
self.list.expand_row(parent_path, 0) 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) path = self.model.on_get_path(node)
if path: if path:
@ -739,7 +760,44 @@ class ListView(NavigationView):
self.edit(obj) self.edit(obj)
return True return True
return False 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): def key_delete(self):
self.remove(None) self.remove(None)

View File

@ -47,7 +47,7 @@ _LOG = logging.getLogger(".gui.personview")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.lib import gen.lib
from gui.views.navigationview import NAVIGATION_PERSON 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 from gui.views.treemodels import PeopleModel
import Utils import Utils
from BasicUtils import name_displayer from BasicUtils import name_displayer
@ -121,7 +121,13 @@ class PersonView(ListView):
} }
config.connect("interface.filter", self.filter_toggle) 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): def column_ord_setfunc(self, clist):
self.dbstate.db.set_person_column_order(clist) self.dbstate.db.set_person_column_order(clist)

View File

@ -28,6 +28,7 @@ Place Tree View
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gui.views.listview import LISTTREE
from gui.views.placebaseview import PlaceBaseView from gui.views.placebaseview import PlaceBaseView
from gui.views.treemodels import PlaceTreeModel from gui.views.treemodels import PlaceTreeModel
import gen.lib import gen.lib
@ -55,6 +56,12 @@ class PlaceTreeView(PlaceBaseView):
PlaceBaseView.__init__(self, dbstate, uistate, PlaceBaseView.__init__(self, dbstate, uistate,
_('Tree'), PlaceTreeModel) _('Tree'), PlaceTreeModel)
def type_list(self):
"""
set the listtype, this governs eg keybinding
"""
return LISTTREE
def get_viewtype_stock(self): def get_viewtype_stock(self):
""" """
Override the default icon. Set for hierarchical view. Override the default icon. Set for hierarchical view.
@ -67,9 +74,9 @@ class PlaceTreeView(PlaceBaseView):
""" """
PlaceBaseView.define_actions(self) PlaceBaseView.define_actions(self)
self._add_action('OpenBranch', None, _("Expand Rows"), self._add_action('OpenBranch', None, _("Expand this Entire Group"),
callback=self.open_branch) callback=self.open_branch)
self._add_action('CloseBranch', None, _("Collapse Rows"), self._add_action('CloseBranch', None, _("Collapse this Entire Group"),
callback=self.close_branch) callback=self.close_branch)
self._add_action('OpenAllNodes', None, _("Expand all Nodes"), self._add_action('OpenAllNodes', None, _("Expand all Nodes"),
callback=self.open_all_nodes) callback=self.open_all_nodes)