diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index 6862c9eac2..e783fe75a2 100644 --- a/src/calibre/gui2/actions/__init__.py +++ b/src/calibre/gui2/actions/__init__.py @@ -39,8 +39,8 @@ class InterfaceAction(QObject): priority takes precedence. Sub-classes should implement the :meth:`genesis`, :meth:`library_changed`, - :meth:`location_selected` :meth:`shutting_down` - and :meth:`initialization_complete` methods. + :meth:`location_selected`, :meth:`shutting_down`, + :meth:`initialization_complete` and :meth:`tag_browser_context_action` methods. Once initialized, this plugin has access to the main calibre GUI via the :attr:`gui` member. You can access other plugins by name, for example:: @@ -349,6 +349,15 @@ class InterfaceAction(QObject): ''' pass + def tag_browser_context_action(self, index): + ''' + Called when displaying the context menu in the Tag browser. ``index`` is + the QModelIndex that points to the Tag browser item that was right clicked. + Test it for validitiy with index.valid() and get the underlying TagTreeItem + object with index.data(Qt.ItemDataRole.UserRole) + ''' + pass + def shutting_down(self): ''' Called once per plugin when the main GUI is in the process of shutting diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index 668b37304f..c469b43605 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -1004,13 +1004,12 @@ class TagsView(QTreeView): # {{{ first = True for ac in get_gui().iactions.values(): try: - if hasattr(ac, 'tag_browser_context_action'): - context_action = ac.tag_browser_context_action(index) - if context_action: - if first: - self.context_menu.addSeparator() - first = False - self.context_menu.addAction(context_action) + context_action = ac.tag_browser_context_action(index) + if context_action is not None: + if first: + self.context_menu.addSeparator() + first = False + self.context_menu.addAction(context_action) except Exception: import traceback traceback.print_exc()