Skip to content

Commit

Permalink
Merge pull request #311 from vkbo/view_comments
Browse files Browse the repository at this point in the history
Comment Rendering in Document Viewer
  • Loading branch information
vkbo committed Jun 13, 2020
2 parents b6e7220 + 181ff99 commit bd1bea2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 30 deletions.
10 changes: 5 additions & 5 deletions nw/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def __init__(self):
## State
self.showRefPanel = True
self.viewComments = True
self.viewSynopsis = True

# Check Qt5 Versions
verQt = splitVersionNumber(QT_VERSION_STR)
Expand Down Expand Up @@ -478,6 +479,9 @@ def loadConfig(self):
self.viewComments = self._parseLine(
cnfParse, cnfSec, "viewcomments", self.CNF_BOOL, self.viewComments
)
self.viewSynopsis = self._parseLine(
cnfParse, cnfSec, "viewsynopsis", self.CNF_BOOL, self.viewSynopsis
)

## Path
cnfSec = "Path"
Expand Down Expand Up @@ -569,6 +573,7 @@ def saveConfig(self):
cnfParse.add_section(cnfSec)
cnfParse.set(cnfSec,"showrefpanel",str(self.showRefPanel))
cnfParse.set(cnfSec,"viewcomments",str(self.viewComments))
cnfParse.set(cnfSec,"viewsynopsis",str(self.viewSynopsis))

## Path
cnfSec = "Path"
Expand Down Expand Up @@ -753,11 +758,6 @@ def setShowRefPanel(self, checkState):
self.confChanged = True
return self.showRefPanel

def setViewComments(self, checkState):
self.viewComments = checkState
self.confChanged = True
return self.viewComments

def getErrData(self):
errMessage = "<br>".join(self.errData)
self.hasError = False
Expand Down
15 changes: 8 additions & 7 deletions nw/core/tohtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, theProject, theParent):
# Setters
##

def setPreview(self, forPreview, doComments):
def setPreview(self, forPreview, doComments, doSynopsis):
"""If we're using this class to generate markdown preview, we
need to make a few changes to formatting, which is managed by
these flags.
Expand All @@ -75,6 +75,7 @@ def setPreview(self, forPreview, doComments):
self.genMode = self.M_PREVIEW
self.doKeywords = True
self.doComments = doComments
self.doSynopsis = doSynopsis
self.repDict["\t"] = "&nbsp;"*8
self._buildRegEx()
return
Expand Down Expand Up @@ -287,18 +288,18 @@ def getStyleSheet(self):
def _formatSynopsis(self, tText):
"""Apply HTML formatting to synopsis.
"""
if self.genMode == self.M_EXPORT:
return "<p class='synopsis'><strong>Synopsis: </strong>%s</p>\n" % tText
if self.genMode == self.M_PREVIEW:
return "<p class='comment'><span class='synopsis'>Synopsis: </span>%s</p>\n" % tText
else:
return "<p class='comment'>%s</p>\n" % tText
return "<p class='synopsis'><strong>Synopsis: </strong>%s</p>\n" % tText

def _formatComments(self, tText):
"""Apply HTML formatting to comments.
"""
if self.genMode == self.M_EXPORT:
return "<p class='comment'><strong>Comment: </strong>%s</p>\n" % tText
else:
if self.genMode == self.M_PREVIEW:
return "<p class='comment'>%s</p>\n" % tText
else:
return "<p class='comment'><strong>Comment: </strong>%s</p>\n" % tText

def _formatKeywords(self, tText):
"""Apply HTML formatting to keywords.
Expand Down
9 changes: 8 additions & 1 deletion nw/gui/docviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def loadText(self, tHandle):
logger.debug("Generating preview for item %s" % tHandle)
sPos = self.verticalScrollBar().value()
aDoc = ToHtml(self.theProject, self.theParent)
aDoc.setPreview(True, self.mainConf.viewComments)
aDoc.setPreview(True, self.mainConf.viewComments, self.mainConf.viewSynopsis)
aDoc.setLinkHeaders(True)

# Be extra careful here to prevent crashes when first opening a
Expand Down Expand Up @@ -366,6 +366,10 @@ def _makeStyleSheet(self):
" margin-left: 1em;"
" margin-right: 1em;"
"}}\n"
".synopsis {{"
" color: rgb({mColR},{mColG},{mColB});"
" font-wright: bold;"
"}}\n"
).format(
textSize = self.mainConf.textSize,
preSize = self.mainConf.textSize*0.9,
Expand All @@ -387,6 +391,9 @@ def _makeStyleSheet(self):
kColR = self.theTheme.colKey[0],
kColG = self.theTheme.colKey[1],
kColB = self.theTheme.colKey[2],
mColR = self.theTheme.colMod[0],
mColG = self.theTheme.colMod[1],
mColB = self.theTheme.colMod[2],
)
self.qDocument.setDefaultStyleSheet(styleSheet)

