From 6ebc4ca268032c3863c06162d121970d081c5be5 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 8 Sep 2020 18:19:22 +0200 Subject: [PATCH] Cleaned up the way navigation is done in the document viewer --- nw/core/tohtml.py | 2 +- nw/gui/docviewer.py | 24 ++++++++++++++---------- nw/guimain.py | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/nw/core/tohtml.py b/nw/core/tohtml.py index cb8cfa1a..720ac9cd 100644 --- a/nw/core/tohtml.py +++ b/nw/core/tohtml.py @@ -189,7 +189,7 @@ class ToHtml(Tokenizer): hStyle = "" if self.linkHeaders: - aNm = "" % (self.theHandle, tLine) + aNm = "" % tLine else: aNm = "" diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 0c8c51b1..17b668c8 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -168,6 +168,7 @@ class GuiDocViewer(QTextBrowser): self.setTabStopWidth(self.mainConf.getTabWidth()) self.setHtml(aDoc.theResult.replace("\t", "!!tab!!")) + self.setDocumentTitle(tHandle) # Loop through the text and put back in the tabs. Tabs are removed by # the setHtml function, so the ToHtml class puts in a placeholder. @@ -203,7 +204,7 @@ class GuiDocViewer(QTextBrowser): index being up to date. """ logger.debug("Loading document from tag '%s'" % theTag) - tHandle, onLine, sTitle = self.theParent.theIndex.getTagSource(theTag) + tHandle, _, sTitle = self.theParent.theIndex.getTagSource(theTag) if tHandle is None: self.theParent.makeAlert(( "Could not find the reference for tag '%s'. It either doesn't " @@ -215,8 +216,9 @@ class GuiDocViewer(QTextBrowser): # Let the parent handle the opening as it also ensures that # the doc view panel is visible in case this request comes # from outside this class. + logger.verbose("Tag points to %s#%s" % (tHandle, sTitle)) self.theParent.viewDocument(tHandle) - self.navigateTo("#head_%s:%s" % (tHandle, sTitle)) + self.navigateTo("#%s" % sTitle) return True def docAction(self, theAction): @@ -240,13 +242,14 @@ class GuiDocViewer(QTextBrowser): return False return True - def navigateTo(self, navLink): + def navigateTo(self, tAnchor): """Go to a specific #link in the document. """ - if not isinstance(navLink, str): + if not isinstance(tAnchor, str): return False - if navLink.startswith("#"): - self.setSource(QUrl(navLink)) + if tAnchor.startswith("#"): + logger.verbose("Moving to anchor %s" % tAnchor) + self.setSource(QUrl(tAnchor)) return True def updateDocMargins(self): @@ -818,7 +821,7 @@ class GuiDocViewDetails(QScrollArea): for tHandle in theRefs: tItem = self.theProject.projTree[tHandle] if tItem is not None: - theList.append("%s" % ( + theList.append("%s" % ( tHandle, theRefs[tHandle], self.linkStyle, tItem.itemName )) @@ -835,9 +838,10 @@ class GuiDocViewDetails(QScrollArea): class for handling. """ logger.verbose("Clicked link: '%s'" % theLink) - if len(theLink) == 27: - tHandle = theLink[6:19] - self.theParent.viewDocument(tHandle, theLink) + if len(theLink) == 21: + tHandle = theLink[:13] + tAnchor = theLink[13:] + self.theParent.viewDocument(tHandle, tAnchor) return # END Class GuiDocViewDetails diff --git a/nw/guimain.py b/nw/guimain.py index 86401a5b..0729a7df 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -525,7 +525,7 @@ class GuiMain(QMainWindow): self.docEditor.saveText() return True - def viewDocument(self, tHandle=None, navLink=None): + def viewDocument(self, tHandle=None, tAnchor=None): """Load a document for viewing in the view panel. """ if tHandle is None: @@ -562,7 +562,7 @@ class GuiMain(QMainWindow): vPos[1] = bPos[1] - vPos[0] self.splitDocs.setSizes(vPos) self.viewMeta.setVisible(self.mainConf.showRefPanel) - self.docViewer.navigateTo(navLink) + self.docViewer.navigateTo(tAnchor) return True