Back-references not consideres all tags in a document, not just the first one

This commit is contained in:
Veronica K. B. Olsen
2020-05-25 21:14:50 +02:00
parent e7f0751275
commit 3b7927f0ff
8 changed files with 81 additions and 34 deletions
+8 -9
View File
@@ -260,9 +260,9 @@ class NWIndex():
logger.debug("Indexing item with handle %s" % tHandle) logger.debug("Indexing item with handle %s" % tHandle)
# Check file type, and reset its old index # Check file type, and reset its old index
# Also add a dummy entry for T0 in case the file has no title # Also add a dummy entry T000000 in case the file has no title
self.refIndex[tHandle] = {} self.refIndex[tHandle] = {}
self.refIndex[tHandle]["T0"] = { self.refIndex[tHandle]["T000000"] = {
"tags" : [], "tags" : [],
"updated" : time(), "updated" : time(),
} }
@@ -606,18 +606,17 @@ class NWIndex():
if tHandle is None: if tHandle is None:
return theRefs return theRefs
theTag = None theTags = []
for tTag in self.tagIndex: for tTag in self.tagIndex:
if tHandle == self.tagIndex[tTag][1]: if tHandle == self.tagIndex[tTag][1]:
theTag = tTag theTags.append(tTag)
break
if theTag is not None: if theTags:
for tHandle in self.refIndex: for tHandle in self.refIndex:
for sTitle in self.refIndex[tHandle]: for sTitle in self.refIndex[tHandle]:
for nLine, tKey, tTag in self.refIndex[tHandle][sTitle]["tags"]: for _, _, tTag in self.refIndex[tHandle][sTitle]["tags"]:
if tTag == theTag: if tTag in theTags and tHandle not in theRefs:
theRefs[tHandle] = nLine theRefs[tHandle] = sTitle
return theRefs return theRefs
+4 -1
View File
@@ -395,6 +395,8 @@ class GuiDocEditor(QTextEdit):
def setCursorPosition(self, thePosition): def setCursorPosition(self, thePosition):
"""Move the cursor to a given position in the document. """Move the cursor to a given position in the document.
""" """
if not isinstance(thePosition, int):
return False
if thePosition >= 0: if thePosition >= 0:
theCursor = self.textCursor() theCursor = self.textCursor()
theCursor.setPosition(thePosition) theCursor.setPosition(thePosition)
@@ -410,12 +412,13 @@ class GuiDocEditor(QTextEdit):
def setCursorLine(self, theLine): def setCursorLine(self, theLine):
"""Move the cursor to a given line in the document. """Move the cursor to a given line in the document.
""" """
if theLine is None: if not isinstance(theLine, int):
return False return False
if theLine >= 0: if theLine >= 0:
theBlock = self.qDocument.findBlockByLineNumber(theLine) theBlock = self.qDocument.findBlockByLineNumber(theLine)
if theBlock: if theBlock:
self.setCursorPosition(theBlock.position()) self.setCursorPosition(theBlock.position())
logger.verbose("Cursor moved to line %d" % theLine)
return True return True
## ##
+27
View File
@@ -206,6 +206,33 @@ class GuiDocViewer(QTextBrowser):
self.docTitle.setTitleFromHandle(self.theHandle) self.docTitle.setTitleFromHandle(self.theHandle)
return return
##
# Setters
##
def setCursorPosition(self, thePosition):
"""Move the cursor to a given position in the document.
"""
if not isinstance(thePosition, int):
return False
if thePosition >= 0:
theCursor = self.textCursor()
theCursor.setPosition(thePosition)
self.setTextCursor(theCursor)
return True
def setCursorLine(self, theLine):
"""Move the cursor to a given line in the document.
"""
if not isinstance(theLine, int):
return False
if theLine >= 0:
theBlock = self.qDocument.findBlockByLineNumber(theLine)
if theBlock:
self.setCursorPosition(theBlock.position())
logger.verbose("Cursor moved to line %d" % theLine)
return True
## ##
# Events # Events
## ##
+14 -4
View File
@@ -107,7 +107,11 @@ class GuiDocViewDetails(QWidget):
for tHandle in theRefs: for tHandle in theRefs:
tItem = self.theProject.projTree[tHandle] tItem = self.theProject.projTree[tHandle]
if tItem is not None: if tItem is not None:
theList.append("<a href='#tag=%s'>%s</a>" % (tHandle,tItem.itemName)) theList.append("<a href='#tag=%s:%s'>%s</a>" % (
tHandle, theRefs[tHandle], tItem.itemName
))
# print(theList)
self.refList.setText(", ".join(theList)) self.refList.setText(", ".join(theList))
self.refList.adjustSize() self.refList.adjustSize()
@@ -122,9 +126,15 @@ class GuiDocViewDetails(QWidget):
"""Capture the link-click and forward it to the document viewer """Capture the link-click and forward it to the document viewer
class for handling. class for handling.
""" """
if len(theLink) == 18: logger.verbose("Clicked link: '%s'" % theLink)
tHandle = theLink[-13:] if len(theLink) == 26:
self.theParent.viewDocument(tHandle) tHandle = theLink[5:18]
tLine = theLink[19:26]
if tLine[1:].isdigit():
nLine = int(tLine[1:])
else:
nLine = 1
self.theParent.viewDocument(tHandle, nLine)
return return
def _doShowHide(self, chState): def _doShowHide(self, chState):
+10 -8
View File
@@ -485,7 +485,7 @@ class GuiMain(QMainWindow):
self.docEditor.saveText() self.docEditor.saveText()
return True return True
def viewDocument(self, tHandle=None): def viewDocument(self, tHandle=None, nLine=0):
"""Load a document for viewing in the view panel. """Load a document for viewing in the view panel.
""" """
if tHandle is None: if tHandle is None:
@@ -503,13 +503,15 @@ class GuiMain(QMainWindow):
# Make sure main tab is in Editor view # Make sure main tab is in Editor view
self.tabWidget.setCurrentWidget(self.splitView) self.tabWidget.setCurrentWidget(self.splitView)
if self.docViewer.loadText(tHandle) and not self.viewPane.isVisible(): if self.docViewer.loadText(tHandle):
bPos = self.splitMain.sizes() if not self.viewPane.isVisible():
self.viewPane.setVisible(True) bPos = self.splitMain.sizes()
vPos = [0,0] self.viewPane.setVisible(True)
vPos[0] = int(bPos[1]/2) vPos = [0,0]
vPos[1] = bPos[1]-vPos[0] vPos[0] = int(bPos[1]/2)
self.splitView.setSizes(vPos) vPos[1] = bPos[1]-vPos[0]
self.splitView.setSizes(vPos)
self.docViewer.setCursorLine(nLine)
return True return True
+1 -1
View File
@@ -2,6 +2,6 @@
### We Found John! ### We Found John!
@pov: John @pov: John
@location: Mars @location: Mars, OuterSpace
Jane has been searching for a while, and she finally found John on Mars. He was indeed in space! What was he doing on Mars anyway? Well, it turns out, he was farming potatoes. Jane has been searching for a while, and she finally found John on Mars. He was indeed in space! What was he doing on Mars anyway? Well, it turns out, he was farming potatoes.
+6
View File
@@ -5,4 +5,10 @@
Space … its an awful lot of nothing, with bits in it here and there. Some of which, people like to call home. Space … its an awful lot of nothing, with bits in it here and there. Some of which, people like to call home.
## Outer Space
@tag: OuterSpace
Now even further into space!
You can have more than one tag in a file, as long as there is only one tag per heading.
+11 -11
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.6" hexVersion="0x000600f0" fileVersion="1.0" saveCount="168" autoCount="26" timeStamp="2020-05-24 18:33:34"> <novelWriterXML appVersion="0.6.1" hexVersion="0x000601f0" fileVersion="1.0" saveCount="182" autoCount="34" timeStamp="2020-05-25 21:08:45">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
@@ -10,9 +10,9 @@
<settings> <settings>
<spellCheck>True</spellCheck> <spellCheck>True</spellCheck>
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>636b6aa9b697b</lastEdited> <lastEdited>ae7339df26ded</lastEdited>
<lastViewed>ba8a28a246524</lastViewed> <lastViewed>ae7339df26ded</lastViewed>
<lastWordCount>914</lastWordCount> <lastWordCount>941</lastWordCount>
<autoReplace> <autoReplace>
<A>B</A> <A>B</A>
<B>E</B> <B>E</B>
@@ -73,7 +73,7 @@
<expanded>False</expanded> <expanded>False</expanded>
<exported>True</exported> <exported>True</exported>
<layout>PAGE</layout> <layout>PAGE</layout>
<charCount>208</charCount> <charCount>210</charCount>
<wordCount>40</wordCount> <wordCount>40</wordCount>
<paraCount>2</paraCount> <paraCount>2</paraCount>
<cursorPos>213</cursorPos> <cursorPos>213</cursorPos>
@@ -174,7 +174,7 @@
<charCount>139</charCount> <charCount>139</charCount>
<wordCount>28</wordCount> <wordCount>28</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>343</cursorPos> <cursorPos>237</cursorPos>
</item> </item>
<item handle="ae7339df26ded" order="6" parent="e7ded148d6e4a"> <item handle="ae7339df26ded" order="6" parent="e7ded148d6e4a">
<name>We Found John!</name> <name>We Found John!</name>
@@ -187,7 +187,7 @@
<charCount>189</charCount> <charCount>189</charCount>
<wordCount>37</wordCount> <wordCount>37</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>224</cursorPos> <cursorPos>236</cursorPos>
</item> </item>
<item handle="f6622b4617424" order="1" parent="None"> <item handle="f6622b4617424" order="1" parent="None">
<name>Characters</name> <name>Characters</name>
@@ -257,10 +257,10 @@
<expanded>False</expanded> <expanded>False</expanded>
<exported>True</exported> <exported>True</exported>
<layout>NOTE</layout> <layout>NOTE</layout>
<charCount>115</charCount> <charCount>241</charCount>
<wordCount>24</wordCount> <wordCount>51</wordCount>
<paraCount>1</paraCount> <paraCount>3</paraCount>
<cursorPos>133</cursorPos> <cursorPos>286</cursorPos>
</item> </item>
<item handle="5eaea4e8cdee8" order="2" parent="15c4492bd5107"> <item handle="5eaea4e8cdee8" order="2" parent="15c4492bd5107">
<name>Mars</name> <name>Mars</name>