Back-references not consideres all tags in a document, not just the first one
This commit is contained in:
+8
-9
@@ -260,9 +260,9 @@ class NWIndex():
|
||||
logger.debug("Indexing item with handle %s" % tHandle)
|
||||
|
||||
# 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]["T0"] = {
|
||||
self.refIndex[tHandle]["T000000"] = {
|
||||
"tags" : [],
|
||||
"updated" : time(),
|
||||
}
|
||||
@@ -606,18 +606,17 @@ class NWIndex():
|
||||
if tHandle is None:
|
||||
return theRefs
|
||||
|
||||
theTag = None
|
||||
theTags = []
|
||||
for tTag in self.tagIndex:
|
||||
if tHandle == self.tagIndex[tTag][1]:
|
||||
theTag = tTag
|
||||
break
|
||||
theTags.append(tTag)
|
||||
|
||||
if theTag is not None:
|
||||
if theTags:
|
||||
for tHandle in self.refIndex:
|
||||
for sTitle in self.refIndex[tHandle]:
|
||||
for nLine, tKey, tTag in self.refIndex[tHandle][sTitle]["tags"]:
|
||||
if tTag == theTag:
|
||||
theRefs[tHandle] = nLine
|
||||
for _, _, tTag in self.refIndex[tHandle][sTitle]["tags"]:
|
||||
if tTag in theTags and tHandle not in theRefs:
|
||||
theRefs[tHandle] = sTitle
|
||||
|
||||
return theRefs
|
||||
|
||||
|
||||
@@ -395,6 +395,8 @@ class GuiDocEditor(QTextEdit):
|
||||
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)
|
||||
@@ -410,12 +412,13 @@ class GuiDocEditor(QTextEdit):
|
||||
def setCursorLine(self, theLine):
|
||||
"""Move the cursor to a given line in the document.
|
||||
"""
|
||||
if theLine is None:
|
||||
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
|
||||
|
||||
##
|
||||
|
||||
@@ -206,6 +206,33 @@ class GuiDocViewer(QTextBrowser):
|
||||
self.docTitle.setTitleFromHandle(self.theHandle)
|
||||
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
|
||||
##
|
||||
|
||||
@@ -107,7 +107,11 @@ class GuiDocViewDetails(QWidget):
|
||||
for tHandle in theRefs:
|
||||
tItem = self.theProject.projTree[tHandle]
|
||||
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.adjustSize()
|
||||
@@ -122,9 +126,15 @@ class GuiDocViewDetails(QWidget):
|
||||
"""Capture the link-click and forward it to the document viewer
|
||||
class for handling.
|
||||
"""
|
||||
if len(theLink) == 18:
|
||||
tHandle = theLink[-13:]
|
||||
self.theParent.viewDocument(tHandle)
|
||||
logger.verbose("Clicked link: '%s'" % theLink)
|
||||
if len(theLink) == 26:
|
||||
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
|
||||
|
||||
def _doShowHide(self, chState):
|
||||
|
||||
+10
-8
@@ -485,7 +485,7 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.saveText()
|
||||
return True
|
||||
|
||||
def viewDocument(self, tHandle=None):
|
||||
def viewDocument(self, tHandle=None, nLine=0):
|
||||
"""Load a document for viewing in the view panel.
|
||||
"""
|
||||
if tHandle is None:
|
||||
@@ -503,13 +503,15 @@ class GuiMain(QMainWindow):
|
||||
# Make sure main tab is in Editor view
|
||||
self.tabWidget.setCurrentWidget(self.splitView)
|
||||
|
||||
if self.docViewer.loadText(tHandle) and not self.viewPane.isVisible():
|
||||
bPos = self.splitMain.sizes()
|
||||
self.viewPane.setVisible(True)
|
||||
vPos = [0,0]
|
||||
vPos[0] = int(bPos[1]/2)
|
||||
vPos[1] = bPos[1]-vPos[0]
|
||||
self.splitView.setSizes(vPos)
|
||||
if self.docViewer.loadText(tHandle):
|
||||
if not self.viewPane.isVisible():
|
||||
bPos = self.splitMain.sizes()
|
||||
self.viewPane.setVisible(True)
|
||||
vPos = [0,0]
|
||||
vPos[0] = int(bPos[1]/2)
|
||||
vPos[1] = bPos[1]-vPos[0]
|
||||
self.splitView.setSizes(vPos)
|
||||
self.docViewer.setCursorLine(nLine)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user