mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
fix context menu in editor, and move workaround into shared function
This commit is contained in:
parent
372d5ed6e8
commit
1603a5224e
4 changed files with 18 additions and 11 deletions
|
@ -20,7 +20,7 @@ from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, htmlToTextLine, \
|
|||
from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
|
||||
saveHeader, restoreHeader, saveState, restoreState, getTag, \
|
||||
showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA, \
|
||||
getOnlyText, MenuList, SubMenu
|
||||
getOnlyText, MenuList, SubMenu, qtMenuShortcutWorkaround
|
||||
from anki.hooks import runHook, addHook, remHook, runFilter
|
||||
from aqt.webview import AnkiWebView
|
||||
from anki.consts import *
|
||||
|
@ -475,14 +475,12 @@ class Browser(QMainWindow):
|
|||
m = QMenu()
|
||||
for act in self.form.menu_Cards.actions():
|
||||
m.addAction(act)
|
||||
if qtminor >= 10:
|
||||
act.setShortcutVisibleInContextMenu(True)
|
||||
m.addSeparator()
|
||||
for act in self.form.menu_Notes.actions():
|
||||
m.addAction(act)
|
||||
if qtminor >= 10:
|
||||
act.setShortcutVisibleInContextMenu(True)
|
||||
runHook("browser.onContextMenu", self, m)
|
||||
|
||||
qtMenuShortcutWorkaround(m)
|
||||
m.exec_(QCursor.pos())
|
||||
|
||||
def updateFont(self):
|
||||
|
@ -1586,8 +1584,8 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
|
|||
|
||||
for c, act in enumerate(flagActions):
|
||||
act.setChecked(flag == c+1)
|
||||
if qtminor >= 10:
|
||||
act.setShortcutVisibleInContextMenu(True)
|
||||
|
||||
qtMenuShortcutWorkaround(self.form.menuFlag)
|
||||
|
||||
def onMark(self, mark=None):
|
||||
if mark is None:
|
||||
|
|
|
@ -21,7 +21,7 @@ from anki.hooks import runHook, runFilter, addHook
|
|||
from aqt.sound import getAudio
|
||||
from aqt.webview import AnkiWebView
|
||||
from aqt.utils import shortcut, showInfo, showWarning, getFile, \
|
||||
openHelp, tooltip, downArrow
|
||||
openHelp, tooltip, downArrow, qtMenuShortcutWorkaround
|
||||
import aqt
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
@ -777,6 +777,9 @@ to a cloze type first, via Edit>Change Note Type."""))
|
|||
a = m.addAction(_("Edit HTML"))
|
||||
a.triggered.connect(self.onHtmlEdit)
|
||||
a.setShortcut(QKeySequence("Ctrl+Shift+X"))
|
||||
|
||||
qtMenuShortcutWorkaround(m)
|
||||
|
||||
m.exec_(QCursor.pos())
|
||||
|
||||
# LaTeX
|
||||
|
|
|
@ -14,7 +14,7 @@ from anki.utils import stripHTML, json, bodyClass
|
|||
from anki.hooks import addHook, runHook, runFilter
|
||||
from anki.sound import playFromText, clearAudioQueue, play
|
||||
from aqt.utils import mungeQA, tooltip, askUserDialog, \
|
||||
downArrow
|
||||
downArrow, qtMenuShortcutWorkaround
|
||||
from aqt.sound import getAudio
|
||||
import aqt
|
||||
|
||||
|
@ -614,6 +614,7 @@ time = %(time)d;
|
|||
self._addMenuItems(m, opts)
|
||||
|
||||
runHook("Reviewer.contextMenuEvent", self, m)
|
||||
qtMenuShortcutWorkaround(m)
|
||||
m.exec_(QCursor.pos())
|
||||
|
||||
def _addMenuItems(self, m, rows):
|
||||
|
@ -624,6 +625,7 @@ time = %(time)d;
|
|||
if len(row) == 2:
|
||||
subm = m.addMenu(row[0])
|
||||
self._addMenuItems(subm, row[1])
|
||||
qtMenuShortcutWorkaround(subm)
|
||||
continue
|
||||
if len(row) == 4:
|
||||
label, scut, func, opts = row
|
||||
|
@ -631,8 +633,6 @@ time = %(time)d;
|
|||
label, scut, func = row
|
||||
opts = {}
|
||||
a = m.addAction(label)
|
||||
if qtminor >= 10:
|
||||
a.setShortcutVisibleInContextMenu(True)
|
||||
if scut:
|
||||
a.setShortcut(QKeySequence(scut))
|
||||
if opts.get("checked"):
|
||||
|
|
|
@ -517,6 +517,12 @@ class MenuItem:
|
|||
a = qmenu.addAction(self.title)
|
||||
a.triggered.connect(self.func)
|
||||
|
||||
def qtMenuShortcutWorkaround(qmenu):
|
||||
if qtminor < 10:
|
||||
return
|
||||
for act in qmenu.actions():
|
||||
act.setShortcutVisibleInContextMenu(True)
|
||||
|
||||
######################################################################
|
||||
|
||||
def versionWithBuild():
|
||||
|
|
Loading…
Reference in a new issue