diff --git a/nw/config.py b/nw/config.py index dfdbe402..42d584e8 100644 --- a/nw/config.py +++ b/nw/config.py @@ -103,6 +103,7 @@ class Config: ## State self.showRefPanel = True + self.viewComments = True ## Path self.recentList = [""]*10 @@ -251,7 +252,8 @@ class Config: ## 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 cnfSec = "Path" @@ -324,7 +326,8 @@ class Config: ## State cnfSec = "State" 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 cnfSec = "Path" @@ -404,6 +407,11 @@ class Config: self.confChanged = True return + def setViewComments(self, checkState): + self.viewComments = checkState + self.confChanged = True + return + ## # Internal Functions ## diff --git a/nw/convert/text/tohtml.py b/nw/convert/text/tohtml.py index de161146..fae40df4 100644 --- a/nw/convert/text/tohtml.py +++ b/nw/convert/text/tohtml.py @@ -26,7 +26,7 @@ class ToHtml(Tokenizer): self.forPreview = False 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 formatting, which is selected by this flag. """ @@ -34,6 +34,7 @@ class ToHtml(Tokenizer): self.forPreview = forPreview if forPreview: self.doKeywords = True + self.doComments = doComments return @@ -118,7 +119,7 @@ class ToHtml(Tokenizer): thisPar.append(tTemp.rstrip()+" ") elif tType == self.T_COMMENT and self.doComments: - self.theResult += "
%s
\n" % tText + # END Class ToHtml diff --git a/nw/gui/elements/docviewer.py b/nw/gui/elements/docviewer.py index 629a9824..08b3ee65 100644 --- a/nw/gui/elements/docviewer.py +++ b/nw/gui/elements/docviewer.py @@ -105,7 +105,7 @@ class GuiDocViewer(QTextBrowser): logger.debug("Generating preview for item %s" % tHandle) sPos = self.verticalScrollBar().value() aDoc = ToHtml(self.theProject, self.theParent) - aDoc.setPreview(True) + aDoc.setPreview(True, self.mainConf.viewComments) aDoc.setText(tHandle) aDoc.doAutoReplace() aDoc.tokenizeText() @@ -121,6 +121,10 @@ class GuiDocViewer(QTextBrowser): return True + def reloadText(self): + self.loadText(self.theHandle) + return + def loadFromTag(self, theTag): logger.debug("Loading document from tag '%s'" % theTag) @@ -180,10 +184,6 @@ class GuiDocViewer(QTextBrowser): "a {{" " color: rgb({aColR},{aColG},{aColB});" "}}\n" - "pre {{" - " color: rgb({cColR},{cColG},{cColB});" - " font-size: {preSize:.1f}pt;" - "}}\n" "mark {{" " color: rgb({eColR},{eColG},{eColB});" "}}\n" @@ -197,6 +197,11 @@ class GuiDocViewer(QTextBrowser): " color: rgb({kColR},{kColG},{kColB});" " font-wright: bold;" "}}\n" + ".comment {{" + " color: rgb({cColR},{cColG},{cColB});" + " margin-left: 1em;" + " margin-right: 1em;" + "}}\n" ).format( textSize = self.mainConf.textSize, preSize = self.mainConf.textSize*0.9, diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 7e4fde17..000865a3 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -112,6 +112,11 @@ class GuiMainMenu(QMenuBar): self.toolsSpellCheck.setChecked(False) return True + def _toggleViewComments(self): + self.mainConf.setViewComments(self.docViewComments.isChecked()) + self.theParent.docViewer.reloadText() + return True + def _showAbout(self): listPrefix = " • " aboutMsg = ( @@ -331,10 +336,18 @@ class GuiMainMenu(QMenuBar): menuItem.triggered.connect(self.theParent.closeDocViewer) 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 self.docuMenu.addSeparator() - # Document > Close Preview + # Document > Import From File menuItem = QAction("Import from File", self) menuItem.setStatusTip("Import document from a text or markdown file") menuItem.setShortcut("Ctrl+Shift+I") diff --git a/nw/project/backup.py b/nw/project/backup.py index 0abef5da..bb69309a 100644 --- a/nw/project/backup.py +++ b/nw/project/backup.py @@ -17,18 +17,16 @@ from os import path, mkdir, listdir from shutil import make_archive from datetime import datetime -from nw.enum import nwAlert +from nw.enum import nwAlert logger = logging.getLogger(__name__) class NWBackup(): def __init__(self, theParent, theProject): - self.mainConf = nw.CONFIG self.theParent = theParent self.theProject = theProject - return def zipIt(self): diff --git a/nw/project/index.py b/nw/project/index.py index 9007a2bc..db7d21e1 100644 --- a/nw/project/index.py +++ b/nw/project/index.py @@ -14,7 +14,7 @@ import logging import json import nw -from os import path +from os import path from nw.project.document import NWDoc from nw.enum import nwItemType, nwItemClass, nwItemLayout