From ab52d0988e4ca29e8d3df8cf41d2561585769806 Mon Sep 17 00:00:00 2001 From: Matthias Kemmer Date: Fri, 28 Jun 2019 16:08:39 +0200 Subject: [PATCH] Remove tag from selected rows --- gramps/gui/views/tags.py | 33 +++++++++++++++++++++++-- gramps/plugins/lib/libpersonview.py | 8 ++++++ gramps/plugins/lib/libplaceview.py | 8 ++++++ gramps/plugins/view/citationlistview.py | 8 ++++++ gramps/plugins/view/citationtreeview.py | 12 +++++++++ gramps/plugins/view/eventview.py | 8 ++++++ gramps/plugins/view/familyview.py | 8 ++++++ gramps/plugins/view/mediaview.py | 8 ++++++ gramps/plugins/view/noteview.py | 8 ++++++ gramps/plugins/view/repoview.py | 8 ++++++ gramps/plugins/view/sourceview.py | 8 ++++++ 11 files changed, 115 insertions(+), 2 deletions(-) diff --git a/gramps/gui/views/tags.py b/gramps/gui/views/tags.py index 5f0eb42bd..c3f54e658 100644 --- a/gramps/gui/views/tags.py +++ b/gramps/gui/views/tags.py @@ -241,14 +241,21 @@ class Tags(DbGUIElement): tag_menu = '' menuitem = ''' - win.TAG-%s + win.%s %s ''' for tag_name, handle in self.__tag_list: - tag_menu += menuitem % (handle, escape(tag_name)) + tag_menu += menuitem % ("TAG-%s" % handle, + "Add tag '%s'" % tag_name) actions.append(('TAG-%s' % handle, make_callback(self.tag_selected_rows, handle))) + for tag_name, handle in self.__tag_list: + tag_menu += menuitem % ("R-TAG-%s" % handle, + "Remove tag '%s'" % tag_name) + actions.append(('R-TAG-%s' % handle, + make_callback(self.remove_tag_selected_rows, + handle))) tag_menu = TAG_MENU % tag_menu self.tag_ui = [TAG_1 % tag_menu, TAG_2, TAG_3 % tag_menu] @@ -315,6 +322,28 @@ class Tags(DbGUIElement): view.add_tag(trans, object_handle, tag_handle) status.end() + def remove_tag_selected_rows(self, tag_handle): + """ + Remove tag from selected rows. + """ + view = self.uistate.viewmanager.active_page + selected = view.selected_handles() + # Make the dialog modal so that the user can't start another + # database transaction while the one setting tags is still running. + pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog, + ("", self.uistate.window, Gtk.DialogFlags.MODAL), popup_time=2) + status = progressdlg.LongOpStatus(msg=_("Adding Tags"), + total_steps=len(selected), + interval=len(selected)//20) + pmon.add_op(status) + tag = self.db.get_tag_from_handle(tag_handle) + msg = _('Tag Selection (%s)') % tag.get_name() + with DbTxn(msg, self.db) as trans: + for object_handle in selected: + status.heartbeat() + view.remove_tag(trans, object_handle, tag_handle) + status.end() + def cb_menu_position(*args): """ Determine the position of the popup menu. diff --git a/gramps/plugins/lib/libpersonview.py b/gramps/plugins/lib/libpersonview.py index 8fac9d11c..84c7bde32 100644 --- a/gramps/plugins/lib/libpersonview.py +++ b/gramps/plugins/lib/libpersonview.py @@ -559,6 +559,14 @@ class BasePersonView(ListView): person.add_tag(tag_handle) self.dbstate.db.commit_person(person, transaction) + def remove_tag(self, transaction, person_handle, tag_handle): + """ + Remove the given tag from the given person. + """ + person = self.dbstate.db.get_person_from_handle(person_handle) + person.remove_tag(tag_handle) + self.dbstate.db.commit_person(person, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/lib/libplaceview.py b/gramps/plugins/lib/libplaceview.py index 57b823c9e..4bbb309b4 100644 --- a/gramps/plugins/lib/libplaceview.py +++ b/gramps/plugins/lib/libplaceview.py @@ -595,6 +595,14 @@ class PlaceBaseView(ListView): place.add_tag(tag_handle) self.dbstate.db.commit_place(place, transaction) + def remove_tag(self, transaction, place_handle, tag_handle): + """ + Remove the given tag from the given place. + """ + place = self.dbstate.db.get_place_from_handle(place_handle) + place.remove_tag(tag_handle) + self.dbstate.db.commit_place(place, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/citationlistview.py b/gramps/plugins/view/citationlistview.py index 8e7a4b1c0..d0e6b5e97 100644 --- a/gramps/plugins/view/citationlistview.py +++ b/gramps/plugins/view/citationlistview.py @@ -453,6 +453,14 @@ class CitationListView(ListView): citation.add_tag(tag_handle) self.dbstate.db.commit_citation(citation, transaction) + def remove_tag(self, transaction, citation_handle, tag_handle): + """ + Remove the given tag from the given citation. + """ + citation = self.dbstate.db.get_citation_from_handle(citation_handle) + citation.remove_tag(tag_handle) + self.dbstate.db.commit_citation(citation, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/citationtreeview.py b/gramps/plugins/view/citationtreeview.py index 8d602ad45..c1bcf41fa 100644 --- a/gramps/plugins/view/citationtreeview.py +++ b/gramps/plugins/view/citationtreeview.py @@ -742,6 +742,18 @@ class CitationTreeView(ListView): source.add_tag(tag_handle) self.dbstate.db.commit_source(source, transaction) + def remove_tag(self, transaction, handle, tag_handle): + """ + Remove the given tag from the given source or citation. + """ + source, citation = self.get_source_or_citation(handle) + if citation: + citation.remove_tag(tag_handle) + self.dbstate.db.commit_citation(citation, transaction) + else: + source.remove_tag(tag_handle) + self.dbstate.db.commit_source(source, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/eventview.py b/gramps/plugins/view/eventview.py index 3aca7d6f5..0f5e0e7c2 100644 --- a/gramps/plugins/view/eventview.py +++ b/gramps/plugins/view/eventview.py @@ -468,6 +468,14 @@ class EventView(ListView): event.add_tag(tag_handle) self.dbstate.db.commit_event(event, transaction) + def remove_tag(self, transaction, event_handle, tag_handle): + """ + Remove the given tag from the given event. + """ + event = self.dbstate.db.get_event_from_handle(event_handle) + event.remove_tag(tag_handle) + self.dbstate.db.commit_event(event, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/familyview.py b/gramps/plugins/view/familyview.py index 8742a2daf..8b835237d 100644 --- a/gramps/plugins/view/familyview.py +++ b/gramps/plugins/view/familyview.py @@ -483,6 +483,14 @@ class FamilyView(ListView): family.add_tag(tag_handle) self.dbstate.db.commit_family(family, transaction) + def remove_tag(self, transaction, family_handle, tag_handle): + """ + Remove the given tag from the given family. + """ + family = self.dbstate.db.get_family_from_handle(family_handle) + family.remove_tag(tag_handle) + self.dbstate.db.commit_family(family, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/mediaview.py b/gramps/plugins/view/mediaview.py index 2b64be6f4..aee8998da 100644 --- a/gramps/plugins/view/mediaview.py +++ b/gramps/plugins/view/mediaview.py @@ -518,6 +518,14 @@ class MediaView(ListView): media.add_tag(tag_handle) self.dbstate.db.commit_media(media, transaction) + def remove_tag(self, transaction, media_handle, tag_handle): + """ + Remove the given tag from the given media object. + """ + media = self.dbstate.db.get_media_from_handle(media_handle) + media.remove_tag(tag_handle) + self.dbstate.db.commit_media(media, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/noteview.py b/gramps/plugins/view/noteview.py index f12e9fef7..b075a5a2e 100644 --- a/gramps/plugins/view/noteview.py +++ b/gramps/plugins/view/noteview.py @@ -382,6 +382,14 @@ class NoteView(ListView): note.add_tag(tag_handle) self.dbstate.db.commit_note(note, transaction) + def remove_tag(self, transaction, note_handle, tag_handle): + """ + Remove the given tag from the given note. + """ + note = self.dbstate.db.get_note_from_handle(note_handle) + note.remove_tag(tag_handle) + self.dbstate.db.commit_note(note, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/repoview.py b/gramps/plugins/view/repoview.py index dd31a16c3..b33eae0b6 100644 --- a/gramps/plugins/view/repoview.py +++ b/gramps/plugins/view/repoview.py @@ -396,6 +396,14 @@ class RepositoryView(ListView): repo.add_tag(tag_handle) self.dbstate.db.commit_repository(repo, transaction) + def remove_tag(self, transaction, repo_handle, tag_handle): + """ + Remove the given tag from the given repository. + """ + repo = self.dbstate.db.get_repository_from_handle(repo_handle) + repo.remove_tag(tag_handle) + self.dbstate.db.commit_repository(repo, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar. diff --git a/gramps/plugins/view/sourceview.py b/gramps/plugins/view/sourceview.py index c1c5e1279..76f80544e 100644 --- a/gramps/plugins/view/sourceview.py +++ b/gramps/plugins/view/sourceview.py @@ -380,6 +380,14 @@ class SourceView(ListView): source.add_tag(tag_handle) self.dbstate.db.commit_source(source, transaction) + def remove_tag(self, transaction, source_handle, tag_handle): + """ + Remove the given tag from the given source. + """ + source = self.dbstate.db.get_source_from_handle(source_handle) + source.remove_tag(tag_handle) + self.dbstate.db.commit_source(source, transaction) + def get_default_gramplets(self): """ Define the default gramplets for the sidebar and bottombar.