mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04: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
@ -38,6 +38,7 @@ class SortByAction(InterfaceAction):
|
|||||||
|
|
||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.sorted_icon = QIcon(I('ok.png'))
|
self.sorted_icon = QIcon(I('ok.png'))
|
||||||
|
self.qaction.menu().aboutToShow.connect(self.update_menu)
|
||||||
|
|
||||||
def location_selected(self, loc):
|
def location_selected(self, loc):
|
||||||
self.qaction.setEnabled(loc == 'library')
|
self.qaction.setEnabled(loc == 'library')
|
||||||
@ -76,5 +77,3 @@ class SortByAction(InterfaceAction):
|
|||||||
self.gui.library_view.intelligent_sort(key, True)
|
self.gui.library_view.intelligent_sort(key, True)
|
||||||
else:
|
else:
|
||||||
self.gui.library_view.sort_by_named_field(key, ascending)
|
self.gui.library_view.sort_by_named_field(key, ascending)
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,6 +253,7 @@ class MenuAction(QAction): # {{{
|
|||||||
|
|
||||||
# MenuBar {{{
|
# MenuBar {{{
|
||||||
|
|
||||||
|
|
||||||
if isosx:
|
if isosx:
|
||||||
# On OS X we need special handling for the application global menu bar and
|
# 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
|
# the context menus, since Qt does not handle dynamic menus or menus in
|
||||||
@ -273,6 +274,15 @@ if isosx:
|
|||||||
self.clone_changed()
|
self.clone_changed()
|
||||||
self.triggered.connect(self.do_trigger)
|
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):
|
def clone_changed(self):
|
||||||
otext = self.text()
|
otext = self.text()
|
||||||
self.setText(self.clone.text())
|
self.setText(self.clone.text())
|
||||||
@ -293,12 +303,17 @@ if isosx:
|
|||||||
self.setMenu(None)
|
self.setMenu(None)
|
||||||
else:
|
else:
|
||||||
m = QMenu(self.text(), self.parent())
|
m = QMenu(self.text(), self.parent())
|
||||||
for ac in QMenu.actions(self.clone.menu()):
|
m.aboutToShow.connect(self.about_to_show)
|
||||||
if ac.isSeparator():
|
|
||||||
m.addSeparator()
|
|
||||||
else:
|
|
||||||
m.addAction(CloneAction(ac, self.parent(), clone_shortcuts=self.clone_shortcuts))
|
|
||||||
self.setMenu(m)
|
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):
|
def do_trigger(self, checked=False):
|
||||||
if not sip.isdeleted(self.clone):
|
if not sip.isdeleted(self.clone):
|
||||||
@ -553,5 +568,3 @@ class BarsManager(QObject):
|
|||||||
bar.setToolButtonStyle(style)
|
bar.setToolButtonStyle(style)
|
||||||
self.donate_button.setIconSize(bar.iconSize())
|
self.donate_button.setIconSize(bar.iconSize())
|
||||||
self.donate_button.setToolButtonStyle(style)
|
self.donate_button.setToolButtonStyle(style)
|
||||||
|
|
||||||
|
|
||||||
|
@ -932,10 +932,6 @@ class GridView(QListView):
|
|||||||
if self.context_menu is None:
|
if self.context_menu is None:
|
||||||
return
|
return
|
||||||
from calibre.gui2.main_window import clone_menu
|
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 = clone_menu(self.context_menu) if islinux else self.context_menu
|
||||||
m.popup(event.globalPos())
|
m.popup(event.globalPos())
|
||||||
event.accept()
|
event.accept()
|
||||||
|
@ -840,10 +840,6 @@ class BooksView(QTableView): # {{{
|
|||||||
|
|
||||||
def contextMenuEvent(self, event):
|
def contextMenuEvent(self, event):
|
||||||
from calibre.gui2.main_window import clone_menu
|
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 = clone_menu(self.context_menu) if islinux else self.context_menu
|
||||||
m.popup(event.globalPos())
|
m.popup(event.globalPos())
|
||||||
event.accept()
|
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
|
# 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
|
# QAction object is used in both a QMenuBar and a QMenu, sub-menus of the
|
||||||
# QMenu flicker when rendered under Unity.
|
# QMenu flicker when rendered under Unity.
|
||||||
|
|
||||||
def clone_action(ac, parent):
|
def clone_action(ac, parent):
|
||||||
if ac.isSeparator():
|
if ac.isSeparator():
|
||||||
ans = QAction(parent)
|
ans = QAction(parent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user