Cut/Copy/Select shortcuts now also work in doc viewer if it has focus
This commit is contained in:
@@ -441,7 +441,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
elif theAction == nwDocAction.REPL_NEXT:
|
elif theAction == nwDocAction.REPL_NEXT:
|
||||||
self._replaceNext()
|
self._replaceNext()
|
||||||
else:
|
else:
|
||||||
logger.error("Unknown or unsupported document action %s" % str(theAction))
|
logger.debug("Unknown or unsupported document action %s" % str(theAction))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import nw
|
|||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import QTextBrowser
|
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.convert import ToHtml
|
||||||
from nw.constants import nwAlert, nwItemType
|
from nw.constants import nwAlert, nwItemType, nwDocAction
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -47,6 +47,7 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
self.qDocument.setDefaultTextOption(theOpt)
|
self.qDocument.setDefaultTextOption(theOpt)
|
||||||
|
|
||||||
self.anchorClicked.connect(self._linkClicked)
|
self.anchorClicked.connect(self._linkClicked)
|
||||||
|
self.setFocusPolicy(Qt.StrongFocus)
|
||||||
|
|
||||||
logger.debug("DocViewer initialisation complete")
|
logger.debug("DocViewer initialisation complete")
|
||||||
|
|
||||||
@@ -142,10 +143,35 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
|
|
||||||
return True
|
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
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
|
def _makeSelection(self, selMode):
|
||||||
|
theCursor = self.textCursor()
|
||||||
|
theCursor.clearSelection()
|
||||||
|
theCursor.select(selMode)
|
||||||
|
self.setTextCursor(theCursor)
|
||||||
|
return
|
||||||
|
|
||||||
def _linkClicked(self, theURL):
|
def _linkClicked(self, theURL):
|
||||||
|
|
||||||
theLink = theURL.url()
|
theLink = theURL.url()
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ class GuiMainMenu(QMenuBar):
|
|||||||
self._buildHelpMenu()
|
self._buildHelpMenu()
|
||||||
|
|
||||||
# Function Pointers
|
# Function Pointers
|
||||||
self._docAction = self.theParent.docEditor.docAction
|
self._docAction = self.theParent.passDocumentAction
|
||||||
self._moveTreeItem = self.theParent.treeView.moveTreeItem
|
self._moveTreeItem = self.theParent.treeView.moveTreeItem
|
||||||
self._newTreeItem = self.theParent.treeView.newTreeItem
|
self._newTreeItem = self.theParent.treeView.newTreeItem
|
||||||
|
|
||||||
|
|||||||
@@ -458,6 +458,15 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
return True
|
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
|
# Tree Item Actions
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user