Cut/Copy/Select shortcuts now also work in doc viewer if it has focus

This commit is contained in:
Veronica K. B. Olsen
2019-11-21 13:37:11 +01:00
parent bd301bd5cc
commit 5b7e3fabde
4 changed files with 39 additions and 4 deletions
+1 -1
View File
@@ -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
+28 -2
View File
@@ -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()
+1 -1
View File
@@ -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
+9
View File
@@ -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
##