Improved the tab handling and added the same fix to the build tool

This commit is contained in:
Veronica K. B. Olsen
2020-08-18 00:21:25 +02:00
parent 10936b6910
commit 2f177c50fc
3 changed files with 47 additions and 18 deletions
+2 -2
View File
@@ -48,7 +48,7 @@ class ToHtml(Tokenizer):
"<" : "&lt;", "<" : "&lt;",
">" : "&gt;", ">" : "&gt;",
"&" : "&amp;", "&" : "&amp;",
"\t" : "&emsp;"*2, # "\t" : "!!tab!!", # "&emsp;"*2,
nwUnicode.U_ENDASH : nwUnicode.H_ENDASH, nwUnicode.U_ENDASH : nwUnicode.H_ENDASH,
nwUnicode.U_EMDASH : nwUnicode.H_EMDASH, nwUnicode.U_EMDASH : nwUnicode.H_EMDASH,
nwUnicode.U_HELLIP : nwUnicode.H_HELLIP, nwUnicode.U_HELLIP : nwUnicode.H_HELLIP,
@@ -77,7 +77,7 @@ class ToHtml(Tokenizer):
self.doKeywords = True self.doKeywords = True
self.doComments = doComments self.doComments = doComments
self.doSynopsis = doSynopsis self.doSynopsis = doSynopsis
self.repDict["\t"] = r"!!tab!!" # The viewer replaces these # self.repDict["\t"] = r"!!tab!!" # The viewer replaces these
self._buildRegEx() self._buildRegEx()
return return
+25 -2
View File
@@ -551,7 +551,6 @@ class GuiBuildNovel(QDialog):
isNone |= theItem.itemClass == nwItemClass.NO_CLASS isNone |= theItem.itemClass == nwItemClass.NO_CLASS
isNone |= theItem.itemClass == nwItemClass.TRASH isNone |= theItem.itemClass == nwItemClass.TRASH
isNone |= theItem.parHandle == self.theProject.projTree.trashRoot() isNone |= theItem.parHandle == self.theProject.projTree.trashRoot()
isNone |= theItem.parHandle == self.theProject.projTree.archiveRoot()
isNone |= theItem.parHandle is None isNone |= theItem.parHandle is None
isNote = theItem.itemLayout == nwItemLayout.NOTE isNote = theItem.itemLayout == nwItemLayout.NOTE
isNovel = not isNone and not isNote isNovel = not isNone and not isNote
@@ -563,6 +562,10 @@ class GuiBuildNovel(QDialog):
if isNovel and not novelFiles: if isNovel and not novelFiles:
return False return False
rootItem = self.theProject.projTree.getRootItem(theItem.itemHandle)
if rootItem.itemClass == nwItemClass.ARCHIVE:
return False
return True return True
def _saveDocument(self, theFormat): def _saveDocument(self, theFormat):
@@ -1014,13 +1017,33 @@ class GuiBuildNovelDocView(QTextBrowser):
theText = "".join(theText) theText = "".join(theText)
self.buildTime = timeStamp self.buildTime = timeStamp
sPos = self.verticalScrollBar().value()
theText = theText.replace("&emsp;", "&nbsp;"*4) # Refresh the tab stops
if self.mainConf.verQtValue >= 51000:
self.setTabStopDistance(self.mainConf.getTabWidth())
else:
self.setTabStopWidth(self.mainConf.getTabWidth())
theText = theText.replace("\t", "!!tab!!")
theText = theText.replace("<del>", "<span style='text-decoration: line-through;'>") theText = theText.replace("<del>", "<span style='text-decoration: line-through;'>")
theText = theText.replace("</del>", "</span>") theText = theText.replace("</del>", "</span>")
self.setHtml(theText) self.setHtml(theText)
while self.find("!!tab!!"):
theCursor = self.textCursor()
theCursor.insertText("\t")
self.verticalScrollBar().setValue(sPos)
self._updateBuildAge() self._updateBuildAge()
# This forces a repaint of the text, It's a hack to fix an occational
# issue where the find/replace above interfers with the rendering and
# leaves parts of the document blank.
textWidth = self.qDocument.textWidth()
self.qDocument.setTextWidth(textWidth - 5)
self.qDocument.setTextWidth(textWidth)
return return
def setStyleSheet(self, theStyles=[]): def setStyleSheet(self, theStyles=[]):
+20 -14
View File
@@ -156,7 +156,20 @@ class GuiDocViewer(QTextBrowser):
self.setText("An error occurred while generating the preview.") self.setText("An error occurred while generating the preview.")
return False return False
self.setHtml(aDoc.theResult) # Refresh the tab stops
if self.mainConf.verQtValue >= 51000:
self.setTabStopDistance(self.mainConf.getTabWidth())
else:
self.setTabStopWidth(self.mainConf.getTabWidth())
self.setHtml(aDoc.theResult.replace("\t", "!!tab!!"))
# 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.
while self.find("!!tab!!"):
theCursor = self.textCursor()
theCursor.insertText("\t")
if self.theHandle == tHandle: if self.theHandle == tHandle:
self.verticalScrollBar().setValue(sPos) self.verticalScrollBar().setValue(sPos)
self.theHandle = tHandle self.theHandle = tHandle
@@ -167,17 +180,12 @@ class GuiDocViewer(QTextBrowser):
# Make sure the main GUI knows we changed the content # Make sure the main GUI knows we changed the content
self.theParent.viewMeta.refreshReferences(tHandle) self.theParent.viewMeta.refreshReferences(tHandle)
# Loop through the text and put back in the tabs. Tabs are removed by # This forces a repaint of the text, It's a hack to fix an occational
# the setHtml function, so the ToHtml class puts in a placeholder. # issue where the find/replace above interfers with the rendering and
while self.find("!!tab!!"): # leaves parts of the document blank.
theCursor = self.textCursor() textWidth = self.qDocument.textWidth()
theCursor.insertText("\t") self.qDocument.setTextWidth(textWidth - 5)
self.qDocument.setTextWidth(textWidth)
# Refresh the tab stops
if self.mainConf.verQtValue >= 51000:
self.setTabStopDistance(self.mainConf.getTabWidth())
else:
self.setTabStopWidth(self.mainConf.getTabWidth())
return True return True
@@ -369,8 +377,6 @@ class GuiDocViewer(QTextBrowser):
"}}\n" "}}\n"
".comment {{" ".comment {{"
" color: rgb({cColR},{cColG},{cColB});" " color: rgb({cColR},{cColG},{cColB});"
" margin-left: 1em;"
" margin-right: 1em;"
"}}\n" "}}\n"
".synopsis {{" ".synopsis {{"
" color: rgb({mColR},{mColG},{mColB});" " color: rgb({mColR},{mColG},{mColB});"