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:
bpnguyen107 2024-08-16 23:18:07 -07:00 committed by GitHub
parent 0bbb052b42
commit c99b50c82f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 5 deletions

View file

@ -187,7 +187,7 @@ Christian Donat <https://github.com/cdonat2>
Asuka Minato <https://asukaminato.eu.org>
Dillon Baldwin <https://github.com/DillBal>
Voczi <https://github.com/voczi>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
********************
The text of the 3 clause BSD license follows:

View file

@ -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

View file

@ -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