Ctrl+Enter on a tag name now opens the file in the view pane
This commit is contained in:
+29
-2
@@ -81,8 +81,8 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
# Custom Shortcuts
|
# Custom Shortcuts
|
||||||
QShortcut(QKeySequence("Ctrl+."), self, context=Qt.WidgetShortcut, activated=self._openSpellContext)
|
QShortcut(QKeySequence("Ctrl+."), self, context=Qt.WidgetShortcut, activated=self._openSpellContext)
|
||||||
# QShortcut(Qt.Key_Return | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._insertHardBreak)
|
QShortcut(Qt.Key_Return | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._followTag)
|
||||||
# QShortcut(Qt.Key_Enter | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._insertHardBreak)
|
QShortcut(Qt.Key_Enter | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._followTag)
|
||||||
|
|
||||||
# Set Up Word Count Thread and Timer
|
# Set Up Word Count Thread and Timer
|
||||||
self.wcInterval = self.mainConf.wordCountTimer
|
self.wcInterval = self.mainConf.wordCountTimer
|
||||||
@@ -356,6 +356,33 @@ class GuiDocEditor(QTextEdit):
|
|||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
|
def _followTag(self):
|
||||||
|
"""Activated by Ctrl+Enter. Checks that we're in a block starting with '@'. We then find the
|
||||||
|
word under the cursor and check that it is after the ':'. If all this is fine, we have a tag
|
||||||
|
and can tell the document viewer to try and find and load the file where the tag is defined.
|
||||||
|
"""
|
||||||
|
|
||||||
|
theCursor = self.textCursor()
|
||||||
|
theBlock = theCursor.block()
|
||||||
|
theText = theBlock.text()
|
||||||
|
|
||||||
|
if len(theText) == 0:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if theText.startswith("@"):
|
||||||
|
|
||||||
|
theCursor.select(QTextCursor.WordUnderCursor)
|
||||||
|
theWord = theCursor.selectedText()
|
||||||
|
cPos = theText.find(":")
|
||||||
|
wPos = theCursor.selectionStart() - theBlock.position()
|
||||||
|
if wPos <= cPos:
|
||||||
|
return False
|
||||||
|
|
||||||
|
logger.verbose("Attempting to follow tag '%s'" % theWord)
|
||||||
|
self.theParent.docViewer.loadFromTag(theWord)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _insertHardBreak(self):
|
def _insertHardBreak(self):
|
||||||
theCursor = self.textCursor()
|
theCursor = self.textCursor()
|
||||||
theCursor.beginEditBlock()
|
theCursor.beginEditBlock()
|
||||||
|
|||||||
@@ -115,6 +115,24 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def loadFromTag(self, theTag):
|
||||||
|
|
||||||
|
logger.debug("Loading document from tag '%s'" % theTag)
|
||||||
|
|
||||||
|
if theTag in self.theParent.theIndex.tagIndex.keys():
|
||||||
|
theTarget = self.theParent.theIndex.tagIndex[theTag]
|
||||||
|
else:
|
||||||
|
logger.debug("The tag was not found in the index")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(theTarget) != 3:
|
||||||
|
# Just to make sure the index is not messed up
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.loadText(theTarget[1])
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user