mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-01 15:23:07 +02:00
OS X: Fix dynamically generated context menus, such as the sort by menu not working: Fixes #1652694 [Empty Sort By List in Cover Grid Context Menu](https://bugs.launchpad.net/calibre/+bug/1652694)
This commit is contained in:
parent
c979c784b6
commit
6ceb84e701
5 changed files with 22 additions and 17 deletions
|
|
@ -38,6 +38,7 @@ class SortByAction(InterfaceAction):
|
|||
|
||||
def genesis(self):
|
||||
self.sorted_icon = QIcon(I('ok.png'))
|
||||
self.qaction.menu().aboutToShow.connect(self.update_menu)
|
||||
|
||||
def location_selected(self, loc):
|
||||
self.qaction.setEnabled(loc == 'library')
|
||||
|
|
@ -76,5 +77,3 @@ def sort_requested(self, key, ascending):
|
|||
self.gui.library_view.intelligent_sort(key, True)
|
||||
else:
|
||||
self.gui.library_view.sort_by_named_field(key, ascending)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -253,6 +253,7 @@ def clone_changed(self):
|
|||
|
||||
# MenuBar {{{
|
||||
|
||||
|
||||
if isosx:
|
||||
# On OS X we need special handling for the application global menu bar and
|
||||
# the context menus, since Qt does not handle dynamic menus or menus in
|
||||
|
|
@ -273,6 +274,15 @@ def __init__(self, clone, parent, is_top_level=False, clone_shortcuts=True):
|
|||
self.clone_changed()
|
||||
self.triggered.connect(self.do_trigger)
|
||||
|
||||
def clone_menu(self):
|
||||
m = self.menu()
|
||||
m.clear()
|
||||
for ac in QMenu.actions(self.clone.menu()):
|
||||
if ac.isSeparator():
|
||||
m.addSeparator()
|
||||
else:
|
||||
m.addAction(CloneAction(ac, self.parent(), clone_shortcuts=self.clone_shortcuts))
|
||||
|
||||
def clone_changed(self):
|
||||
otext = self.text()
|
||||
self.setText(self.clone.text())
|
||||
|
|
@ -293,12 +303,17 @@ def clone_changed(self):
|
|||
self.setMenu(None)
|
||||
else:
|
||||
m = QMenu(self.text(), self.parent())
|
||||
for ac in QMenu.actions(self.clone.menu()):
|
||||
if ac.isSeparator():
|
||||
m.addSeparator()
|
||||
else:
|
||||
m.addAction(CloneAction(ac, self.parent(), clone_shortcuts=self.clone_shortcuts))
|
||||
m.aboutToShow.connect(self.about_to_show)
|
||||
self.setMenu(m)
|
||||
self.clone_menu()
|
||||
|
||||
def about_to_show(self):
|
||||
cm = self.clone.menu()
|
||||
before = list(QMenu.actions(cm))
|
||||
cm.aboutToShow.emit()
|
||||
after = list(QMenu.actions(cm))
|
||||
if before != after:
|
||||
self.clone_menu()
|
||||
|
||||
def do_trigger(self, checked=False):
|
||||
if not sip.isdeleted(self.clone):
|
||||
|
|
@ -553,5 +568,3 @@ def apply_settings(self):
|
|||
bar.setToolButtonStyle(style)
|
||||
self.donate_button.setIconSize(bar.iconSize())
|
||||
self.donate_button.setToolButtonStyle(style)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -932,10 +932,6 @@ def contextMenuEvent(self, event):
|
|||
if self.context_menu is None:
|
||||
return
|
||||
from calibre.gui2.main_window import clone_menu
|
||||
sac = self.gui.iactions['Sort By']
|
||||
sort_added = tuple(ac for ac in self.context_menu.actions() if ac is sac.qaction)
|
||||
if sort_added:
|
||||
sac.update_menu()
|
||||
m = clone_menu(self.context_menu) if islinux else self.context_menu
|
||||
m.popup(event.globalPos())
|
||||
event.accept()
|
||||
|
|
|
|||
|
|
@ -840,10 +840,6 @@ def set_context_menu(self, menu, edit_collections_action):
|
|||
|
||||
def contextMenuEvent(self, event):
|
||||
from calibre.gui2.main_window import clone_menu
|
||||
sac = self.gui.iactions['Sort By']
|
||||
sort_added = tuple(ac for ac in self.context_menu.actions() if ac is sac.qaction)
|
||||
if sort_added:
|
||||
sac.update_menu()
|
||||
m = clone_menu(self.context_menu) if islinux else self.context_menu
|
||||
m.popup(event.globalPos())
|
||||
event.accept()
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ def clone_menu(menu):
|
|||
# This is needed to workaround a bug in Qt 5.5+ and Unity. When the same
|
||||
# QAction object is used in both a QMenuBar and a QMenu, sub-menus of the
|
||||
# QMenu flicker when rendered under Unity.
|
||||
|
||||
def clone_action(ac, parent):
|
||||
if ac.isSeparator():
|
||||
ans = QAction(parent)
|
||||
|
|
|
|||
Loading…
Reference in a new issue