Merge branch 'release' into dev

This commit is contained in:
Veronica K. B. Olsen
2021-02-01 23:02:40 +01:00
7 changed files with 179 additions and 35 deletions
+30
View File
@@ -613,6 +613,36 @@ class NWIndex():
return hCount
def getHandleWordCounts(self, tHandle):
"""Get all header word counts for a specific handle.
"""
theCounts = []
hRecord = self._novelIndex.get(tHandle, None)
if hRecord is None:
hRecord = self._noteIndex.get(tHandle, None)
if hRecord is None:
return theCounts
for sTitle, sData in hRecord.items():
theCounts.append(("%s:%s" % (tHandle, sTitle), sData["wCount"]))
return theCounts
def getHandleHeaders(self, tHandle):
"""Get all headers for a specific handle.
"""
theHeaders = []
hRecord = self._novelIndex.get(tHandle, None)
if hRecord is None:
hRecord = self._noteIndex.get(tHandle, None)
if hRecord is None:
return theHeaders
for sTitle, sData in hRecord.items():
theHeaders.append((sTitle, sData["level"], sData["title"]))
return theHeaders
def getTableOfContents(self, maxDepth, skipExcluded=True):
"""Generate a table of contents up to a maxiumum depth.
"""
+33 -1
View File
@@ -75,12 +75,14 @@ class GuiDocEditor(QTextEdit):
self.mainConf = nw.CONFIG
self.theParent = theParent
self.theTheme = theParent.theTheme
self.theIndex = theParent.theIndex
self.theProject = theParent.theProject
self.nwDocument = NWDoc(self.theProject, self.theParent)
self.docChanged = False # Flag for changed status of document
self.spellCheck = False # Flag for spell checking enabled
self.theHandle = None # The handle of the open file
self.theHeaders = [] # Record of headers in the file
self.theDict = None # The current spell check dictionary
self.nonWord = "\"'" # Characters to not include in spell checking
@@ -342,6 +344,7 @@ class GuiDocEditor(QTextEdit):
self.docFooter.updateLineCount()
self.lengthLast = self.qDocument.characterCount()
self.theHeaders = self.theIndex.getHandleHeaders(self.theHandle)
qApp.processEvents()
self.setDocumentChanged(False)
@@ -411,7 +414,7 @@ class GuiDocEditor(QTextEdit):
self.nwDocument.saveDocument(docText)
self.setDocumentChanged(False)
self.theParent.theIndex.scanText(tHandle, docText)
self.theIndex.scanText(tHandle, docText)
hLevel, _ = self.theParent.theIndex.getFirstTitle(tHandle)
if self.theProject.projTree.updateItemLayout(tHandle, hLevel):
@@ -419,6 +422,11 @@ class GuiDocEditor(QTextEdit):
self.nwDocument.saveDocument(docText)
self.docFooter.updateInfo()
if self._updateHeaders(checkLevel=True):
self.theParent.novelView.refreshTree()
else:
self.theParent.novelView.updateWordCounts(tHandle)
return True
def updateDocMargins(self):
@@ -1230,6 +1238,30 @@ class GuiDocEditor(QTextEdit):
return
def _updateHeaders(self, checkPos=False, checkLevel=False):
"""Update the headers record and return True if anything
changed, if a check flag was provided.
"""
if self.theHandle is None:
return False
newHeaders = self.theIndex.getHandleHeaders(self.theHandle)
if checkPos:
newPos = [x[0] for x in newHeaders]
oldPos = [x[0] for x in self.theHeaders]
if checkLevel:
newLev = [x[1] for x in newHeaders]
oldLev = [x[1] for x in self.theHeaders]
self.theHeaders = newHeaders
if checkPos:
return newPos != oldPos
if checkLevel:
return newLev != oldLev
return False
def _replaceQuotes(self, sQuote, oQuote, cQuote):
"""Replace all straight quotes in the selected text.
"""
+27 -19
View File
@@ -1,28 +1,27 @@
# -*- coding: utf-8 -*-
"""novelWriter GUI Novel Tree
"""
novelWriter GUI Novel Tree
============================
GUI classe for the main window novel tree
novelWriter GUI Novel Tree
==============================
Class holding the project's novel files tree view
File History:
Created: 2020-12-20 [1.1a0]
File History:
Created: 2020-12-20 [1.1a0]
This file is a part of novelWriter
Copyright 20182020, Veronica Berglyd Olsen
This file is a part of novelWriter
Copyright 20182020, Veronica Berglyd Olsen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import nw
@@ -151,6 +150,15 @@ class GuiNovelTree(QTreeWidget):
return
def updateWordCounts(self, tHandle):
"""Update the word count for a given handle.
"""
tHeaders = self.theIndex.getHandleWordCounts(tHandle)
for titleKey, wCount in tHeaders:
if titleKey in self._treeMap:
self._treeMap[titleKey].setText(self.C_WORDS, f"{wCount:n}")
return
def getColumnSizes(self):
"""Return the column widths for the tree columns.
"""