Allow showing comments in document view pane, with a toggle swithc in document menu

This commit is contained in:
Veronica K. B. Olsen
2019-11-02 20:08:02 +01:00
parent a8c0608457
commit e94bdd9340
6 changed files with 46 additions and 14 deletions
+10 -2
View File
@@ -103,6 +103,7 @@ class Config:
## State ## State
self.showRefPanel = True self.showRefPanel = True
self.viewComments = True
## Path ## Path
self.recentList = [""]*10 self.recentList = [""]*10
@@ -251,7 +252,8 @@ class Config:
## State ## State
cnfSec = "State" cnfSec = "State"
self.showRefPanel = self._parseLine(cnfParse, cnfSec, "showrefdetails", self.CNF_BOOL, self.showRefPanel) self.showRefPanel = self._parseLine(cnfParse, cnfSec, "showrefpanel", self.CNF_BOOL, self.showRefPanel)
self.viewComments = self._parseLine(cnfParse, cnfSec, "viewcomments", self.CNF_BOOL, self.viewComments)
## Path ## Path
cnfSec = "Path" cnfSec = "Path"
@@ -324,7 +326,8 @@ class Config:
## State ## State
cnfSec = "State" cnfSec = "State"
cnfParse.add_section(cnfSec) cnfParse.add_section(cnfSec)
cnfParse.set(cnfSec,"showrefdetails",str(self.showRefPanel)) cnfParse.set(cnfSec,"showrefpanel",str(self.showRefPanel))
cnfParse.set(cnfSec,"viewcomments",str(self.viewComments))
## Path ## Path
cnfSec = "Path" cnfSec = "Path"
@@ -404,6 +407,11 @@ class Config:
self.confChanged = True self.confChanged = True
return return
def setViewComments(self, checkState):
self.viewComments = checkState
self.confChanged = True
return
## ##
# Internal Functions # Internal Functions
## ##
+10 -2
View File
@@ -26,7 +26,7 @@ class ToHtml(Tokenizer):
self.forPreview = False self.forPreview = False
return return
def setPreview(self, forPreview): def setPreview(self, forPreview, doComments):
"""If we're using this class to generate markdown preview, we need to make a few changes to """If we're using this class to generate markdown preview, we need to make a few changes to
formatting, which is selected by this flag. formatting, which is selected by this flag.
""" """
@@ -34,6 +34,7 @@ class ToHtml(Tokenizer):
self.forPreview = forPreview self.forPreview = forPreview
if forPreview: if forPreview:
self.doKeywords = True self.doKeywords = True
self.doComments = doComments
return return
@@ -118,7 +119,7 @@ class ToHtml(Tokenizer):
thisPar.append(tTemp.rstrip()+" ") thisPar.append(tTemp.rstrip()+" ")
elif tType == self.T_COMMENT and self.doComments: elif tType == self.T_COMMENT and self.doComments:
self.theResult += "<div class='comment'>%s</div>\n" % tText self.theResult += self._formatComments(tText)
elif tType == self.T_KEYWORD and self.doKeywords: elif tType == self.T_KEYWORD and self.doKeywords:
self.theResult += self._formatTags(tText) self.theResult += self._formatTags(tText)
@@ -151,4 +152,11 @@ class ToHtml(Tokenizer):
return "<div>%s</div>" % retText return "<div>%s</div>" % retText
def _formatComments(self, tText):
if not self.forPreview:
return "<div class='comment'>%s</div>\n" % tText
return "<p class='comment'>%s</p>\n" % tText
# END Class ToHtml # END Class ToHtml
+10 -5
View File
@@ -105,7 +105,7 @@ class GuiDocViewer(QTextBrowser):
logger.debug("Generating preview for item %s" % tHandle) logger.debug("Generating preview for item %s" % tHandle)
sPos = self.verticalScrollBar().value() sPos = self.verticalScrollBar().value()
aDoc = ToHtml(self.theProject, self.theParent) aDoc = ToHtml(self.theProject, self.theParent)
aDoc.setPreview(True) aDoc.setPreview(True, self.mainConf.viewComments)
aDoc.setText(tHandle) aDoc.setText(tHandle)
aDoc.doAutoReplace() aDoc.doAutoReplace()
aDoc.tokenizeText() aDoc.tokenizeText()
@@ -121,6 +121,10 @@ class GuiDocViewer(QTextBrowser):
return True return True
def reloadText(self):
self.loadText(self.theHandle)
return
def loadFromTag(self, theTag): def loadFromTag(self, theTag):
logger.debug("Loading document from tag '%s'" % theTag) logger.debug("Loading document from tag '%s'" % theTag)
@@ -180,10 +184,6 @@ class GuiDocViewer(QTextBrowser):
"a {{" "a {{"
" color: rgb({aColR},{aColG},{aColB});" " color: rgb({aColR},{aColG},{aColB});"
"}}\n" "}}\n"
"pre {{"
" color: rgb({cColR},{cColG},{cColB});"
" font-size: {preSize:.1f}pt;"
"}}\n"
"mark {{" "mark {{"
" color: rgb({eColR},{eColG},{eColB});" " color: rgb({eColR},{eColG},{eColB});"
"}}\n" "}}\n"
@@ -197,6 +197,11 @@ class GuiDocViewer(QTextBrowser):
" color: rgb({kColR},{kColG},{kColB});" " color: rgb({kColR},{kColG},{kColB});"
" font-wright: bold;" " font-wright: bold;"
"}}\n" "}}\n"
".comment {{"
" color: rgb({cColR},{cColG},{cColB});"
" margin-left: 1em;"
" margin-right: 1em;"
"}}\n"
).format( ).format(
textSize = self.mainConf.textSize, textSize = self.mainConf.textSize,
preSize = self.mainConf.textSize*0.9, preSize = self.mainConf.textSize*0.9,
+14 -1
View File
@@ -112,6 +112,11 @@ class GuiMainMenu(QMenuBar):
self.toolsSpellCheck.setChecked(False) self.toolsSpellCheck.setChecked(False)
return True return True
def _toggleViewComments(self):
self.mainConf.setViewComments(self.docViewComments.isChecked())
self.theParent.docViewer.reloadText()
return True
def _showAbout(self): def _showAbout(self):
listPrefix = "&nbsp;&nbsp;&bull;&nbsp;&nbsp;" listPrefix = "&nbsp;&nbsp;&bull;&nbsp;&nbsp;"
aboutMsg = ( aboutMsg = (
@@ -331,10 +336,18 @@ class GuiMainMenu(QMenuBar):
menuItem.triggered.connect(self.theParent.closeDocViewer) menuItem.triggered.connect(self.theParent.closeDocViewer)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(menuItem)
# Document > Toggle View Comments
self.docViewComments = QAction("View Comments", self)
self.docViewComments.setStatusTip("Show comments in view panel")
self.docViewComments.setCheckable(True)
self.docViewComments.setChecked(self.mainConf.viewComments)
self.docViewComments.toggled.connect(self._toggleViewComments)
self.docuMenu.addAction(self.docViewComments)
# Document > Separator # Document > Separator
self.docuMenu.addSeparator() self.docuMenu.addSeparator()
# Document > Close Preview # Document > Import From File
menuItem = QAction("Import from File", self) menuItem = QAction("Import from File", self)
menuItem.setStatusTip("Import document from a text or markdown file") menuItem.setStatusTip("Import document from a text or markdown file")
menuItem.setShortcut("Ctrl+Shift+I") menuItem.setShortcut("Ctrl+Shift+I")
+1 -3
View File
@@ -17,18 +17,16 @@ from os import path, mkdir, listdir
from shutil import make_archive from shutil import make_archive
from datetime import datetime from datetime import datetime
from nw.enum import nwAlert from nw.enum import nwAlert
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class NWBackup(): class NWBackup():
def __init__(self, theParent, theProject): def __init__(self, theParent, theProject):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.theProject = theProject self.theProject = theProject
return return
def zipIt(self): def zipIt(self):
+1 -1
View File
@@ -14,7 +14,7 @@ import logging
import json import json
import nw import nw
from os import path from os import path
from nw.project.document import NWDoc from nw.project.document import NWDoc
from nw.enum import nwItemType, nwItemClass, nwItemLayout from nw.enum import nwItemType, nwItemClass, nwItemLayout