diff --git a/gramps/gui/editors/displaytabs/eventbackreflist.py b/gramps/gui/editors/displaytabs/eventbackreflist.py index d88959f89..fafe995ae 100644 --- a/gramps/gui/editors/displaytabs/eventbackreflist.py +++ b/gramps/gui/editors/displaytabs/eventbackreflist.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2018 Alois Poettker # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,10 +28,24 @@ from .backrefmodel import BackRefModel from .backreflist import BackRefList class EventBackRefList(BackRefList): + """""" + def __init__(self, dbstate, uistate, track, obj, option=None, callback=None): + """ + Connector class between events and back reference mechanism + """ + self.option = option - def __init__(self, dbstate, uistate, track, obj, callback=None): BackRefList.__init__(self, dbstate, uistate, track, obj, BackRefModel, callback) def get_icon_name(self): return 'gramps-event' + + def get_data(self): + """ + Method overrides 'get_data' from BackRefList.py + """ + if self.option and self.option['action']: + return [] + else: + return self.obj diff --git a/gramps/gui/editors/editevent.py b/gramps/gui/editors/editevent.py index f2726f292..0d7ab6c1e 100644 --- a/gramps/gui/editors/editevent.py +++ b/gramps/gui/editors/editevent.py @@ -4,6 +4,7 @@ # Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2009 Gary Burton # Copyright (C) 2011 Tim G L Lyons +# Copyright (C) 2018 Alois Poettker # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -71,6 +72,9 @@ WIKI_HELP_SEC = _('manual|New_Event_dialog') class EditEvent(EditPrimary): def __init__(self, dbstate, uistate, track, event, callback=None): + """""" + self.callback = callback + self.action = uistate.action.split('-')[1] EditPrimary.__init__(self, dbstate, uistate, track, event, dbstate.db.get_event_from_handle, @@ -86,18 +90,27 @@ class EditEvent(EditPrimary): return Event() def get_menu_title(self): + """ compile menu title out of different actions """ handle = self.obj.get_handle() + + event_action, event_name = '', '' if handle: + if self.action == 'clone': + event_action = _('Clone') + if self.action == 'edit': + event_action = _('Edit') + who = get_participant_from_event(self.db, handle) desc = self.obj.get_description() - event_name = self.obj.get_type() - if desc: - event_name = '%s - %s' % (event_name, desc) + event_name = self.obj.get_type().string if who: - event_name = '%s - %s' % (event_name, who) - dialog_title = _('Event: %s') % event_name + event_name = ': %s - %s' % (event_name, who) + elif desc: + event_name = ': %s - %s' % (event_name, desc) else: - dialog_title = _('New Event') + event_action = _('New') + + dialog_title = _('%s Event%s') % (event_action, event_name) return dialog_title def get_custom_events(self): @@ -207,10 +220,14 @@ class EditEvent(EditPrimary): self._add_tab(notebook, self.attr_list) handle_list = self.dbstate.db.find_backlink_handles(self.obj.handle) + # Additional variables in 'EventBackRefList' injected via 'option' + backref_option = {} + backref_option['action'] = self.action == 'clone' self.backref_list = EventBackRefList(self.dbstate, self.uistate, self.track, - handle_list) + handle_list, + option=backref_option) self._add_tab(notebook, self.backref_list) self._setup_notebook_tabs(notebook) @@ -269,7 +286,11 @@ class EditEvent(EditPrimary): self.db) as trans: self.db.add_event(self.obj, trans) else: - if self.data_has_changed(): + if self.action == 'clone': + with DbTxn(_("Clone Event"), self.db) as trans: + self.obj.handle = None + self.db.add_event(self.obj, trans) + elif self.data_has_changed(): with DbTxn(_("Edit Event (%s)") % self.obj.get_gramps_id(), self.db) as trans: if not self.obj.get_gramps_id(): @@ -287,7 +308,6 @@ class EditEvent(EditPrimary): entered date when importing from a XML file, so we can get an incorrect fail. """ - if self.db.readonly: return False elif self.obj.handle: diff --git a/gramps/gui/editors/editeventref.py b/gramps/gui/editors/editeventref.py index 676b1d78c..053b70bf6 100644 --- a/gramps/gui/editors/editeventref.py +++ b/gramps/gui/editors/editeventref.py @@ -241,7 +241,7 @@ class EditEventRef(EditReference): self.uistate, self.track, self.db.find_backlink_handles(self.source.handle), - self.enable_warnbox) + callback=self.enable_warnbox) self._add_tab(notebook, self.backref_tab) self.track_ref_for_deletion("backref_tab") diff --git a/gramps/plugins/view/eventview.py b/gramps/plugins/view/eventview.py index e133406fb..c369799f1 100644 --- a/gramps/plugins/view/eventview.py +++ b/gramps/plugins/view/eventview.py @@ -3,7 +3,7 @@ # Copyright (C) 2001-2007 Donald N. Allingham # Copyright (C) 2008 Gary Burton # Copyright (C) 2011 Tim G L Lyons -# Copyright (C) 2017 Alois Poettker +# Copyright (C) 2018 Alois Poettker # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ Provide the event view. # Standard python modules # #------------------------------------------------------------------------- +import copy import logging _LOG = logging.getLogger(".plugins.eventview") @@ -40,16 +41,16 @@ _LOG = logging.getLogger(".plugins.eventview") from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -from gramps.gui.dialog import ErrorDialog, MultiSelectDialog, QuestionDialog from gramps.gen.errors import WindowActiveError from gramps.gen.lib import Event +from gramps.gen.plug import CATEGORY_QR_EVENT from gramps.gen.utils.string import data_recover_msg +from gramps.gui.dialog import ErrorDialog, MultiSelectDialog, QuestionDialog from gramps.gui.ddtargets import DdTargets from gramps.gui.editors import EditEvent, DeleteEventQuery from gramps.gui.filters.sidebar import EventSidebarFilter from gramps.gui.merge import MergeEvent -from gramps.gen.plug import CATEGORY_QR_EVENT from gramps.gui.views.bookmarks import EventBookmarks from gramps.gui.views.listview import ListView, TEXT, MARKUP, ICON from gramps.gui.views.treemodels import EventModel @@ -97,6 +98,7 @@ class EventView(ListView): EDIT_MSG = _("Edit the selected event") DEL_MSG = _("Delete the selected event") MERGE_MSG = _("Merge the selected events") + CLONE_MSG = _("Clones the selected event") FILTER_TYPE = "Event" QR_CATEGORY = CATEGORY_QR_EVENT @@ -124,6 +126,8 @@ class EventView(ListView): 'BackSpace' : self.key_delete, }) + # Identify the requested action in several sublevel + uistate.action = '' uistate.connect('nameformat-changed', self.build_tree) uistate.connect('placeformat-changed', self.build_tree) @@ -174,6 +178,7 @@ class EventView(ListView): + @@ -188,6 +193,7 @@ class EventView(ListView): + @@ -198,6 +204,7 @@ class EventView(ListView): + @@ -205,8 +212,13 @@ class EventView(ListView): def define_actions(self): ListView.define_actions(self) + self.edit_action.add_actions([ + ('Clone', 'gramps-clone', _('Clone...'), None, + self.CLONE_MSG, self.clone), + ]) self._add_action('FilterEdit', None, - _('Event Filter Editor'), callback=self.filter_editor) + _('Event Filter Editor'), + callback=self.filter_editor,) self._add_action('QuickReport', None, _("Quick View"), None, None, None) @@ -219,6 +231,7 @@ class EventView(ListView): def add(self, obj): try: + self.uistate.action = 'event-add' EditEvent(self.dbstate, self.uistate, [], Event()) except WindowActiveError: pass @@ -282,6 +295,7 @@ class EventView(ListView): for handle in self.selected_handles(): event = self.dbstate.db.get_event_from_handle(handle) try: + self.uistate.action = 'event-edit' EditEvent(self.dbstate, self.uistate, [], event) except WindowActiveError: pass @@ -290,16 +304,38 @@ class EventView(ListView): """ Merge the selected events. """ - mlist = self.selected_handles() + merge_list = self.selected_handles() - if len(mlist) != 2: + if len(merge_list) != 2: msg = _("Cannot merge event objects.") msg2 = _("Exactly two events must be selected to perform a merge. " "A second object can be selected by holding down the " "control key while clicking on the desired event.") ErrorDialog(msg, msg2, parent=self.uistate.window) else: - MergeEvent(self.dbstate, self.uistate, [], mlist[0], mlist[1]) + self.uistate.action = 'event-merge' + MergeEvent(self.dbstate, self.uistate, [], merge_list[0], merge_list[1]) + + def clone(self, obj): + """ + Clones the selected event. + """ + event_list = self.selected_handles() + + if len(event_list) != 1: + msg = _("Cannot clone event object.") + msg2 = _("Exactly one event must be selected to perform a clone.") + ErrorDialog(msg, msg2, parent=self.uistate.window) + else: + event = Event() + event = copy.deepcopy(self.dbstate.db.get_event_from_handle(event_list[0])) + event.gramps_id = None + + try: + self.uistate.action = 'event-clone' + EditEvent(self.dbstate, self.uistate, [], event) + except WindowActiveError: + pass def tag_updated(self, handle_list): """ diff --git a/images/hicolor/16x16/actions/gramps-clone.png b/images/hicolor/16x16/actions/gramps-clone.png new file mode 100644 index 000000000..a8b5edaff Binary files /dev/null and b/images/hicolor/16x16/actions/gramps-clone.png differ diff --git a/images/hicolor/22x22/actions/gramps-clone.png b/images/hicolor/22x22/actions/gramps-clone.png new file mode 100644 index 000000000..d2144b8ad Binary files /dev/null and b/images/hicolor/22x22/actions/gramps-clone.png differ diff --git a/images/hicolor/24x24/actions/gramps-clone.png b/images/hicolor/24x24/actions/gramps-clone.png new file mode 100644 index 000000000..e2c8f029b Binary files /dev/null and b/images/hicolor/24x24/actions/gramps-clone.png differ diff --git a/images/hicolor/48x48/actions/gramps-clone.png b/images/hicolor/48x48/actions/gramps-clone.png new file mode 100644 index 000000000..df054a60e Binary files /dev/null and b/images/hicolor/48x48/actions/gramps-clone.png differ diff --git a/images/hicolor/gramps-clone.png b/images/hicolor/gramps-clone.png new file mode 100644 index 000000000..e2c8f029b Binary files /dev/null and b/images/hicolor/gramps-clone.png differ diff --git a/images/hicolor/scalable/actions/gramps-clone.svg b/images/hicolor/scalable/actions/gramps-clone.svg new file mode 100644 index 000000000..de1b3d548 --- /dev/null +++ b/images/hicolor/scalable/actions/gramps-clone.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + +