Move the project index into the project class
This commit is contained in:
@@ -37,6 +37,7 @@ from PyQt5.QtCore import QCoreApplication
|
|||||||
|
|
||||||
from novelwriter.core.tree import NWTree
|
from novelwriter.core.tree import NWTree
|
||||||
from novelwriter.core.item import NWItem
|
from novelwriter.core.item import NWItem
|
||||||
|
from novelwriter.core.index import NWIndex
|
||||||
from novelwriter.core.status import NWStatus
|
from novelwriter.core.status import NWStatus
|
||||||
from novelwriter.core.options import OptionState
|
from novelwriter.core.options import OptionState
|
||||||
from novelwriter.core.document import NWDoc
|
from novelwriter.core.document import NWDoc
|
||||||
@@ -62,9 +63,10 @@ class NWProject():
|
|||||||
self.mainConf = novelwriter.CONFIG
|
self.mainConf = novelwriter.CONFIG
|
||||||
|
|
||||||
# Core Elements
|
# Core Elements
|
||||||
self.optState = OptionState(self) # Project-specific GUI options
|
self.optState = OptionState(self) # Project-specific GUI options
|
||||||
self.projTree = NWTree(self) # The project tree
|
self.projTree = NWTree(self) # The project tree
|
||||||
self.langData = {} # Localisation data
|
self._projIndex = NWIndex(self) # The projecty index
|
||||||
|
self.langData = {} # Localisation data
|
||||||
|
|
||||||
# Project Status
|
# Project Status
|
||||||
self.projOpened = 0 # The time stamp of when the project file was opened
|
self.projOpened = 0 # The time stamp of when the project file was opened
|
||||||
@@ -116,6 +118,14 @@ class NWProject():
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Properties
|
||||||
|
##
|
||||||
|
|
||||||
|
@property
|
||||||
|
def index(self):
|
||||||
|
return self._projIndex
|
||||||
|
|
||||||
##
|
##
|
||||||
# Item Methods
|
# Item Methods
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ class ToHtml(Tokenizer):
|
|||||||
def _formatKeywords(self, tText):
|
def _formatKeywords(self, tText):
|
||||||
"""Apply HTML formatting to keywords.
|
"""Apply HTML formatting to keywords.
|
||||||
"""
|
"""
|
||||||
isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText)
|
isValid, theBits, _ = self.theProject.index.scanThis("@"+tText)
|
||||||
if not isValid or not theBits:
|
if not isValid or not theBits:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class ToMarkdown(Tokenizer):
|
|||||||
def _formatKeywords(self, tText, tStyle):
|
def _formatKeywords(self, tText, tStyle):
|
||||||
"""Apply Markdown formatting to keywords.
|
"""Apply Markdown formatting to keywords.
|
||||||
"""
|
"""
|
||||||
isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText)
|
isValid, theBits, _ = self.theProject.index.scanThis("@"+tText)
|
||||||
if not isValid or not theBits:
|
if not isValid or not theBits:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ class ToOdt(Tokenizer):
|
|||||||
def _formatKeywords(self, tText):
|
def _formatKeywords(self, tText):
|
||||||
"""Apply formatting to keywords.
|
"""Apply formatting to keywords.
|
||||||
"""
|
"""
|
||||||
isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText)
|
isValid, theBits, _ = self.theProject.index.scanThis("@"+tText)
|
||||||
if not isValid or not theBits:
|
if not isValid or not theBits:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,6 @@ class GuiProjectDetailsMain(QWidget):
|
|||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theIndex = theParent.theIndex
|
|
||||||
|
|
||||||
fPx = self.theTheme.fontPixelSize
|
fPx = self.theTheme.fontPixelSize
|
||||||
fPt = self.theTheme.fontPointSize
|
fPt = self.theTheme.fontPointSize
|
||||||
@@ -245,8 +244,9 @@ class GuiProjectDetailsMain(QWidget):
|
|||||||
def updateValues(self):
|
def updateValues(self):
|
||||||
"""Set all the values.
|
"""Set all the values.
|
||||||
"""
|
"""
|
||||||
hCounts = self.theIndex.getNovelTitleCounts()
|
pIndex = self.theProject.index
|
||||||
nwCount = self.theIndex.getNovelWordCount()
|
hCounts = pIndex.getNovelTitleCounts()
|
||||||
|
nwCount = pIndex.getNovelWordCount()
|
||||||
edTime = self.theProject.getCurrentEditTime()
|
edTime = self.theProject.getCurrentEditTime()
|
||||||
|
|
||||||
self.wordCountVal.setText(f"{nwCount:n}")
|
self.wordCountVal.setText(f"{nwCount:n}")
|
||||||
@@ -277,7 +277,6 @@ class GuiProjectDetailsContents(QWidget):
|
|||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theIndex = theParent.theIndex
|
|
||||||
self.optState = theProject.optState
|
self.optState = theProject.optState
|
||||||
|
|
||||||
# Internal
|
# Internal
|
||||||
@@ -424,7 +423,7 @@ class GuiProjectDetailsContents(QWidget):
|
|||||||
"""Extract the data for the tree.
|
"""Extract the data for the tree.
|
||||||
"""
|
"""
|
||||||
self._theToC = []
|
self._theToC = []
|
||||||
self._theToC = self.theIndex.getTableOfContents(2)
|
self._theToC = self.theProject.index.getTableOfContents(2)
|
||||||
self._theToC.append(("", 0, self.tr("END"), 0))
|
self._theToC.append(("", 0, self.tr("END"), 0))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -409,10 +409,10 @@ class PagedDialog(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def addTab(self, tabWidget, tabLabel):
|
def addTab(self, widget, label):
|
||||||
"""Forwards the adding of tabs to the QTabWidget.
|
"""Forwards the adding of tabs to the QTabWidget.
|
||||||
"""
|
"""
|
||||||
self._tabBox.addTab(tabWidget, tabLabel)
|
self._tabBox.addTab(widget, label)
|
||||||
return
|
return
|
||||||
|
|
||||||
def addControls(self, buttonBar):
|
def addControls(self, buttonBar):
|
||||||
@@ -431,15 +431,15 @@ class VerticalTabBar(QTabBar):
|
|||||||
self._mW = novelwriter.CONFIG.pxInt(150)
|
self._mW = novelwriter.CONFIG.pxInt(150)
|
||||||
return
|
return
|
||||||
|
|
||||||
def tabSizeHint(self, theIndex):
|
def tabSizeHint(self, index):
|
||||||
"""Returns a transposed size hint for the rotated bar.
|
"""Returns a transposed size hint for the rotated bar.
|
||||||
"""
|
"""
|
||||||
tSize = QTabBar.tabSizeHint(self, theIndex)
|
tSize = QTabBar.tabSizeHint(self, index)
|
||||||
tSize.transpose()
|
tSize.transpose()
|
||||||
tSize.setWidth(min(tSize.width(), self._mW))
|
tSize.setWidth(min(tSize.width(), self._mW))
|
||||||
return tSize
|
return tSize
|
||||||
|
|
||||||
def paintEvent(self, theEvent):
|
def paintEvent(self, event):
|
||||||
"""Custom implementation of the label painter that rotates the
|
"""Custom implementation of the label painter that rotates the
|
||||||
label 90 degrees.
|
label 90 degrees.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ class GuiDocEditor(QTextEdit):
|
|||||||
self.mainConf = novelwriter.CONFIG
|
self.mainConf = novelwriter.CONFIG
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theIndex = theParent.theIndex
|
|
||||||
self.theProject = theParent.theProject
|
self.theProject = theParent.theProject
|
||||||
|
|
||||||
self._nwDocument = None
|
self._nwDocument = None
|
||||||
@@ -401,7 +400,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
self.document().rootFrame().setFrameFormat(docFrame)
|
self.document().rootFrame().setFrameFormat(docFrame)
|
||||||
|
|
||||||
self.docFooter.updateLineCount()
|
self.docFooter.updateLineCount()
|
||||||
self._docHeaders = self.theIndex.getHandleHeaders(self._docHandle)
|
self._docHeaders = self.theProject.index.getHandleHeaders(self._docHandle)
|
||||||
|
|
||||||
qApp.processEvents()
|
qApp.processEvents()
|
||||||
self.document().clearUndoRedoStacks()
|
self.document().clearUndoRedoStacks()
|
||||||
@@ -506,9 +505,9 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
self.setDocumentChanged(False)
|
self.setDocumentChanged(False)
|
||||||
|
|
||||||
oldHeader = self.theIndex.getHandleHeaderLevel(tHandle)
|
oldHeader = self.theProject.index.getHandleHeaderLevel(tHandle)
|
||||||
self.theIndex.scanText(tHandle, docText)
|
self.theProject.index.scanText(tHandle, docText)
|
||||||
newHeader = self.theIndex.getHandleHeaderLevel(tHandle)
|
newHeader = self.theProject.index.getHandleHeaderLevel(tHandle)
|
||||||
|
|
||||||
if self._updateHeaders(checkLevel=True):
|
if self._updateHeaders(checkLevel=True):
|
||||||
self.theParent.requestNovelTreeRefresh()
|
self.theParent.requestNovelTreeRefresh()
|
||||||
@@ -2003,7 +2002,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
if self._docHandle is None:
|
if self._docHandle is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
newHeaders = self.theIndex.getHandleHeaders(self._docHandle)
|
newHeaders = self.theProject.index.getHandleHeaders(self._docHandle)
|
||||||
if checkPos:
|
if checkPos:
|
||||||
newPos = [x[0] for x in newHeaders]
|
newPos = [x[0] for x in newHeaders]
|
||||||
oldPos = [x[0] for x in self._docHeaders]
|
oldPos = [x[0] for x in self._docHeaders]
|
||||||
@@ -2943,7 +2942,7 @@ class GuiDocEditFooter(QWidget):
|
|||||||
else:
|
else:
|
||||||
theStatus, theIcon = self._theItem.getImportStatus()
|
theStatus, theIcon = self._theItem.getImportStatus()
|
||||||
sIcon = theIcon.pixmap(self.sPx, self.sPx)
|
sIcon = theIcon.pixmap(self.sPx, self.sPx)
|
||||||
hLevel = self.theParent.theIndex.getHandleHeaderLevel(self._docHandle)
|
hLevel = self.theProject.index.getHandleHeaderLevel(self._docHandle)
|
||||||
sText = f"{theStatus} / {self._theItem.describeMe(hLevel)}"
|
sText = f"{theStatus} / {self._theItem.describeMe(hLevel)}"
|
||||||
|
|
||||||
self.statusIcon.setPixmap(sIcon)
|
self.statusIcon.setPixmap(sIcon)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
self.spEnchant = spEnchant
|
self.spEnchant = spEnchant
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theIndex = theParent.theIndex
|
self.theProject = theParent.theProject
|
||||||
self.theHandle = None
|
self.theHandle = None
|
||||||
self.spellCheck = False
|
self.spellCheck = False
|
||||||
self.spellRx = None
|
self.spellRx = None
|
||||||
@@ -287,9 +287,10 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
|
|
||||||
if theText.startswith("@"): # Keywords and commands
|
if theText.startswith("@"): # Keywords and commands
|
||||||
self.setCurrentBlockState(self.BLOCK_META)
|
self.setCurrentBlockState(self.BLOCK_META)
|
||||||
|
pIndex = self.theProject.index
|
||||||
tItem = self.theParent.theProject.projTree[self.theHandle]
|
tItem = self.theParent.theProject.projTree[self.theHandle]
|
||||||
isValid, theBits, thePos = self.theIndex.scanThis(theText)
|
isValid, theBits, thePos = pIndex.scanThis(theText)
|
||||||
isGood = self.theIndex.checkThese(theBits, tItem)
|
isGood = pIndex.checkThese(theBits, tItem)
|
||||||
if isValid:
|
if isValid:
|
||||||
for n, theBit in enumerate(theBits):
|
for n, theBit in enumerate(theBits):
|
||||||
xPos = thePos[n]
|
xPos = thePos[n]
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ class GuiDocViewer(QTextBrowser):
|
|||||||
index being up to date.
|
index being up to date.
|
||||||
"""
|
"""
|
||||||
logger.debug("Loading document from tag '%s'", theTag)
|
logger.debug("Loading document from tag '%s'", theTag)
|
||||||
tHandle, _, sTitle = self.theParent.theIndex.getTagSource(theTag)
|
tHandle, _, sTitle = self.theProject.index.getTagSource(theTag)
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
self.theParent.makeAlert(self.tr(
|
self.theParent.makeAlert(self.tr(
|
||||||
"Could not find the reference for tag '{0}'. It either doesn't "
|
"Could not find the reference for tag '{0}'. It either doesn't "
|
||||||
@@ -1199,7 +1199,7 @@ class GuiDocViewDetails(QScrollArea):
|
|||||||
if self.theParent.docViewer.stickyRef:
|
if self.theParent.docViewer.stickyRef:
|
||||||
return
|
return
|
||||||
|
|
||||||
theRefs = self.theParent.theIndex.getBackReferenceList(tHandle)
|
theRefs = self.theProject.index.getBackReferenceList(tHandle)
|
||||||
theList = []
|
theList = []
|
||||||
for tHandle in theRefs:
|
for tHandle in theRefs:
|
||||||
tItem = self.theProject.projTree[tHandle]
|
tItem = self.theProject.projTree[tHandle]
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ class GuiItemDetails(QWidget):
|
|||||||
# Layout
|
# Layout
|
||||||
# ======
|
# ======
|
||||||
|
|
||||||
hLevel = self.theParent.theIndex.getHandleHeaderLevel(tHandle)
|
hLevel = self.theProject.index.getHandleHeaderLevel(tHandle)
|
||||||
usageIcon = self.theTheme.getItemIcon(
|
usageIcon = self.theTheme.getItemIcon(
|
||||||
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ class GuiNovelTree(QTreeWidget):
|
|||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theProject = theParent.theProject
|
self.theProject = theParent.theProject
|
||||||
self.theIndex = theParent.theIndex
|
|
||||||
|
|
||||||
# Internal Variables
|
# Internal Variables
|
||||||
self._treeMap = {}
|
self._treeMap = {}
|
||||||
@@ -137,7 +136,7 @@ class GuiNovelTree(QTreeWidget):
|
|||||||
"""
|
"""
|
||||||
logger.verbose("Requesting refresh of the novel tree")
|
logger.verbose("Requesting refresh of the novel tree")
|
||||||
treeChanged = self.theParent.treeView.changedSince(self._lastBuild)
|
treeChanged = self.theParent.treeView.changedSince(self._lastBuild)
|
||||||
indexChanged = self.theIndex.novelChangedSince(self._lastBuild)
|
indexChanged = self.theProject.index.novelChangedSince(self._lastBuild)
|
||||||
if not (treeChanged or indexChanged or overRide):
|
if not (treeChanged or indexChanged or overRide):
|
||||||
logger.verbose("No changes have been made to the novel index")
|
logger.verbose("No changes have been made to the novel index")
|
||||||
return
|
return
|
||||||
@@ -158,7 +157,7 @@ class GuiNovelTree(QTreeWidget):
|
|||||||
def updateWordCounts(self, tHandle):
|
def updateWordCounts(self, tHandle):
|
||||||
"""Update the word count for a given handle.
|
"""Update the word count for a given handle.
|
||||||
"""
|
"""
|
||||||
tHeaders = self.theIndex.getHandleWordCounts(tHandle)
|
tHeaders = self.theProject.index.getHandleWordCounts(tHandle)
|
||||||
for titleKey, wCount in tHeaders:
|
for titleKey, wCount in tHeaders:
|
||||||
if titleKey in self._treeMap:
|
if titleKey in self._treeMap:
|
||||||
self._treeMap[titleKey].setText(self.C_WORDS, f"{wCount:n}")
|
self._treeMap[titleKey].setText(self.C_WORDS, f"{wCount:n}")
|
||||||
@@ -252,7 +251,9 @@ class GuiNovelTree(QTreeWidget):
|
|||||||
currChapter = None
|
currChapter = None
|
||||||
currScene = None
|
currScene = None
|
||||||
|
|
||||||
for tKey, tHandle, sTitle, novIdx in self.theIndex.novelStructure(skipExcluded=True):
|
for tKey, tHandle, sTitle, novIdx in self.theProject.index.novelStructure(
|
||||||
|
skipExcluded=True
|
||||||
|
):
|
||||||
|
|
||||||
tItem = self._createTreeItem(tHandle, sTitle, tKey, novIdx)
|
tItem = self._createTreeItem(tHandle, sTitle, tKey, novIdx)
|
||||||
self._treeMap[tKey] = tItem
|
self._treeMap[tKey] = tItem
|
||||||
@@ -315,7 +316,7 @@ class GuiNovelTree(QTreeWidget):
|
|||||||
newItem.setText(self.C_WORDS, f"{wC:n}")
|
newItem.setText(self.C_WORDS, f"{wC:n}")
|
||||||
newItem.setTextAlignment(self.C_WORDS, Qt.AlignRight)
|
newItem.setTextAlignment(self.C_WORDS, Qt.AlignRight)
|
||||||
|
|
||||||
theRefs = self.theIndex.getReferences(tHandle, sTitle)
|
theRefs = self.theProject.index.getReferences(tHandle, sTitle)
|
||||||
newItem.setText(self.C_POV, ", ".join(theRefs[nwKeyWords.POV_KEY]))
|
newItem.setText(self.C_POV, ", ".join(theRefs[nwKeyWords.POV_KEY]))
|
||||||
|
|
||||||
return newItem
|
return newItem
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ class GuiOutline(QTreeWidget):
|
|||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theParent.theProject
|
self.theProject = theParent.theProject
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theIndex = theParent.theIndex
|
|
||||||
self.optState = theParent.theProject.optState
|
self.optState = theParent.theProject.optState
|
||||||
self.headerMenu = GuiOutlineHeaderMenu(self)
|
self.headerMenu = GuiOutlineHeaderMenu(self)
|
||||||
|
|
||||||
@@ -182,7 +181,7 @@ class GuiOutline(QTreeWidget):
|
|||||||
|
|
||||||
# If the novel index or novel tree has changed since the tree
|
# If the novel index or novel tree has changed since the tree
|
||||||
# was last built, we rebuild the tree from the updated index.
|
# was last built, we rebuild the tree from the updated index.
|
||||||
indexChanged = self.theIndex.novelChangedSince(self._lastBuild)
|
indexChanged = self.theProject.index.novelChangedSince(self._lastBuild)
|
||||||
doBuild = (novelChanged or indexChanged) and self.theProject.autoOutline
|
doBuild = (novelChanged or indexChanged) and self.theProject.autoOutline
|
||||||
if doBuild or overRide:
|
if doBuild or overRide:
|
||||||
logger.debug("Rebuilding Project Outline")
|
logger.debug("Rebuilding Project Outline")
|
||||||
@@ -388,7 +387,7 @@ class GuiOutline(QTreeWidget):
|
|||||||
currChapter = None
|
currChapter = None
|
||||||
currScene = None
|
currScene = None
|
||||||
|
|
||||||
for tKey, tHandle, sTitle, novIdx in self.theIndex.novelStructure(skipExcluded=True):
|
for _, tHandle, sTitle, novIdx in self.theProject.index.novelStructure(skipExcluded=True):
|
||||||
|
|
||||||
tItem = self._createTreeItem(tHandle, sTitle, novIdx)
|
tItem = self._createTreeItem(tHandle, sTitle, novIdx)
|
||||||
|
|
||||||
@@ -442,7 +441,7 @@ class GuiOutline(QTreeWidget):
|
|||||||
newItem = QTreeWidgetItem()
|
newItem = QTreeWidgetItem()
|
||||||
hIcon = "doc_%s" % novIdx["level"].lower()
|
hIcon = "doc_%s" % novIdx["level"].lower()
|
||||||
|
|
||||||
hLevel = self.theIndex.getHandleHeaderLevel(tHandle)
|
hLevel = self.theProject.index.getHandleHeaderLevel(tHandle)
|
||||||
dIcon = self.theTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, hLevel)
|
dIcon = self.theTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, hLevel)
|
||||||
|
|
||||||
cC = int(novIdx["cCount"])
|
cC = int(novIdx["cCount"])
|
||||||
@@ -465,7 +464,7 @@ class GuiOutline(QTreeWidget):
|
|||||||
newItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
|
newItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
|
||||||
newItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
|
newItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
|
||||||
|
|
||||||
theRefs = self.theIndex.getReferences(tHandle, sTitle)
|
theRefs = self.theProject.index.getReferences(tHandle, sTitle)
|
||||||
newItem.setText(self._colIdx[nwOutline.POV], ", ".join(theRefs[nwKeyWords.POV_KEY]))
|
newItem.setText(self._colIdx[nwOutline.POV], ", ".join(theRefs[nwKeyWords.POV_KEY]))
|
||||||
newItem.setText(self._colIdx[nwOutline.FOCUS], ", ".join(theRefs[nwKeyWords.FOCUS_KEY]))
|
newItem.setText(self._colIdx[nwOutline.FOCUS], ", ".join(theRefs[nwKeyWords.FOCUS_KEY]))
|
||||||
newItem.setText(self._colIdx[nwOutline.CHAR], ", ".join(theRefs[nwKeyWords.CHAR_KEY]))
|
newItem.setText(self._colIdx[nwOutline.CHAR], ", ".join(theRefs[nwKeyWords.CHAR_KEY]))
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theParent.theProject
|
self.theProject = theParent.theProject
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theIndex = theParent.theIndex
|
|
||||||
self.optState = theParent.theProject.optState
|
self.optState = theParent.theProject.optState
|
||||||
|
|
||||||
# Sizes
|
# Sizes
|
||||||
@@ -283,9 +282,10 @@ class GuiOutlineDetails(QScrollArea):
|
|||||||
"""Update the content of the tree with the given handle and line
|
"""Update the content of the tree with the given handle and line
|
||||||
number pointing to a header.
|
number pointing to a header.
|
||||||
"""
|
"""
|
||||||
|
pIndex = self.theProject.index
|
||||||
nwItem = self.theProject.projTree[tHandle]
|
nwItem = self.theProject.projTree[tHandle]
|
||||||
novIdx = self.theIndex.getNovelData(tHandle, sTitle)
|
novIdx = pIndex.getNovelData(tHandle, sTitle)
|
||||||
theRefs = self.theIndex.getReferences(tHandle, sTitle)
|
theRefs = pIndex.getReferences(tHandle, sTitle)
|
||||||
if nwItem is None or novIdx is None:
|
if nwItem is None or novIdx is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
self.theProject = theParent.theProject
|
self.theProject = theParent.theProject
|
||||||
self.theIndex = theParent.theIndex
|
|
||||||
|
|
||||||
# Internal Variables
|
# Internal Variables
|
||||||
self._treeMap = {}
|
self._treeMap = {}
|
||||||
@@ -236,12 +235,14 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
else:
|
else:
|
||||||
newText = f"# {nwItem.itemName}\n\n"
|
newText = f"# {nwItem.itemName}\n\n"
|
||||||
|
|
||||||
|
pIndex = self.theProject.index
|
||||||
|
|
||||||
# Save the text and index it
|
# Save the text and index it
|
||||||
newDoc.writeDocument(newText)
|
newDoc.writeDocument(newText)
|
||||||
self.theIndex.scanText(tHandle, newText)
|
pIndex.scanText(tHandle, newText)
|
||||||
|
|
||||||
# Get Word Counts
|
# Get Word Counts
|
||||||
cC, wC, pC = self.theIndex.getCounts(tHandle)
|
cC, wC, pC = pIndex.getCounts(tHandle)
|
||||||
nwItem.setCharCount(cC)
|
nwItem.setCharCount(cC)
|
||||||
nwItem.setWordCount(wC)
|
nwItem.setWordCount(wC)
|
||||||
nwItem.setParaCount(pC)
|
nwItem.setParaCount(pC)
|
||||||
@@ -542,7 +543,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
expIcon = self.theTheme.getIcon("cross")
|
expIcon = self.theTheme.getIcon("cross")
|
||||||
|
|
||||||
itempStatus, statusIcon = nwItem.getImportStatus()
|
itempStatus, statusIcon = nwItem.getImportStatus()
|
||||||
hLevel = self.theIndex.getHandleHeaderLevel(tHandle)
|
hLevel = self.theProject.index.getHandleHeaderLevel(tHandle)
|
||||||
itemIcon = self.theTheme.getItemIcon(
|
itemIcon = self.theTheme.getItemIcon(
|
||||||
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
||||||
)
|
)
|
||||||
@@ -598,7 +599,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
if self.theProject.projTree.checkType(pHandle, nwItemType.FILE):
|
if self.theProject.projTree.checkType(pHandle, nwItemType.FILE):
|
||||||
# A file has an internal word count we need to account
|
# A file has an internal word count we need to account
|
||||||
# for, but a folder always has 0 words on its own.
|
# for, but a folder always has 0 words on its own.
|
||||||
pCount += self.theIndex.getCounts(pHandle)[1]
|
pCount += self.theProject.index.getCounts(pHandle)[1]
|
||||||
|
|
||||||
self.propagateCount(pHandle, pCount, countChildren=False)
|
self.propagateCount(pHandle, pCount, countChildren=False)
|
||||||
|
|
||||||
@@ -817,9 +818,9 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
# Update the index
|
# Update the index
|
||||||
if nwItemS.isInactive():
|
if nwItemS.isInactive():
|
||||||
self.theIndex.deleteHandle(mHandle)
|
self.theProject.index.deleteHandle(mHandle)
|
||||||
else:
|
else:
|
||||||
self.theIndex.reIndexHandle(mHandle)
|
self.theProject.index.reIndexHandle(mHandle)
|
||||||
|
|
||||||
self.setTreeItemValues(mHandle)
|
self.setTreeItemValues(mHandle)
|
||||||
|
|
||||||
@@ -854,7 +855,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
], nwAlert.ERROR)
|
], nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.theIndex.deleteHandle(tHandle)
|
self.theProject.index.deleteHandle(tHandle)
|
||||||
del self.theProject.projTree[tHandle]
|
del self.theProject.projTree[tHandle]
|
||||||
self._treeMap.pop(tHandle, None)
|
self._treeMap.pop(tHandle, None)
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ from novelwriter.dialogs import (
|
|||||||
from novelwriter.tools import (
|
from novelwriter.tools import (
|
||||||
GuiBuildNovel, GuiLipsum, GuiProjectWizard, GuiWritingStats
|
GuiBuildNovel, GuiLipsum, GuiProjectWizard, GuiWritingStats
|
||||||
)
|
)
|
||||||
from novelwriter.core import NWProject, NWIndex
|
from novelwriter.core import NWProject
|
||||||
from novelwriter.enum import (
|
from novelwriter.enum import (
|
||||||
nwItemType, nwItemClass, nwAlert, nwWidget, nwState, nwView
|
nwItemType, nwItemClass, nwAlert, nwWidget, nwState, nwView
|
||||||
)
|
)
|
||||||
@@ -86,7 +86,6 @@ class GuiMain(QMainWindow):
|
|||||||
# Core Classes and Settings
|
# Core Classes and Settings
|
||||||
self.theTheme = GuiTheme()
|
self.theTheme = GuiTheme()
|
||||||
self.theProject = NWProject(self)
|
self.theProject = NWProject(self)
|
||||||
self.theIndex = NWIndex(self.theProject)
|
|
||||||
self.hasProject = False
|
self.hasProject = False
|
||||||
self.isFocusMode = False
|
self.isFocusMode = False
|
||||||
self.idleRefTime = time()
|
self.idleRefTime = time()
|
||||||
@@ -420,7 +419,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.idleRefTime = time()
|
self.idleRefTime = time()
|
||||||
self.idleTime = 0.0
|
self.idleTime = 0.0
|
||||||
|
|
||||||
self.theIndex.clearIndex()
|
self.theProject.index.clearIndex()
|
||||||
self.clearGUI()
|
self.clearGUI()
|
||||||
self.hasProject = False
|
self.hasProject = False
|
||||||
self._changeView(nwView.PROJECT)
|
self._changeView(nwView.PROJECT)
|
||||||
@@ -497,7 +496,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.idleTime = 0.0
|
self.idleTime = 0.0
|
||||||
|
|
||||||
# Load the tag index
|
# Load the tag index
|
||||||
self.theIndex.loadIndex()
|
self.theProject.index.loadIndex()
|
||||||
|
|
||||||
# Update GUI
|
# Update GUI
|
||||||
self._updateWindowTitle(self.theProject.projName)
|
self._updateWindowTitle(self.theProject.projName)
|
||||||
@@ -516,7 +515,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.viewDocument(self.theProject.lastViewed)
|
self.viewDocument(self.theProject.lastViewed)
|
||||||
|
|
||||||
# Check if we need to rebuild the index
|
# Check if we need to rebuild the index
|
||||||
if self.theIndex.indexBroken:
|
if self.theProject.index.indexBroken:
|
||||||
self.makeAlert(self.tr(
|
self.makeAlert(self.tr(
|
||||||
"The project index is outdated or broken. Rebuilding index."
|
"The project index is outdated or broken. Rebuilding index."
|
||||||
), nwAlert.INFO)
|
), nwAlert.INFO)
|
||||||
@@ -540,7 +539,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
self.treeView.saveTreeOrder()
|
self.treeView.saveTreeOrder()
|
||||||
if self.theProject.saveProject(autoSave=autoSave):
|
if self.theProject.saveProject(autoSave=autoSave):
|
||||||
self.theIndex.saveIndex()
|
self.theProject.index.saveIndex()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -863,7 +862,7 @@ class GuiMain(QMainWindow):
|
|||||||
tStart = time()
|
tStart = time()
|
||||||
|
|
||||||
self.treeView.saveTreeOrder()
|
self.treeView.saveTreeOrder()
|
||||||
self.theIndex.clearIndex()
|
self.theProject.index.clearIndex()
|
||||||
|
|
||||||
for tItem in self.theProject.projTree:
|
for tItem in self.theProject.projTree:
|
||||||
|
|
||||||
@@ -874,10 +873,10 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
if tItem is not None and tItem.itemType == nwItemType.FILE:
|
if tItem is not None and tItem.itemType == nwItemType.FILE:
|
||||||
logger.verbose("Scanning '%s'", tItem.itemName)
|
logger.verbose("Scanning '%s'", tItem.itemName)
|
||||||
self.theIndex.reIndexHandle(tItem.itemHandle)
|
self.theProject.index.reIndexHandle(tItem.itemHandle)
|
||||||
|
|
||||||
# Get Word Counts
|
# Get Word Counts
|
||||||
cC, wC, pC = self.theIndex.getCounts(tItem.itemHandle)
|
cC, wC, pC = self.theProject.index.getCounts(tItem.itemHandle)
|
||||||
tItem.setCharCount(cC)
|
tItem.setCharCount(cC)
|
||||||
tItem.setWordCount(wC)
|
tItem.setWordCount(wC)
|
||||||
tItem.setParaCount(pC)
|
tItem.setParaCount(pC)
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ class MockGuiMain():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mainConf = None
|
self.mainConf = None
|
||||||
self.hasProject = True
|
self.hasProject = True
|
||||||
self.theIndex = None
|
|
||||||
self.theProject = None
|
self.theProject = None
|
||||||
self.statusBar = MockStatusBar()
|
self.statusBar = MockStatusBar()
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum):
|
|||||||
|
|
||||||
# Rebuild the index
|
# Rebuild the index
|
||||||
nwGUI.mainMenu.aRebuildIndex.activate(QAction.Trigger)
|
nwGUI.mainMenu.aRebuildIndex.activate(QAction.Trigger)
|
||||||
assert nwGUI.theIndex._tagIndex != {}
|
assert nwGUI.theProject.index._tagIndex != {}
|
||||||
assert nwGUI.theIndex._refIndex != {}
|
assert nwGUI.theProject.index._refIndex != {}
|
||||||
|
|
||||||
# Select a document in the project tree
|
# Select a document in the project tree
|
||||||
nwGUI.treeView.setSelectedHandle("88243afbe5ed8")
|
nwGUI.treeView.setSelectedHandle("88243afbe5ed8")
|
||||||
|
|||||||
Reference in New Issue
Block a user