mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Right click context menu on images not useful (#3362)
* right click and copy on image works * renamed helper fn * separated functionality of copy and copy image * Update CONTRIBUTORS * snake case * Update CONTRIBUTORS
This commit is contained in:
parent
0bbb052b42
commit
c99b50c82f
3 changed files with 30 additions and 5 deletions
|
@ -10,6 +10,7 @@ editing-center = Center
|
|||
editing-change-color = Change color
|
||||
editing-cloze-deletion = Cloze deletion (new card)
|
||||
editing-cloze-deletion-repeat = Cloze deletion (same card)
|
||||
editing-copy-image = Copy image
|
||||
editing-couldnt-record-audio-have-you-installed = Couldn't record audio. Have you installed 'lame'?
|
||||
editing-customize-card-templates = Customize Card Templates
|
||||
editing-customize-fields = Customize Fields
|
||||
|
|
|
@ -1433,6 +1433,16 @@ class EditorWebView(AnkiWebView):
|
|||
def onCopy(self) -> None:
|
||||
self.triggerPageAction(QWebEnginePage.WebAction.Copy)
|
||||
|
||||
def on_copy_image(self) -> None:
|
||||
self.triggerPageAction(QWebEnginePage.WebAction.CopyImageToClipboard)
|
||||
|
||||
def _opened_context_menu_on_image(self) -> bool:
|
||||
context_menu_request = self.lastContextMenuRequest()
|
||||
return (
|
||||
context_menu_request.mediaType()
|
||||
== context_menu_request.MediaType.MediaTypeImage
|
||||
)
|
||||
|
||||
def _wantsExtendedPaste(self) -> bool:
|
||||
strip_html = self.editor.mw.col.get_config_bool(
|
||||
Config.Bool.PASTE_STRIPS_FORMATTING
|
||||
|
@ -1575,15 +1585,29 @@ class EditorWebView(AnkiWebView):
|
|||
|
||||
def contextMenuEvent(self, evt: QContextMenuEvent) -> None:
|
||||
m = QMenu(self)
|
||||
a = m.addAction(tr.editing_cut())
|
||||
qconnect(a.triggered, self.onCut)
|
||||
a = m.addAction(tr.actions_copy())
|
||||
qconnect(a.triggered, self.onCopy)
|
||||
self._maybe_add_cut_action(m)
|
||||
self._maybe_add_copy_action(m)
|
||||
a = m.addAction(tr.editing_paste())
|
||||
qconnect(a.triggered, self.onPaste)
|
||||
self._maybe_add_copy_image_action(m)
|
||||
gui_hooks.editor_will_show_context_menu(self, m)
|
||||
m.popup(QCursor.pos())
|
||||
|
||||
def _maybe_add_cut_action(self, menu: QMenu) -> None:
|
||||
if self.hasSelection():
|
||||
a = menu.addAction(tr.editing_cut())
|
||||
qconnect(a.triggered, self.onCut)
|
||||
|
||||
def _maybe_add_copy_action(self, menu: QMenu) -> None:
|
||||
if self.hasSelection():
|
||||
a = menu.addAction(tr.actions_copy())
|
||||
qconnect(a.triggered, self.onCopy)
|
||||
|
||||
def _maybe_add_copy_image_action(self, menu: QMenu) -> None:
|
||||
if self._opened_context_menu_on_image():
|
||||
a = menu.addAction(tr.editing_copy_image())
|
||||
qconnect(a.triggered, self.on_copy_image)
|
||||
|
||||
|
||||
# QFont returns "Kozuka Gothic Pro L" but WebEngine expects "Kozuka Gothic Pro Light"
|
||||
# - there may be other cases like a trailing 'Bold' that need fixing, but will
|
||||
|
|
Loading…
Reference in a new issue