diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index ce36b63df..8f1d76a55 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -8,6 +8,10 @@ Recursively walk the items under a given item and lower the track entry. + * src/DisplayState.py: Factor out recursive action function. + * src/EditPerson.py: Use person handle to identify the window. + * src/EventEdit.py: Use more descriptive menu label. + 2005-12-21 Richard Taylor * src/EditSource.py: fixed small mistake in display_references diff --git a/gramps2/src/DisplayState.py b/gramps2/src/DisplayState.py index 2dd7c363a..2a1997a8f 100644 --- a/gramps2/src/DisplayState.py +++ b/gramps2/src/DisplayState.py @@ -201,30 +201,35 @@ class GrampsWindowManager: def close_track(self,track): # This is called when item needs to be closed # Closes all its children and then removes the item from the tree. - #print "1", track item = self.get_item_from_track(track) - self.close_item(item) + self.recursive_action(item,self.close_item) # This only needs to be run once for the highest level point # to remove. self.remove_item(track) - def close_item(self,item): - # This function calls children's close_item() method - # to let the children go away cleanly. + def recursive_action(self,item,func,*args): + # This function recursively calls itself over the child items + # starting with the given item. + # Eventualy, every non-list item (leaf) will be reached + # and the func(item,*args) will be called on that item. if type(item) == list: # If this item is a branch # close the children except for the first one for sub_item in item[1:]: - self.close_item(sub_item) + self.recursive_action(sub_item,func,*args) # return the first child last_item = item[0] else: # This item is a leaf -- no children to close # return itself last_item = item - if last_item.window_id: - del self.id2item[last_item.window_id] - last_item.window.destroy() + func(last_item,*args) + + def close_item(self,item,*args): + # Given an item, close its window and remove it's ID from the dict + if item.window_id: + del self.id2item[item.window_id] + item.window.destroy() def remove_item(self,track): # We need the whole gymnastics below because our item @@ -242,25 +247,15 @@ class GrampsWindowManager: # so that it's track is down by one on this level for ix in range(child_in_parent,len(parent_item)): item = parent_item[ix] - self.move_item_down(item,len(track)-1) + self.recursive_action(item,self.move_item_down,len(track)-1) # Rebuild menu self.build_windows_menu() - def move_item_down(self,item,index): - # This function calls children's move_item_down() method - # to subtract 1 from the children's track component given by index. - if type(item) == list: - # If this item is a branch - # move down the children except for the first one - for sub_item in item[1:]: - self.move_item_down(sub_item,index) - # return the first child - last_item = item[0] - else: - # This item is a leaf -- no children to move down - # return itself - last_item = item - last_item.track[index] -= 1 + def move_item_down(self,item,*args): + # Given an item and an index, adjust the item's track + # by subtracting 1 from that index's level + index = args[0] + item.track[index] -= 1 def add_item(self,track,item): # if the item is identifiable then we need to remember diff --git a/gramps2/src/EditPerson.py b/gramps2/src/EditPerson.py index 05ebbb0b9..a3a32db47 100644 --- a/gramps2/src/EditPerson.py +++ b/gramps2/src/EditPerson.py @@ -107,8 +107,15 @@ class EditPerson(DisplayState.ManagedWindow): if not win_menu_label.strip(): win_menu_label = _("New Person") + if person: + self.orig_handle = person.get_handle() + win_key = self.orig_handle + else: + self.orig_handle = "" + win_key = self + DisplayState.ManagedWindow.__init__( - self, uistate, [], self, win_menu_label, _('Edit Person')) + self, uistate, [], win_key, win_menu_label, _('Edit Person')) if self.already_exist: return @@ -118,11 +125,6 @@ class EditPerson(DisplayState.ManagedWindow): self.uistate = uistate self.retval = const.UPDATE_PERSON - if person: - self.orig_handle = person.get_handle() - else: - self.orig_handle = "" - # UGLY HACK to refresh person object from handle if that exists # done to ensure that the person object is not stale, as it could # have been changed by something external (merge, tool, etc). diff --git a/gramps2/src/EventEdit.py b/gramps2/src/EventEdit.py index a24f2abba..025350501 100644 --- a/gramps2/src/EventEdit.py +++ b/gramps2/src/EventEdit.py @@ -451,7 +451,17 @@ class EventRefEditor(DisplayState.ManagedWindow): win_key = event_ref else: win_key = self - submenu_label =_('Event Reference') + if event: + if event.get_type()[0] == RelLib.Event.CUSTOM: + event_name = event.get_type()[1] + else: + try: + event_name = Utils.personal_events[event.get_type()[0]] + except: + event_name = Utils.family_events[event.get_type()[0]] + submenu_label = _('Event: %s') % event_name + else: + submenu_label = _('New Event') menu_label = _('Event Reference Editor') DisplayState.ManagedWindow.__init__(