Expand Down
13 changes: 0 additions & 13 deletions nw/gui/mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ def _toggleAutoOutline(self, theMode):
self.theProject.setAutoOutline(theMode)
return True

def _toggleViewComments(self):
self.mainConf.setViewComments(self.aViewDocComments.isChecked())
self.theParent.docViewer.reloadText()
return True

def _showAbout(self):
"""Show the about dialog.
"""
Expand Down Expand Up @@ -314,14 +309,6 @@ def _buildDocumentMenu(self):
self.aCloseView.triggered.connect(self.theParent.closeDocViewer)
self.docuMenu.addAction(self.aCloseView)

# Document > Toggle View Comments
self.aViewDocComments = QAction("Show Comments", self)
self.aViewDocComments.setStatusTip("Show comments in view panel")
self.aViewDocComments.setCheckable(True)
self.aViewDocComments.setChecked(self.mainConf.viewComments)
self.aViewDocComments.toggled.connect(self._toggleViewComments)
self.docuMenu.addAction(self.aViewDocComments)

# Document > Separator
self.docuMenu.addSeparator()

Expand Down
26 changes: 25 additions & 1 deletion nw/gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, theParent, theProject):
self.tabAutoRep = GuiConfigEditAutoReplaceTab(self.theParent)

self.addTab(self.tabGeneral, "General")
self.addTab(self.tabLayout, "Layout")
self.addTab(self.tabLayout, "Text Layout")
self.addTab(self.tabEditing, "Editor")
self.addTab(self.tabAutoRep, "Auto-Replace")

Expand Down Expand Up @@ -506,6 +506,26 @@ def __init__(self, theParent):
self.showLineEndings
)

# Render Options
# ==============
self.mainForm.addGroupLabel("Render Text")

## Render Comments
self.viewComments = QSwitch()
self.viewComments.setChecked(self.mainConf.viewComments)
self.mainForm.addRow(
"Render comments in document view panel",
self.viewComments
)

## Render Synopsis
self.viewSynopsis = QSwitch()
self.viewSynopsis.setChecked(self.mainConf.viewSynopsis)
self.mainForm.addRow(
"Render synopsis in document view panel",
self.viewSynopsis
)

return

def saveValues(self):
Expand All @@ -523,6 +543,8 @@ def saveValues(self):
tabWidth = self.tabWidth.value()
showTabsNSpaces = self.showTabsNSpaces.isChecked()
showLineEndings = self.showLineEndings.isChecked()
viewComments = self.viewComments.isChecked()
viewSynopsis = self.viewSynopsis.isChecked()

self.mainConf.textFont = textFont
self.mainConf.textSize = textSize
Expand All @@ -534,6 +556,8 @@ def saveValues(self):
self.mainConf.tabWidth = tabWidth
self.mainConf.showTabsNSpaces = showTabsNSpaces
self.mainConf.showLineEndings = showLineEndings
self.mainConf.viewComments = viewComments
self.mainConf.viewSynopsis = viewSynopsis

self.mainConf.confChanged = True

Expand Down
3 changes: 2 additions & 1 deletion tests/reference/novelwriter.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Main]
timestamp = 2020-06-09 23:05:17
timestamp = 2020-06-13 22:59:36
theme = default
syntax = default_light
icons = typicons_colour_light
Expand Down Expand Up @@ -54,6 +54,7 @@ askbeforebackup = True
[State]
showrefpanel = True
viewcomments = True
viewsynopsis = True

[Path]
lastpath =
Expand Down
5 changes: 3 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def testConfigSetTreeColWidths(nwTemp,nwRef):
assert theConf.setTreeColWidths([0, 0, 0])
assert theConf.confChanged
assert theConf.setTreeColWidths([120, 30, 50])
assert theConf.setProjColWidths([140, 55, 140])
assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged
Expand All @@ -82,6 +83,8 @@ def testConfigSetPanePos(nwTemp,nwRef):
assert theConf.confChanged
assert theConf.setMainPanePos([300, 800])
assert theConf.setDocPanePos([400, 400])
assert theConf.setViewPanePos([500, 150])
assert theConf.setOutlinePanePos([500, 150])
assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged
Expand All @@ -92,8 +95,6 @@ def testConfigFlags(nwTemp,nwRef):
refConf = path.join(nwRef, "novelwriter.conf")
assert not theConf.setShowRefPanel(False)
assert theConf.setShowRefPanel(True)
assert not theConf.setViewComments(False)
assert theConf.setViewComments(True)
assert theConf.confChanged
assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2])
Expand Down

0 comments on commit bd1bea2

Please sign in to comment.