diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index 6fa2294f..9d7bd083 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -441,7 +441,7 @@ class GuiDocEditor(QTextEdit): elif theAction == nwDocAction.REPL_NEXT: self._replaceNext() else: - logger.error("Unknown or unsupported document action %s" % str(theAction)) + logger.debug("Unknown or unsupported document action %s" % str(theAction)) return False return True diff --git a/nw/gui/elements/docviewer.py b/nw/gui/elements/docviewer.py index ab9585f6..39d8f57f 100644 --- a/nw/gui/elements/docviewer.py +++ b/nw/gui/elements/docviewer.py @@ -15,10 +15,10 @@ import nw from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QTextBrowser -from PyQt5.QtGui import QTextOption, QFont, QPalette, QColor +from PyQt5.QtGui import QTextOption, QFont, QPalette, QColor, QTextCursor from nw.convert import ToHtml -from nw.constants import nwAlert, nwItemType +from nw.constants import nwAlert, nwItemType, nwDocAction logger = logging.getLogger(__name__) @@ -47,6 +47,7 @@ class GuiDocViewer(QTextBrowser): self.qDocument.setDefaultTextOption(theOpt) self.anchorClicked.connect(self._linkClicked) + self.setFocusPolicy(Qt.StrongFocus) logger.debug("DocViewer initialisation complete") @@ -142,10 +143,35 @@ class GuiDocViewer(QTextBrowser): return True + def docAction(self, theAction): + logger.verbose("Requesting action: %s" % theAction.name) + if self.theHandle is None: + logger.error("No document open") + return False + if theAction == nwDocAction.CUT: + self.copy() + elif theAction == nwDocAction.COPY: + self.copy() + elif theAction == nwDocAction.SEL_ALL: + self._makeSelection(QTextCursor.Document) + elif theAction == nwDocAction.SEL_PARA: + self._makeSelection(QTextCursor.BlockUnderCursor) + else: + logger.debug("Unknown or unsupported document action %s" % str(theAction)) + return False + return True + ## # Internal Functions ## + def _makeSelection(self, selMode): + theCursor = self.textCursor() + theCursor.clearSelection() + theCursor.select(selMode) + self.setTextCursor(theCursor) + return + def _linkClicked(self, theURL): theLink = theURL.url() diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 5966509d..66b4cb31 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -40,7 +40,7 @@ class GuiMainMenu(QMenuBar): self._buildHelpMenu() # Function Pointers - self._docAction = self.theParent.docEditor.docAction + self._docAction = self.theParent.passDocumentAction self._moveTreeItem = self.theParent.treeView.moveTreeItem self._newTreeItem = self.theParent.treeView.newTreeItem diff --git a/nw/guimain.py b/nw/guimain.py index 95e0c6a3..e07af0bd 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -458,6 +458,15 @@ class GuiMain(QMainWindow): return True + def passDocumentAction(self, theAction): + if self.docEditor.hasFocus(): + self.docEditor.docAction(theAction) + elif self.docViewer.hasFocus(): + self.docViewer.docAction(theAction) + else: + logger.debug("Document action requested, but no document has focus") + return True + ## # Tree Item Actions ##