This commit is contained in:
Kovid Goyal 2022-10-20 07:41:54 +05:30
commit f810bb7974
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 45 additions and 19 deletions

View File

@ -2,6 +2,8 @@
# License: GPLv3 Copyright: 2022, Charles Haley
#
from qt.core import QToolButton
from calibre.gui2.actions import InterfaceAction
@ -11,6 +13,7 @@ class BooklistContextMenuAction(InterfaceAction):
action_spec = (_('Book list header menu'), 'context_menu.png',
_('Show the book list header context menu'), None)
action_type = 'current'
popup_type = QToolButton.ToolButtonPopupMode.InstantPopup
action_add_menu = False
dont_add_to = frozenset(['context-menu-device', 'menubar-device'])

View File

@ -2,6 +2,8 @@
# License: GPLv3 Copyright: 2022, Charles Haley
#
from qt.core import QMenu, QToolButton
from calibre.gui2.actions import InterfaceAction
@ -9,20 +11,30 @@ class ManageCategoriesAction(InterfaceAction):
name = 'Manage categories'
action_spec = (_('Manage categories'), 'tags.png',
_('Manage categories: authors, tags, series, etc.'), ())
_('Manage categories: authors, tags, series, etc.'), None)
action_type = 'current'
popup_type = QToolButton.ToolButtonPopupMode.InstantPopup
action_add_menu = True
dont_add_to = frozenset(['context-menu-device', 'menubar-device'])
def genesis(self):
self.menu = m = self.qaction.menu()
self.qaction.triggered.connect(self.show_menu)
m.aboutToShow.connect(self.about_to_show_menu)
# We want to show the menu when a toolbar button is clicked. Apparently
# the only way to do that is to scan the toolbar(s) for the action button
# then exec the associated menu. The search is done here to take adding and
# removing the action from toolbars into account.
# Create a "hidden" menu that can have a shortcut.
self.hidden_menu = QMenu()
self.shortcut_action = self.create_menu_action(
menu=self.hidden_menu,
unique_name=_('Manage categories'),
text=_('Manage categories: authors, tags, series, etc.'),
icon='tags.png',
triggered=self.show_menu)
# We want to show the menu when a shortcut is used. Apparently the only way
# to do that is to scan the toolbar(s) for the action button then exec the
# associated menu. The search is done here to take adding and removing the
# action from toolbars into account.
#
# If a shortcut is triggered and there isn't a toolbar button visible then
# show the menu in the upper left corner of the library view pane. Yes, this

View File

@ -2,7 +2,7 @@
# License: GPLv3 Copyright: 2022, Charles Haley
#
from qt.core import QPoint
from qt.core import QPoint, QMenu, QToolButton
from calibre.gui2.actions import InterfaceAction
@ -57,20 +57,29 @@ class SavedSearchesAction(InterfaceAction):
name = 'Saved searches'
action_spec = (_('Saved searches'), 'folder_saved_search.png',
_('Show a menu of saved searches'), ())
_('Show a menu of saved searches'), None)
action_type = 'current'
popup_type = QToolButton.ToolButtonPopupMode.InstantPopup
action_add_menu = True
dont_add_to = frozenset(('context-menu-device', 'menubar-device'))
def genesis(self):
self.menu = m = self.qaction.menu()
self.qaction.triggered.connect(self.show_menu)
m.aboutToShow.connect(self.about_to_show_menu)
# We want to show the menu when a toolbar button is clicked. Apparently
# the only way to do that is to scan the toolbar(s) for the action button
# then exec the associated menu. The search is done here to take adding and
# removing the action from toolbars into account.
# Create a "hidden" menu that can have a shortcut.
self.hidden_menu = QMenu()
self.shortcut_action = self.create_menu_action(
menu=self.hidden_menu,
unique_name=_('Saved searches'),
text=_('Show a menu of saved searches'),
icon='folder_saved_search.png',
triggered=self.show_menu)
# We want to show the menu when a shortcut is used. Apparently the only way
# to do that is to scan the toolbar(s) for the action button then exec the
# associated menu. The search is done here to take adding and removing the
# action from toolbars into account.
#
# If a shortcut is triggered and there isn't a toolbar button visible then
# show the menu in the upper left corner of the library view pane. Yes, this

View File

@ -15,7 +15,7 @@ from calibre.constants import ismacos
from calibre.gui2 import gprefs, native_menubar_defaults, config
from calibre.gui2.throbber import ThrobbingButton
from polyglot.builtins import itervalues
from calibre.gui2.widgets2 import RightClickButton
class RevealBar(QWidget): # {{{
@ -679,7 +679,7 @@ class BarsManager(QObject):
for ac in self.search_tool_bar_actions:
self.search_tool_bar.removeWidget(ac)
self.search_tool_bar.setContentsMargins(0, 0, 0, 0)
self.search_tool_bar.setContentsMargins(0, 0, 10, 0)
self.search_tool_bar.setSpacing(0)
self.search_tool_bar_actions = []
@ -693,8 +693,10 @@ class BarsManager(QObject):
self.search_tool_bar.addWidget(frame)
self.search_tool_bar_actions.append(frame)
elif what in self.parent().iactions:
qact = self.parent().iactions[what].qaction
tb = QToolButton()
act = self.parent().iactions[what]
qact = act.qaction
tb = RightClickButton()
tb.menu = qact.menu
tb.setContentsMargins(0, 0, 0, 0)
tb.setDefaultAction(qact)
if not gprefs['search_tool_bar_shows_text']:
@ -702,7 +704,7 @@ class BarsManager(QObject):
else:
tb.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
tb.setCursor(Qt.CursorShape.PointingHandCursor)
tb.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup)
tb.setPopupMode(act.popup_type)
tb.setAutoRaise(True)
self.search_tool_bar.addWidget(tb)
self.search_tool_bar_actions.append(tb)

View File

@ -238,6 +238,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
def refresh_gui(self, gui):
gui.refresh_search_bar_widgets()
self.gui.bars_manager.update_bars()
gui.current_db.new_api.clear_caches()
set_use_primary_find_in_search(prefs['use_primary_find_in_search'])
gui.set_highlight_only_button_icon()

View File

@ -641,7 +641,6 @@ class SearchRestrictionMixin:
self._apply_search_restriction('', '')
def _apply_search_restriction(self, restriction, name):
self.saved_search.clear()
# The order below is important. Set the restriction, force a '' search
# to apply it, reset the tag browser to take it into account, then set
# the book count.