diff --git a/gramps/gui/editors/displaytabs/backreflist.py b/gramps/gui/editors/displaytabs/backreflist.py index 715fa7568..2af843863 100644 --- a/gramps/gui/editors/displaytabs/backreflist.py +++ b/gramps/gui/editors/displaytabs/backreflist.py @@ -89,7 +89,9 @@ class BackRefList(EmbeddedList): def is_empty(self): return self.model.count == 0 - def _create_buttons(self, share=False, move=False, jump=False, top_label=None): + def _create_buttons(self, + share=False, clone=False, move=False, jump=False, + top_label=None): """ Create a button box consisting of one button: Edit. This button box is then appended hbox (self). diff --git a/gramps/gui/editors/displaytabs/buttontab.py b/gramps/gui/editors/displaytabs/buttontab.py index c8fd12b04..dd685bbf9 100644 --- a/gramps/gui/editors/displaytabs/buttontab.py +++ b/gramps/gui/editors/displaytabs/buttontab.py @@ -3,6 +3,7 @@ # # Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2009-2011 Gary Burton +# 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 @@ -70,13 +71,16 @@ class ButtonTab(GrampsTab): 'del' : _('Remove'), 'edit' : _('Edit'), 'share' : _('Share'), + 'clone' : _('Clone'), 'jump' : _('Jump To'), 'up' : _('Move Up'), 'down' : _('Move Down'), } - def __init__(self, dbstate, uistate, track, name, share_button=False, - move_buttons=False, jump_button=False, top_label=None): + def __init__(self, dbstate, uistate, track, name, + share_button=False, clone_button=False, + move_buttons=False, jump_button=False, + top_label=None): """ Similar to the base class, except after Build. @@ -95,6 +99,8 @@ class ButtonTab(GrampsTab): @type name: str/unicode @param share_button: Add a share button to the Notebook tab or not @type name: bool + @param clone_button: Add a clone button to the Notebook tab or not + @type name: bool @param move_buttons: Add up and down button to the Notebook tab or not @type name: bool @param jump_button: Add a goto button @@ -103,17 +109,20 @@ class ButtonTab(GrampsTab): @type top_label: string or None for no label """ self.dirty_selection = False - GrampsTab.__init__(self,dbstate, uistate, track, name) - self._create_buttons(share_button, move_buttons, jump_button, top_label) + GrampsTab.__init__(self, dbstate, uistate, track, name) + self._create_buttons(share_button, clone_button, + move_buttons, jump_button, + top_label) - def _create_buttons(self, share_button, move_buttons, jump_button, - top_label): + def _create_buttons(self, + share_button, clone_button, move_buttons, jump_button, + top_label): """ Create a button box consisting of three buttons, one for Add, one for Edit, and one for Delete. - Add buttons for Share, Move and Jump depending on parameters. This - button box is then appended hbox (self). + Add buttons for Share, Clone, Move and Jump depending on parameters. + This button box is then appended hbox (self). Prepend a label if top_label given Note: some ButtonTab subclasses override this method. @@ -141,6 +150,13 @@ class ButtonTab(GrampsTab): else: self.share_btn = None + if clone_button: + self.clone_btn = SimpleButton('gramps-clone', self.clone_button_clicked) + self.clone_btn.set_tooltip_text(self._MSG['clone']) + self.track_ref_for_deletion("clone_btn") + else: + self.clone_btn = None + if move_buttons: self.up_btn = SimpleButton('go-up', self.up_button_clicked) self.up_btn.set_tooltip_text(self._MSG['up']) @@ -167,6 +183,8 @@ class ButtonTab(GrampsTab): if share_button: hbox.pack_start(self.share_btn, False, True, 0) hbox.pack_start(self.edit_btn, False, True, 0) + if clone_button: + hbox.pack_start(self.clone_btn, False, True, 0) hbox.pack_start(self.del_btn, False, True, 0) if move_buttons: hbox.pack_start(self.up_btn, False, True, 0) @@ -182,6 +200,8 @@ class ButtonTab(GrampsTab): self.del_btn.set_sensitive(False) if share_button: self.share_btn.set_sensitive(False) + if clone_button: + self.clone_btn.set_sensitive(False) if jump_button and self.jump_btn: self.jump_btn.set_sensitive(False) if move_buttons: @@ -246,6 +266,13 @@ class ButtonTab(GrampsTab): """ print("Uncaught Share clicked") + def clone_button_clicked(self, obj): + """ + Function called with the Clone button is clicked. This function + should be overridden by the derived class. + """ + print("Uncaught Clone clicked") + def jump_button_clicked(self, obj): """ Function called with the Jump button is clicked. This function @@ -284,8 +311,8 @@ class ButtonTab(GrampsTab): def _selection_changed(self, obj=None): """ - Attached to the selection's 'changed' signal. Checks - to see if anything is selected. If it is, the edit and + Attached to the selection's 'changed' signal. Checks to see + if anything is selected. If it is, the edit, clone and delete buttons are enabled, otherwise the are disabled. """ # Comparing to None is important, as empty strings @@ -296,6 +323,8 @@ class ButtonTab(GrampsTab): return if self.get_selected() is not None: self.edit_btn.set_sensitive(True) + if self.clone_btn: + self.clone_btn.set_sensitive(True) if self.jump_btn: self.jump_btn.set_sensitive(True) if not self.dbstate.db.readonly: @@ -307,6 +336,8 @@ class ButtonTab(GrampsTab): # self.down_btn.set_sensitive(True) else: self.edit_btn.set_sensitive(False) + if self.clone_btn: + self.clone_btn.set_sensitive(False) if self.jump_btn: self.jump_btn.set_sensitive(False) if not self.dbstate.db.readonly: diff --git a/gramps/gui/editors/displaytabs/embeddedlist.py b/gramps/gui/editors/displaytabs/embeddedlist.py index 7bbeaf0a3..9bf818f4f 100644 --- a/gramps/gui/editors/displaytabs/embeddedlist.py +++ b/gramps/gui/editors/displaytabs/embeddedlist.py @@ -76,13 +76,16 @@ class EmbeddedList(ButtonTab): _DND_EXTRA = None def __init__(self, dbstate, uistate, track, name, build_model, - share_button=False, move_buttons=False, jump_button=False, + share_button=False, clone_button=False, + move_buttons=False, jump_button=False, top_label=None): """ Create a new list, using the passed build_model to populate the list. """ - ButtonTab.__init__(self, dbstate, uistate, track, name, share_button, - move_buttons, jump_button, top_label) + ButtonTab.__init__(self, dbstate, uistate, track, name, + share_button, clone_button, + move_buttons, jump_button, + top_label) self.changed = False self.model = None diff --git a/gramps/gui/editors/displaytabs/eventembedlist.py b/gramps/gui/editors/displaytabs/eventembedlist.py index 30e7bcb62..24bc3e4da 100644 --- a/gramps/gui/editors/displaytabs/eventembedlist.py +++ b/gramps/gui/editors/displaytabs/eventembedlist.py @@ -3,6 +3,7 @@ # # Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2009 B. Malengier +# 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 @@ -65,6 +66,7 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList): 'del' : _('Remove the selected family event'), 'edit' : _('Edit the selected family event or edit person'), 'share' : _('Share an existing event'), + 'clone' : _('Clone an existing event'), 'up' : _('Move the selected event upwards'), 'down' : _('Move the selected event downwards'), } @@ -96,7 +98,7 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList): self._data = [] DbGUIElement.__init__(self, dbstate.db) GroupEmbeddedList.__init__(self, dbstate, uistate, track, _('_Events'), - build_model, share_button=True, + build_model, share_button=True, clone_button=True, move_buttons=True, **kwargs) def _connect_db_signals(self): @@ -286,6 +288,27 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList): key = self._groups[ref[0]][0] self.editnotworkgroup(key) + def clone_button_clicked(self, obj): + 'Function called with the Clone button is clicked.' + source_ref = self.get_selected() + if source_ref and \ + source_ref[1] is not None \ + and source_ref[0] == self._WORKGROUP: + source_event = self.dbstate.db.get_event_from_handle(source_ref[1].ref) + + try: + ref = EventRef(source=source_ref[1]) + + event = Event(source=source_event) + event.set_gramps_id(self.dbstate.db.find_next_event_gramps_id()) + event.set_handle(None) + + self.get_ref_editor()( + self.dbstate, self.uistate, self.track, + event, ref, self.object_added) + except WindowActiveError: + pass + def object_added(self, reference, primary): reference.ref = primary.handle data = self.get_data()[self._WORKGROUP] diff --git a/gramps/gui/editors/displaytabs/groupembeddedlist.py b/gramps/gui/editors/displaytabs/groupembeddedlist.py index a619c4134..266799ae2 100644 --- a/gramps/gui/editors/displaytabs/groupembeddedlist.py +++ b/gramps/gui/editors/displaytabs/groupembeddedlist.py @@ -60,17 +60,21 @@ class GroupEmbeddedList(EmbeddedList): _WORKGROUP = 0 def __init__(self, dbstate, uistate, track, name, build_model, - share_button=False, move_buttons=False, jump_button=False, **kwargs): + share_button=False, clone_button=False, + move_buttons=False, jump_button=False, **kwargs): """ Create a new list, using the passed build_model to populate the list. """ self.kwargs = kwargs - EmbeddedList.__init__(self, dbstate, uistate, track, name, build_model, - share_button, move_buttons, jump_button) - #connect click on the first column + EmbeddedList.__init__(self, dbstate, uistate, track, name, build_model, + share_button, clone_button, + move_buttons, jump_button) + + # connect click on the first column self.columns[0].connect('clicked', self.groupcol_click) for col in self.columns[1:]: col.connect('clicked', self.col_click) + self.dbsort = True def construct_model(self): diff --git a/gramps/gui/editors/displaytabs/personeventembedlist.py b/gramps/gui/editors/displaytabs/personeventembedlist.py index 320f04777..4857543b5 100644 --- a/gramps/gui/editors/displaytabs/personeventembedlist.py +++ b/gramps/gui/editors/displaytabs/personeventembedlist.py @@ -57,6 +57,7 @@ class PersonEventEmbedList(EventEmbedList): 'del' : _('Remove the selected personal event'), 'edit' : _('Edit the selected personal event or edit family'), 'share' : _('Share an existing event'), + 'clone' : _('Clone an existing event'), 'up' : _('Move the selected event upwards or change family order'), 'down' : _('Move the selected event downwards or change family order'), }