diff --git a/imgsrc/context_menu.svg b/imgsrc/context_menu.svg new file mode 100644 index 0000000000..77a560a477 --- /dev/null +++ b/imgsrc/context_menu.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/images/context_menu.png b/resources/images/context_menu.png new file mode 100644 index 0000000000..73d2029ba1 Binary files /dev/null and b/resources/images/context_menu.png differ diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 78c1b1cf34..59229a04aa 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1070,6 +1070,13 @@ class ActionManageCategories(InterfaceActionBase): description = _('Manage tag browser categories') +class ActionBooklistContextMenu(InterfaceActionBase): + name = 'Booklist context menu' + author = 'Charles Haley' + actual_plugin = 'calibre.gui2.actions.booklist_context_menu:BooklistContextMenuAction' + description = _('Open the context menu for the column') + + class ActionVirtualLibrary(InterfaceActionBase): name = 'Virtual Library' actual_plugin = 'calibre.gui2.actions.virtual_library:VirtualLibraryAction' @@ -1111,7 +1118,7 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog, ActionPluginUpdater, ActionPickRandom, ActionEditToC, ActionSortBy, ActionMarkBooks, ActionEmbed, ActionTemplateTester, ActionTagMapper, ActionAuthorMapper, ActionVirtualLibrary, ActionBrowseAnnotations, ActionTemplateFunctions, ActionAutoscrollBooks, - ActionFullTextSearch, ActionManageCategories] + ActionFullTextSearch, ActionManageCategories, ActionBooklistContextMenu] # }}} diff --git a/src/calibre/gui2/actions/booklist_context_menu.py b/src/calibre/gui2/actions/booklist_context_menu.py new file mode 100644 index 0000000000..014137d275 --- /dev/null +++ b/src/calibre/gui2/actions/booklist_context_menu.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# License: GPLv3 Copyright: 2022, Charles Haley +# +from qt.core import QPoint + +from calibre.gui2.actions import InterfaceAction + + +class BooklistContextMenuAction(InterfaceAction): + + name = 'Booklist context menu' + action_spec = (_('Book list context menu'), 'context_menu.png', + _('Show the book list context menu'), '') + action_type = 'current' + action_add_menu = False + dont_add_to = frozenset(['context-menu-device', 'menubar-device']) + + def genesis(self): + self.qaction.triggered.connect(self.show_context_menu) + + def show_context_menu(self): + self.gui.library_view.show_column_header_context_menu_from_action() + + def location_selected(self, loc): + self.qaction.setEnabled(loc == 'library') diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index b3fd22929f..8703d18297 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -541,6 +541,16 @@ class BooksView(QTableView): # {{{ gprefs['row_numbers_in_book_list'] = show self.set_row_header_visibility() + def show_column_header_context_menu_from_action(self): + if self.is_library_view: + if self.hasFocus(): + p = QPoint(self.column_header.sectionViewportPosition(self.currentIndex().column()), 10) + self.show_column_header_context_menu(p, view=self) + elif self.pin_view.hasFocus(): + p = QPoint(self.pin_view.horizontalHeader().sectionViewportPosition(self.pin_view.currentIndex().column()), 10) + self.show_column_header_context_menu(p, view=self.pin_view) + # else some other widget has the focus, such as the tag browser or quickview + def show_column_header_context_menu(self, pos, view=None): view = view or self idx = view.column_header.logicalIndexAt(pos)