Make project instance private to main GUI class
This commit is contained in:
@@ -41,11 +41,10 @@ class NovelSelector(QComboBox):
|
||||
|
||||
novelSelectionChanged = pyqtSignal(str)
|
||||
|
||||
def __init__(self, parent, project, mainGui):
|
||||
def __init__(self, parent, mainGui):
|
||||
super().__init__(parent=parent)
|
||||
|
||||
self._mainGui = mainGui
|
||||
self._project = project
|
||||
self._blockSignal = False
|
||||
self._firstHandle = None
|
||||
|
||||
@@ -91,7 +90,7 @@ class NovelSelector(QComboBox):
|
||||
|
||||
icon = CONFIG.theme.getIcon(nwLabels.CLASS_ICON[nwItemClass.NOVEL])
|
||||
handle = self.currentData()
|
||||
for tHandle, nwItem in self._project.tree.iterRoots(nwItemClass.NOVEL):
|
||||
for tHandle, nwItem in self._mainGui.project.tree.iterRoots(nwItemClass.NOVEL):
|
||||
if prefix:
|
||||
name = prefix.format(nwItem.itemName)
|
||||
self.addItem(name, tHandle)
|
||||
|
||||
@@ -84,8 +84,7 @@ class GuiDocEditor(QTextEdit):
|
||||
logger.debug("Create: GuiDocEditor")
|
||||
|
||||
# Class Variables
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.mainGui = mainGui
|
||||
|
||||
self._nwDocument = None
|
||||
self._nwItem = None
|
||||
@@ -133,7 +132,7 @@ class GuiDocEditor(QTextEdit):
|
||||
self.docSearch = GuiDocEditSearch(self)
|
||||
|
||||
# Syntax
|
||||
self.spEnchant = NWSpellEnchant(self.theProject)
|
||||
self.spEnchant = NWSpellEnchant(self.mainGui.project)
|
||||
self.highLight = GuiDocHighlighter(qDoc, self.mainGui, self.spEnchant)
|
||||
|
||||
# Context Menu
|
||||
@@ -341,7 +340,7 @@ class GuiDocEditor(QTextEdit):
|
||||
document is new (empty string), we set up the editor for editing
|
||||
the file.
|
||||
"""
|
||||
self._nwDocument = self.theProject.storage.getDocument(tHandle)
|
||||
self._nwDocument = self.mainGui.project.storage.getDocument(tHandle)
|
||||
self._nwItem = self._nwDocument.getCurrentItem()
|
||||
|
||||
theDoc = self._nwDocument.readDocument()
|
||||
@@ -517,10 +516,10 @@ class GuiDocEditor(QTextEdit):
|
||||
self.setDocumentChanged(False)
|
||||
|
||||
oldHeader = self._nwItem.mainHeading
|
||||
oldCount = self.theProject.index.getHandleHeaderCount(tHandle)
|
||||
self.theProject.index.scanText(tHandle, docText)
|
||||
oldCount = self.mainGui.project.index.getHandleHeaderCount(tHandle)
|
||||
self.mainGui.project.index.scanText(tHandle, docText)
|
||||
newHeader = self._nwItem.mainHeading
|
||||
newCount = self.theProject.index.getHandleHeaderCount(tHandle)
|
||||
newCount = self.mainGui.project.index.getHandleHeaderCount(tHandle)
|
||||
|
||||
if self._nwItem.itemClass == nwItemClass.NOVEL:
|
||||
if oldCount == newCount:
|
||||
@@ -699,10 +698,10 @@ class GuiDocEditor(QTextEdit):
|
||||
"""Set the spell checker dictionary language, and emit the
|
||||
dictionary changed signal.
|
||||
"""
|
||||
if self.theProject.data.spellLang is None:
|
||||
if self.mainGui.project.data.spellLang is None:
|
||||
theLang = CONFIG.spellLanguage
|
||||
else:
|
||||
theLang = self.theProject.data.spellLang
|
||||
theLang = self.mainGui.project.data.spellLang
|
||||
|
||||
self.spEnchant.setLanguage(theLang)
|
||||
_, theProvider = self.spEnchant.describeDict()
|
||||
@@ -735,7 +734,7 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
self._spellCheck = theMode
|
||||
self.mainGui.mainMenu.setSpellCheck(theMode)
|
||||
self.theProject.data.setSpellCheck(theMode)
|
||||
self.mainGui.project.data.setSpellCheck(theMode)
|
||||
self.highLight.setSpellCheck(theMode)
|
||||
if not self._bigDoc or theMode is False:
|
||||
# We don't run the spell checker automatically on big docs
|
||||
@@ -1917,7 +1916,7 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
if theText.startswith("@"):
|
||||
|
||||
isGood, tBits, tPos = self.theProject.index.scanThis(theText)
|
||||
isGood, tBits, tPos = self.mainGui.project.index.scanThis(theText)
|
||||
if not isGood:
|
||||
return False
|
||||
|
||||
@@ -2222,9 +2221,8 @@ class GuiDocEditSearch(QFrame):
|
||||
|
||||
logger.debug("Create: GuiDocEditSearch")
|
||||
|
||||
self.docEditor = docEditor
|
||||
self.mainGui = docEditor.mainGui
|
||||
self.theProject = docEditor.theProject
|
||||
self.docEditor = docEditor
|
||||
self.mainGui = docEditor.mainGui
|
||||
|
||||
self.repVisible = False
|
||||
self.isCaseSense = CONFIG.searchCase
|
||||
@@ -2636,9 +2634,8 @@ class GuiDocEditHeader(QWidget):
|
||||
|
||||
logger.debug("Create: GuiDocEditHeader")
|
||||
|
||||
self.docEditor = docEditor
|
||||
self.mainGui = docEditor.mainGui
|
||||
self.theProject = docEditor.theProject
|
||||
self.docEditor = docEditor
|
||||
self.mainGui = docEditor.mainGui
|
||||
|
||||
self._docHandle = None
|
||||
|
||||
@@ -2775,17 +2772,18 @@ class GuiDocEditHeader(QWidget):
|
||||
self.minmaxButton.setVisible(False)
|
||||
return True
|
||||
|
||||
pTree = self.mainGui.project.tree
|
||||
if CONFIG.showFullPath:
|
||||
tTitle = []
|
||||
tTree = self.theProject.tree.getItemPath(tHandle)
|
||||
tTree = pTree.getItemPath(tHandle)
|
||||
for aHandle in reversed(tTree):
|
||||
nwItem = self.theProject.tree[aHandle]
|
||||
nwItem = pTree[aHandle]
|
||||
if nwItem is not None:
|
||||
tTitle.append(nwItem.itemName)
|
||||
sSep = " %s " % nwUnicode.U_RSAQUO
|
||||
self.theTitle.setText(sSep.join(tTitle))
|
||||
else:
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = pTree[tHandle]
|
||||
if nwItem is None:
|
||||
return False
|
||||
self.theTitle.setText(nwItem.itemName)
|
||||
@@ -2870,9 +2868,8 @@ class GuiDocEditFooter(QWidget):
|
||||
|
||||
logger.debug("Create: GuiDocEditFooter")
|
||||
|
||||
self.docEditor = docEditor
|
||||
self.mainGui = docEditor.mainGui
|
||||
self.theProject = docEditor.theProject
|
||||
self.docEditor = docEditor
|
||||
self.mainGui = docEditor.mainGui
|
||||
|
||||
self._theItem = None
|
||||
self._docHandle = None
|
||||
@@ -3003,7 +3000,7 @@ class GuiDocEditFooter(QWidget):
|
||||
logger.debug("No handle set, so clearing the editor footer")
|
||||
self._theItem = None
|
||||
else:
|
||||
self._theItem = self.theProject.tree[self._docHandle]
|
||||
self._theItem = self.mainGui.project.tree[self._docHandle]
|
||||
|
||||
self.setHasSelection(False)
|
||||
self.updateInfo()
|
||||
|
||||
@@ -54,7 +54,6 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
self.theDoc = theDoc
|
||||
self.spEnchant = spEnchant
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.theHandle = None
|
||||
self.spellCheck = False
|
||||
self.spellRx = None
|
||||
@@ -286,8 +285,8 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
|
||||
if theText.startswith("@"): # Keywords and commands
|
||||
self.setCurrentBlockState(self.BLOCK_META)
|
||||
pIndex = self.theProject.index
|
||||
tItem = self.mainGui.theProject.tree[self.theHandle]
|
||||
pIndex = self.mainGui.project.index
|
||||
tItem = self.mainGui.project.tree[self.theHandle]
|
||||
isValid, theBits, thePos = pIndex.scanThis(theText)
|
||||
isGood = pIndex.checkThese(theBits, tItem)
|
||||
if isValid:
|
||||
|
||||
@@ -59,8 +59,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
logger.debug("Create: GuiDocViewer")
|
||||
|
||||
# Class Variables
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.mainGui = mainGui
|
||||
|
||||
# Internal Variables
|
||||
self._docHandle = None
|
||||
@@ -163,7 +162,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
def loadText(self, tHandle, updateHistory=True):
|
||||
"""Load text into the viewer from an item handle.
|
||||
"""
|
||||
if not self.theProject.tree.checkType(tHandle, nwItemType.FILE):
|
||||
if not self.mainGui.project.tree.checkType(tHandle, nwItemType.FILE):
|
||||
logger.warning("Item not found")
|
||||
return False
|
||||
|
||||
@@ -171,7 +170,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||
|
||||
sPos = self.verticalScrollBar().value()
|
||||
aDoc = ToHtml(self.theProject)
|
||||
aDoc = ToHtml(self.mainGui.project)
|
||||
aDoc.setPreview(CONFIG.viewComments, CONFIG.viewSynopsis)
|
||||
aDoc.setLinkHeaders(True)
|
||||
|
||||
@@ -211,7 +210,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
self.verticalScrollBar().setValue(sPos)
|
||||
|
||||
self._docHandle = tHandle
|
||||
self.theProject._data.setLastHandle(tHandle, "viewer")
|
||||
self.mainGui.project.data.setLastHandle(tHandle, "viewer")
|
||||
self.docHeader.setTitleFromHandle(self._docHandle)
|
||||
self.updateDocMargins()
|
||||
|
||||
@@ -680,9 +679,8 @@ class GuiDocViewHeader(QWidget):
|
||||
|
||||
logger.debug("Create: GuiDocViewHeader")
|
||||
|
||||
self.docViewer = docViewer
|
||||
self.mainGui = docViewer.mainGui
|
||||
self.theProject = docViewer.theProject
|
||||
self.docViewer = docViewer
|
||||
self.mainGui = docViewer.mainGui
|
||||
|
||||
# Internal Variables
|
||||
self._docHandle = None
|
||||
@@ -821,17 +819,18 @@ class GuiDocViewHeader(QWidget):
|
||||
self.refreshButton.setVisible(False)
|
||||
return True
|
||||
|
||||
pTree = self.mainGui.project.tree
|
||||
if CONFIG.showFullPath:
|
||||
tTitle = []
|
||||
tTree = self.theProject.tree.getItemPath(tHandle)
|
||||
tTree = pTree.getItemPath(tHandle)
|
||||
for aHandle in reversed(tTree):
|
||||
nwItem = self.theProject.tree[aHandle]
|
||||
nwItem = pTree[aHandle]
|
||||
if nwItem is not None:
|
||||
tTitle.append(nwItem.itemName)
|
||||
sSep = " %s " % nwUnicode.U_RSAQUO
|
||||
self.theTitle.setText(sSep.join(tTitle))
|
||||
else:
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = pTree[tHandle]
|
||||
if nwItem is None:
|
||||
return False
|
||||
self.theTitle.setText(nwItem.itemName)
|
||||
@@ -1138,8 +1137,7 @@ class GuiDocViewDetails(QScrollArea):
|
||||
|
||||
logger.debug("Create: GuiDocViewDetails")
|
||||
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.mainGui = mainGui
|
||||
|
||||
self.refList = QLabel("")
|
||||
self.refList.setWordWrap(True)
|
||||
@@ -1174,10 +1172,10 @@ class GuiDocViewDetails(QScrollArea):
|
||||
if self.mainGui.docViewer.stickyRef:
|
||||
return
|
||||
|
||||
theRefs = self.theProject.index.getBackReferenceList(tHandle)
|
||||
theRefs = self.mainGui.project.index.getBackReferenceList(tHandle)
|
||||
theList = []
|
||||
for tHandle in theRefs:
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is not None:
|
||||
theList.append("<a href='%s#%s' %s>%s</a>" % (
|
||||
tHandle, theRefs[tHandle], self.linkStyle, tItem.itemName
|
||||
|
||||
@@ -42,8 +42,7 @@ class GuiItemDetails(QWidget):
|
||||
|
||||
logger.debug("Create: GuiItemDetails")
|
||||
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.mainGui = mainGui
|
||||
|
||||
# Internal Variables
|
||||
self._itemHandle = None
|
||||
@@ -234,7 +233,7 @@ class GuiItemDetails(QWidget):
|
||||
self.clearDetails()
|
||||
return
|
||||
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = self.mainGui.project.tree[tHandle]
|
||||
if nwItem is None:
|
||||
self.clearDetails()
|
||||
return
|
||||
|
||||
+13
-14
@@ -51,8 +51,7 @@ class GuiMainMenu(QMenuBar):
|
||||
|
||||
logger.debug("Create: GuiMainMenu")
|
||||
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.mainGui = mainGui
|
||||
|
||||
# Build Menu
|
||||
self._buildProjectMenu()
|
||||
@@ -380,10 +379,10 @@ class GuiMainMenu(QMenuBar):
|
||||
"""Assemble the Insert menu.
|
||||
"""
|
||||
# Insert
|
||||
self.insertMenu = self.addMenu(self.tr("&Insert"))
|
||||
self.insMenu = self.addMenu(self.tr("&Insert"))
|
||||
|
||||
# Insert > Dashes and Dots
|
||||
self.mInsDashes = self.insertMenu.addMenu(self.tr("Dashes"))
|
||||
self.mInsDashes = self.insMenu.addMenu(self.tr("Dashes"))
|
||||
|
||||
# Insert > Short Dash
|
||||
self.aInsENDash = QAction(self.tr("Short Dash"), self)
|
||||
@@ -410,7 +409,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsDashes.addAction(self.aInsFigDash)
|
||||
|
||||
# Insert > Quote Marks
|
||||
self.mInsQuotes = self.insertMenu.addMenu(self.tr("Quote Marks"))
|
||||
self.mInsQuotes = self.insMenu.addMenu(self.tr("Quote Marks"))
|
||||
|
||||
# Insert > Left Single Quote
|
||||
self.aInsQuoteLS = QAction(self.tr("Left Single Quote"), self)
|
||||
@@ -443,7 +442,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsQuotes.addAction(self.aInsMSApos)
|
||||
|
||||
# Insert > Symbols
|
||||
self.mInsPunct = self.insertMenu.addMenu(self.tr("General Punctuation"))
|
||||
self.mInsPunct = self.insMenu.addMenu(self.tr("General Punctuation"))
|
||||
|
||||
# Insert > Ellipsis
|
||||
self.aInsEllipsis = QAction(self.tr("Ellipsis"), self)
|
||||
@@ -464,7 +463,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsPunct.addAction(self.aInsDPrime)
|
||||
|
||||
# Insert > White Spaces
|
||||
self.mInsSpace = self.insertMenu.addMenu(self.tr("White Spaces"))
|
||||
self.mInsSpace = self.insMenu.addMenu(self.tr("White Spaces"))
|
||||
|
||||
# Insert > Non-Breaking Space
|
||||
self.aInsNBSpace = QAction(self.tr("Non-Breaking Space"), self)
|
||||
@@ -485,7 +484,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsSpace.addAction(self.aInsThinNBSpace)
|
||||
|
||||
# Insert > Symbols
|
||||
self.mInsSymbol = self.insertMenu.addMenu(self.tr("Other Symbols"))
|
||||
self.mInsSymbol = self.insMenu.addMenu(self.tr("Other Symbols"))
|
||||
|
||||
# Insert > List Bullet
|
||||
self.aInsBullet = QAction(self.tr("List Bullet"), self)
|
||||
@@ -536,7 +535,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsSymbol.addAction(self.aInsDivide)
|
||||
|
||||
# Insert > Tags and References
|
||||
self.mInsKeywords = self.insertMenu.addMenu(self.tr("Tags and References"))
|
||||
self.mInsKeywords = self.insMenu.addMenu(self.tr("Tags and References"))
|
||||
self.mInsKWItems = {}
|
||||
self.mInsKWItems[nwKeyWords.TAG_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, G")
|
||||
self.mInsKWItems[nwKeyWords.POV_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, V")
|
||||
@@ -557,7 +556,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsKeywords.addAction(self.mInsKWItems[keyWord][0])
|
||||
|
||||
# Insert > Special Comments
|
||||
self.mInsComments = self.insertMenu.addMenu(self.tr("Special Comments"))
|
||||
self.mInsComments = self.insMenu.addMenu(self.tr("Special Comments"))
|
||||
|
||||
# Insert > Synopsis Comment
|
||||
self.aInsSynopsis = QAction(self.tr("Synopsis Comment"), self)
|
||||
@@ -566,7 +565,7 @@ class GuiMainMenu(QMenuBar):
|
||||
self.mInsComments.addAction(self.aInsSynopsis)
|
||||
|
||||
# Insert > Symbols
|
||||
self.mInsBreaks = self.insertMenu.addMenu(self.tr("Page Break and Space"))
|
||||
self.mInsBreaks = self.insMenu.addMenu(self.tr("Page Break and Space"))
|
||||
|
||||
# Insert > New Page
|
||||
self.aInsNewPage = QAction(self.tr("Page Break"), self)
|
||||
@@ -586,7 +585,7 @@ class GuiMainMenu(QMenuBar):
|
||||
# Insert > Placeholder Text
|
||||
self.aLipsumText = QAction(self.tr("Placeholder Text"), self)
|
||||
self.aLipsumText.triggered.connect(lambda: self.mainGui.showLoremIpsumDialog())
|
||||
self.insertMenu.addAction(self.aLipsumText)
|
||||
self.insMenu.addAction(self.aLipsumText)
|
||||
|
||||
return
|
||||
|
||||
@@ -796,7 +795,7 @@ class GuiMainMenu(QMenuBar):
|
||||
# Tools > Check Spelling
|
||||
self.aSpellCheck = QAction(self.tr("Check Spelling"), self)
|
||||
self.aSpellCheck.setCheckable(True)
|
||||
self.aSpellCheck.setChecked(self.theProject.data.spellCheck)
|
||||
self.aSpellCheck.setChecked(self.mainGui.project.data.spellCheck)
|
||||
self.aSpellCheck.triggered.connect(self._toggleSpellCheck) # triggered, not toggled!
|
||||
self.aSpellCheck.setShortcut("Ctrl+F7")
|
||||
self.toolsMenu.addAction(self.aSpellCheck)
|
||||
@@ -826,7 +825,7 @@ class GuiMainMenu(QMenuBar):
|
||||
|
||||
# Tools > Backup Project
|
||||
self.aBackupProject = QAction(self.tr("Backup Project"), self)
|
||||
self.aBackupProject.triggered.connect(lambda: self.theProject.backupProject(True))
|
||||
self.aBackupProject.triggered.connect(lambda: self.mainGui.project.backupProject(True))
|
||||
self.toolsMenu.addAction(self.aBackupProject)
|
||||
|
||||
# Tools > Build Manuscript
|
||||
|
||||
@@ -66,8 +66,7 @@ class GuiNovelView(QWidget):
|
||||
def __init__(self, mainGui):
|
||||
super().__init__(parent=mainGui)
|
||||
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.mainGui = mainGui
|
||||
|
||||
# Build GUI
|
||||
self.novelTree = GuiNovelTree(self)
|
||||
@@ -118,16 +117,16 @@ class GuiNovelView(QWidget):
|
||||
def openProjectTasks(self):
|
||||
"""Run open project tasks.
|
||||
"""
|
||||
lastNovel = self.theProject.data.getLastHandle("novelTree")
|
||||
if lastNovel not in self.theProject.tree:
|
||||
lastNovel = self.theProject.tree.findRoot(nwItemClass.NOVEL)
|
||||
lastNovel = self.mainGui.project.data.getLastHandle("novelTree")
|
||||
if lastNovel not in self.mainGui.project.tree:
|
||||
lastNovel = self.mainGui.project.tree.findRoot(nwItemClass.NOVEL)
|
||||
|
||||
logger.debug("Setting novel tree to root item '%s'", lastNovel)
|
||||
|
||||
lastCol = self.theProject.options.getEnum(
|
||||
lastCol = self.mainGui.project.options.getEnum(
|
||||
"GuiNovelView", "lastCol", NovelTreeColumn, NovelTreeColumn.HIDDEN
|
||||
)
|
||||
lastColSize = self.theProject.options.getInt(
|
||||
lastColSize = self.mainGui.project.options.getInt(
|
||||
"GuiNovelView", "lastColSize", 25
|
||||
)
|
||||
|
||||
@@ -147,8 +146,9 @@ class GuiNovelView(QWidget):
|
||||
"""
|
||||
lastColType = self.novelTree.lastColType
|
||||
lastColSize = self.novelTree.lastColSize
|
||||
self.theProject.options.setValue("GuiNovelView", "lastCol", lastColType)
|
||||
self.theProject.options.setValue("GuiNovelView", "lastColSize", lastColSize)
|
||||
pOptions = self.mainGui.project.options
|
||||
pOptions.setValue("GuiNovelView", "lastCol", lastColType)
|
||||
pOptions.setValue("GuiNovelView", "lastColSize", lastColSize)
|
||||
return
|
||||
|
||||
def setTreeFocus(self):
|
||||
@@ -170,7 +170,7 @@ class GuiNovelView(QWidget):
|
||||
def refreshTree(self):
|
||||
"""Refresh the current tree.
|
||||
"""
|
||||
self.novelTree.refreshTree(rootHandle=self.theProject.data.getLastHandle("novelTree"))
|
||||
self.novelTree.refreshTree(rootHandle=self.mainGui.project.data.getLastHandle("novelTree"))
|
||||
return
|
||||
|
||||
@pyqtSlot(str)
|
||||
@@ -198,9 +198,8 @@ class GuiNovelToolBar(QWidget):
|
||||
|
||||
logger.debug("Create: GuiNovelToolBar")
|
||||
|
||||
self.novelView = novelView
|
||||
self.mainGui = novelView.mainGui
|
||||
self.theProject = novelView.mainGui.theProject
|
||||
self.novelView = novelView
|
||||
self.mainGui = novelView.mainGui
|
||||
|
||||
iPx = CONFIG.theme.baseIconSize
|
||||
mPx = CONFIG.pxInt(2)
|
||||
@@ -212,7 +211,7 @@ class GuiNovelToolBar(QWidget):
|
||||
selFont = self.font()
|
||||
selFont.setWeight(QFont.Bold)
|
||||
self.novelPrefix = self.tr("Outline of {0}")
|
||||
self.novelValue = NovelSelector(self, self.theProject, self.mainGui)
|
||||
self.novelValue = NovelSelector(self, self.mainGui)
|
||||
self.novelValue.setFont(selFont)
|
||||
self.novelValue.setMinimumWidth(CONFIG.pxInt(150))
|
||||
self.novelValue.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
@@ -346,7 +345,7 @@ class GuiNovelToolBar(QWidget):
|
||||
def _refreshNovelTree(self):
|
||||
"""Rebuild the current tree.
|
||||
"""
|
||||
rootHandle = self.theProject.data.getLastHandle("novelTree")
|
||||
rootHandle = self.mainGui.project.data.getLastHandle("novelTree")
|
||||
self.novelView.novelTree.refreshTree(rootHandle=rootHandle, overRide=True)
|
||||
return
|
||||
|
||||
@@ -398,9 +397,8 @@ class GuiNovelTree(QTreeWidget):
|
||||
|
||||
logger.debug("Create: GuiNovelTree")
|
||||
|
||||
self.novelView = novelView
|
||||
self.mainGui = novelView.mainGui
|
||||
self.theProject = novelView.mainGui.theProject
|
||||
self.novelView = novelView
|
||||
self.mainGui = novelView.mainGui
|
||||
|
||||
# Internal Variables
|
||||
self._treeMap = {}
|
||||
@@ -516,10 +514,10 @@ class GuiNovelTree(QTreeWidget):
|
||||
"""
|
||||
logger.debug("Requesting refresh of the novel tree")
|
||||
if rootHandle is None:
|
||||
rootHandle = self.theProject.tree.findRoot(nwItemClass.NOVEL)
|
||||
rootHandle = self.mainGui.project.tree.findRoot(nwItemClass.NOVEL)
|
||||
|
||||
treeChanged = self.mainGui.projView.changedSince(self._lastBuild)
|
||||
indexChanged = self.theProject.index.rootChangedSince(rootHandle, self._lastBuild)
|
||||
indexChanged = self.mainGui.project.index.rootChangedSince(rootHandle, self._lastBuild)
|
||||
if not (treeChanged or indexChanged or overRide):
|
||||
logger.debug("No changes have been made to the novel index")
|
||||
return
|
||||
@@ -530,7 +528,7 @@ class GuiNovelTree(QTreeWidget):
|
||||
titleKey = selItem[0].data(self.C_DATA, self.D_KEY)
|
||||
|
||||
self._populateTree(rootHandle)
|
||||
self.theProject.data.setLastHandle(rootHandle, "novelTree")
|
||||
self.mainGui.project.data.setLastHandle(rootHandle, "novelTree")
|
||||
|
||||
if titleKey is not None and titleKey in self._treeMap:
|
||||
self._treeMap[titleKey].setSelected(True)
|
||||
@@ -540,7 +538,7 @@ class GuiNovelTree(QTreeWidget):
|
||||
def refreshHandle(self, tHandle):
|
||||
"""Refresh the data for a given handle.
|
||||
"""
|
||||
idxData = self.theProject.index.getItemData(tHandle)
|
||||
idxData = self.mainGui.project.index.getItemData(tHandle)
|
||||
if idxData is None:
|
||||
return
|
||||
|
||||
@@ -577,7 +575,7 @@ class GuiNovelTree(QTreeWidget):
|
||||
self._lastCol = colType
|
||||
self.setColumnHidden(self.C_EXTRA, colType == NovelTreeColumn.HIDDEN)
|
||||
if doRefresh:
|
||||
lastNovel = self.theProject.data.getLastHandle("novelTree")
|
||||
lastNovel = self.mainGui.project.data.getLastHandle("novelTree")
|
||||
self.refreshTree(rootHandle=lastNovel, overRide=True)
|
||||
return
|
||||
|
||||
@@ -709,7 +707,7 @@ class GuiNovelTree(QTreeWidget):
|
||||
tStart = time()
|
||||
logger.debug("Building novel tree for root item '%s'", rootHandle)
|
||||
|
||||
novStruct = self.theProject.index.novelStructure(rootHandle=rootHandle, skipExcl=True)
|
||||
novStruct = self.mainGui.project.index.novelStructure(rootHandle=rootHandle, skipExcl=True)
|
||||
for tKey, tHandle, sTitle, novIdx in novStruct:
|
||||
if novIdx.level == "H0":
|
||||
continue
|
||||
@@ -761,7 +759,7 @@ class GuiNovelTree(QTreeWidget):
|
||||
|
||||
refData = []
|
||||
refName = ""
|
||||
theRefs = self.theProject.index.getReferences(tHandle, sTitle)
|
||||
theRefs = self.mainGui.project.index.getReferences(tHandle, sTitle)
|
||||
if self._lastCol == NovelTreeColumn.POV:
|
||||
refData = theRefs[nwKeyWords.POV_KEY]
|
||||
refName = self._povLabel
|
||||
@@ -785,7 +783,7 @@ class GuiNovelTree(QTreeWidget):
|
||||
"""
|
||||
logger.debug("Generating meta data tooltip for '%s:%s'", tHandle, sTitle)
|
||||
|
||||
pIndex = self.theProject.index
|
||||
pIndex = self.mainGui.project.index
|
||||
novIdx = pIndex.getItemHeader(tHandle, sTitle)
|
||||
refTags = pIndex.getReferences(tHandle, sTitle)
|
||||
|
||||
|
||||
+17
-21
@@ -62,8 +62,7 @@ class GuiOutlineView(QWidget):
|
||||
def __init__(self, mainGui):
|
||||
super().__init__(parent=mainGui)
|
||||
|
||||
self.mainGui = mainGui
|
||||
self.theProject = mainGui.theProject
|
||||
self.mainGui = mainGui
|
||||
|
||||
# Build GUI
|
||||
self.outlineTree = GuiOutlineTree(self)
|
||||
@@ -118,7 +117,7 @@ class GuiOutlineView(QWidget):
|
||||
def refreshTree(self):
|
||||
"""Refresh the current tree.
|
||||
"""
|
||||
self.outlineTree.refreshTree(rootHandle=self.theProject.data.getLastHandle("outline"))
|
||||
self.outlineTree.refreshTree(rootHandle=self.mainGui.project.data.getLastHandle("outline"))
|
||||
return
|
||||
|
||||
def clearProject(self):
|
||||
@@ -131,9 +130,9 @@ class GuiOutlineView(QWidget):
|
||||
def openProjectTasks(self):
|
||||
"""Run open project tasks.
|
||||
"""
|
||||
lastOutline = self.theProject.data.getLastHandle("outline")
|
||||
if not (lastOutline in self.theProject.tree or lastOutline is None):
|
||||
lastOutline = self.theProject.tree.findRoot(nwItemClass.NOVEL)
|
||||
lastOutline = self.mainGui.project.data.getLastHandle("outline")
|
||||
if not (lastOutline in self.mainGui.project.tree or lastOutline is None):
|
||||
lastOutline = self.mainGui.project.tree.findRoot(nwItemClass.NOVEL)
|
||||
|
||||
logger.debug("Setting outline tree to root item '%s'", lastOutline)
|
||||
|
||||
@@ -215,8 +214,7 @@ class GuiOutlineToolBar(QToolBar):
|
||||
|
||||
logger.debug("Create: GuiOutlineToolBar")
|
||||
|
||||
self.mainGui = theOutline.mainGui
|
||||
self.theProject = theOutline.mainGui.theProject
|
||||
self.mainGui = theOutline.mainGui
|
||||
|
||||
iPx = CONFIG.pxInt(22)
|
||||
mPx = CONFIG.pxInt(12)
|
||||
@@ -232,7 +230,7 @@ class GuiOutlineToolBar(QToolBar):
|
||||
self.novelLabel = QLabel(self.tr("Outline of"))
|
||||
self.novelLabel.setContentsMargins(0, 0, mPx, 0)
|
||||
|
||||
self.novelValue = NovelSelector(self, self.theProject, self.mainGui)
|
||||
self.novelValue = NovelSelector(self, self.mainGui)
|
||||
self.novelValue.setMinimumWidth(CONFIG.pxInt(200))
|
||||
self.novelValue.novelSelectionChanged.connect(self._novelValueChanged)
|
||||
|
||||
@@ -373,7 +371,6 @@ class GuiOutlineTree(QTreeWidget):
|
||||
|
||||
self.outlineView = outlineView
|
||||
self.mainGui = outlineView.mainGui
|
||||
self.theProject = outlineView.mainGui.theProject
|
||||
|
||||
self.setUniformRowHeights(True)
|
||||
self.setFrameStyle(QFrame.NoFrame)
|
||||
@@ -491,13 +488,13 @@ class GuiOutlineTree(QTreeWidget):
|
||||
|
||||
# If the novel index or novel tree has changed since the tree
|
||||
# was last built, we rebuild the tree from the updated index.
|
||||
indexChanged = self.theProject.index.rootChangedSince(rootHandle, self._lastBuild)
|
||||
indexChanged = self.mainGui.project.index.rootChangedSince(rootHandle, self._lastBuild)
|
||||
if not (novelChanged or indexChanged or overRide):
|
||||
logger.debug("No changes have been made to the novel index")
|
||||
return
|
||||
|
||||
self._populateTree(rootHandle)
|
||||
self.theProject.data.setLastHandle(rootHandle or None, "outline")
|
||||
self.mainGui.project.data.setLastHandle(rootHandle or None, "outline")
|
||||
|
||||
return
|
||||
|
||||
@@ -577,7 +574,7 @@ class GuiOutlineTree(QTreeWidget):
|
||||
"""
|
||||
# Load whatever we saved last time, regardless of wether it
|
||||
# contains the correct names or number of columns.
|
||||
colState = self.theProject.options.getValue("GuiOutline", "columnState", {})
|
||||
colState = self.mainGui.project.options.getValue("GuiOutline", "columnState", {})
|
||||
|
||||
tmpOrder = []
|
||||
tmpHidden = {}
|
||||
@@ -628,7 +625,7 @@ class GuiOutlineTree(QTreeWidget):
|
||||
logHidden, orgWidth if logHidden and logWidth == 0 else logWidth
|
||||
]
|
||||
|
||||
pOptions = self.theProject.options
|
||||
pOptions = self.mainGui.project.options
|
||||
pOptions.setValue("GuiOutline", "columnState", colState)
|
||||
pOptions.saveSettings()
|
||||
|
||||
@@ -664,7 +661,7 @@ class GuiOutlineTree(QTreeWidget):
|
||||
headItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
|
||||
headItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
|
||||
|
||||
novStruct = self.theProject.index.novelStructure(rootHandle=rootHandle, skipExcl=True)
|
||||
novStruct = self.mainGui.project.index.novelStructure(rootHandle=rootHandle, skipExcl=True)
|
||||
for _, tHandle, sTitle, novIdx in novStruct:
|
||||
|
||||
iLevel = nwHeaders.H_LEVEL.get(novIdx.level, 0)
|
||||
@@ -672,7 +669,7 @@ class GuiOutlineTree(QTreeWidget):
|
||||
continue
|
||||
|
||||
trItem = QTreeWidgetItem()
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = self.mainGui.project.tree[tHandle]
|
||||
hDec = CONFIG.theme.getHeaderDecoration(iLevel)
|
||||
|
||||
trItem.setData(self._colIdx[nwOutline.TITLE], Qt.DecorationRole, hDec)
|
||||
@@ -692,7 +689,7 @@ class GuiOutlineTree(QTreeWidget):
|
||||
trItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
|
||||
trItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
|
||||
|
||||
refs = self.theProject.index.getReferences(tHandle, sTitle)
|
||||
refs = self.mainGui.project.index.getReferences(tHandle, sTitle)
|
||||
trItem.setText(self._colIdx[nwOutline.POV], ", ".join(refs[nwKeyWords.POV_KEY]))
|
||||
trItem.setText(self._colIdx[nwOutline.FOCUS], ", ".join(refs[nwKeyWords.FOCUS_KEY]))
|
||||
trItem.setText(self._colIdx[nwOutline.CHAR], ", ".join(refs[nwKeyWords.CHAR_KEY]))
|
||||
@@ -774,7 +771,6 @@ class GuiOutlineDetails(QScrollArea):
|
||||
|
||||
self.theOutline = theOutline
|
||||
self.mainGui = theOutline.mainGui
|
||||
self.theProject = theOutline.mainGui.theProject
|
||||
|
||||
# Sizes
|
||||
minTitle = 30*CONFIG.theme.textNWidth
|
||||
@@ -1009,8 +1005,8 @@ class GuiOutlineDetails(QScrollArea):
|
||||
"""Update the content of the tree with the given handle and line
|
||||
number pointing to a header.
|
||||
"""
|
||||
pIndex = self.theProject.index
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
pIndex = self.mainGui.project.index
|
||||
nwItem = self.mainGui.project.tree[tHandle]
|
||||
novIdx = pIndex.getItemHeader(tHandle, sTitle)
|
||||
theRefs = pIndex.getReferences(tHandle, sTitle)
|
||||
if nwItem is None or novIdx is None:
|
||||
@@ -1053,7 +1049,7 @@ class GuiOutlineDetails(QScrollArea):
|
||||
def updateClasses(self):
|
||||
"""Update the visibility status of class details.
|
||||
"""
|
||||
usedClasses = self.theProject.tree.rootClasses()
|
||||
usedClasses = self.mainGui.project.tree.rootClasses()
|
||||
|
||||
pltVisible = nwItemClass.PLOT in usedClasses
|
||||
timVisible = nwItemClass.TIMELINE in usedClasses
|
||||
|
||||
+60
-62
@@ -233,10 +233,9 @@ class GuiProjectToolBar(QWidget):
|
||||
|
||||
logger.debug("Create: GuiProjectToolBar")
|
||||
|
||||
self.projView = projView
|
||||
self.projTree = projView.projTree
|
||||
self.mainGui = projView.mainGui
|
||||
self.theProject = projView.mainGui.theProject
|
||||
self.projView = projView
|
||||
self.projTree = projView.projTree
|
||||
self.mainGui = projView.mainGui
|
||||
|
||||
iPx = CONFIG.theme.baseIconSize
|
||||
mPx = CONFIG.pxInt(2)
|
||||
@@ -394,7 +393,7 @@ class GuiProjectToolBar(QWidget):
|
||||
"""Build the quick link menu."""
|
||||
logger.debug("Rebuilding quick links menu")
|
||||
self.mQuick.clear()
|
||||
for n, (tHandle, nwItem) in enumerate(self.theProject.tree.iterRoots(None)):
|
||||
for n, (tHandle, nwItem) in enumerate(self.mainGui.project.tree.iterRoots(None)):
|
||||
aRoot = self.mQuick.addAction(nwItem.itemName)
|
||||
aRoot.setData(tHandle)
|
||||
aRoot.setIcon(CONFIG.theme.getIcon(nwLabels.CLASS_ICON[nwItem.itemClass]))
|
||||
@@ -440,7 +439,7 @@ class GuiProjectToolBar(QWidget):
|
||||
documents. They should only be visible if novel documents can
|
||||
actually be added.
|
||||
"""
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = self.mainGui.project.tree[tHandle]
|
||||
allowDoc = isinstance(nwItem, NWItem) and nwItem.documentAllowed()
|
||||
self.aAddEmpty.setVisible(allowDoc)
|
||||
self.aAddChap.setVisible(allowDoc)
|
||||
@@ -466,9 +465,8 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
logger.debug("Create: GuiProjectTree")
|
||||
|
||||
self.projView = projView
|
||||
self.mainGui = projView.mainGui
|
||||
self.theProject = projView.mainGui.theProject
|
||||
self.projView = projView
|
||||
self.mainGui = projView.mainGui
|
||||
|
||||
# Internal Variables
|
||||
self._treeMap = {}
|
||||
@@ -575,15 +573,15 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass):
|
||||
|
||||
tHandle = self.theProject.newRoot(itemClass)
|
||||
tHandle = self.mainGui.project.newRoot(itemClass)
|
||||
sHandle = self.getSelectedHandle()
|
||||
pItem = self.theProject.tree[sHandle] if sHandle else None
|
||||
pItem = self.mainGui.project.tree[sHandle] if sHandle else None
|
||||
nHandle = pItem.itemRoot if pItem else None
|
||||
|
||||
elif itemType in (nwItemType.FILE, nwItemType.FOLDER):
|
||||
|
||||
sHandle = self.getSelectedHandle()
|
||||
pItem = self.theProject.tree[sHandle] if sHandle else None
|
||||
pItem = self.mainGui.project.tree[sHandle] if sHandle else None
|
||||
if sHandle is None or pItem is None:
|
||||
self.mainGui.makeAlert(self.tr(
|
||||
"Did not find anywhere to add the file or folder!"
|
||||
@@ -595,7 +593,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0)
|
||||
sIsParent = False if qItem is None else qItem.childCount() > 0
|
||||
|
||||
if self.theProject.tree.isTrash(sHandle):
|
||||
if self.mainGui.project.tree.isTrash(sHandle):
|
||||
self.mainGui.makeAlert(self.tr(
|
||||
"Cannot add new files or folders to the Trash folder."
|
||||
), level=nwAlert.ERROR)
|
||||
@@ -638,9 +636,9 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
# Add the file or folder
|
||||
if itemType == nwItemType.FILE:
|
||||
tHandle = self.theProject.newFile(newLabel, sHandle)
|
||||
tHandle = self.mainGui.project.newFile(newLabel, sHandle)
|
||||
else:
|
||||
tHandle = self.theProject.newFolder(newLabel, sHandle)
|
||||
tHandle = self.mainGui.project.newFolder(newLabel, sHandle)
|
||||
|
||||
else:
|
||||
logger.error("Failed to add new item")
|
||||
@@ -653,7 +651,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
# Handle new file creation
|
||||
if itemType == nwItemType.FILE and hLevel > 0:
|
||||
self.theProject.writeNewFile(tHandle, hLevel, not isNote)
|
||||
self.mainGui.project.writeNewFile(tHandle, hLevel, not isNote)
|
||||
|
||||
# Add the new item to the project tree
|
||||
self.revealNewTreeItem(tHandle, nHandle=nHandle, wordCount=True)
|
||||
@@ -664,7 +662,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
def revealNewTreeItem(self, tHandle: str | None, nHandle: str | None = None,
|
||||
wordCount: bool = False) -> bool:
|
||||
"""Reveal a newly added project item in the project tree."""
|
||||
nwItem = self.theProject.tree[tHandle] if tHandle else None
|
||||
nwItem = self.mainGui.project.tree[tHandle] if tHandle else None
|
||||
if tHandle is None or nwItem is None:
|
||||
return False
|
||||
|
||||
@@ -673,7 +671,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
return False
|
||||
|
||||
if nwItem.isFileType() and wordCount:
|
||||
wC = self.theProject.index.getCounts(tHandle)[1]
|
||||
wC = self.mainGui.project.index.getCounts(tHandle)[1]
|
||||
self.propagateCount(tHandle, wC)
|
||||
self.projView.wordCountsChanged.emit()
|
||||
|
||||
@@ -748,7 +746,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
def renameTreeItem(self, tHandle: str) -> bool:
|
||||
"""Open a dialog to edit the label of an item."""
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is None:
|
||||
return False
|
||||
|
||||
@@ -772,7 +770,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
if isinstance(item, QTreeWidgetItem):
|
||||
theList = self._scanChildren(theList, item, i)
|
||||
logger.debug("Saving project tree item order")
|
||||
self.theProject.setTreeOrder(theList)
|
||||
self.mainGui.project.setTreeOrder(theList)
|
||||
return
|
||||
|
||||
def getTreeFromHandle(self, tHandle: str) -> list[str]:
|
||||
@@ -805,16 +803,16 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.error("There is no item to delete")
|
||||
return False
|
||||
|
||||
trashHandle = self.theProject.tree.trashRoot()
|
||||
trashHandle = self.mainGui.project.tree.trashRoot()
|
||||
if tHandle == trashHandle:
|
||||
logger.error("Cannot delete the Trash folder")
|
||||
return False
|
||||
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = self.mainGui.project.tree[tHandle]
|
||||
if nwItem is None:
|
||||
return False
|
||||
|
||||
if self.theProject.tree.isTrash(tHandle) or nwItem.isRootType():
|
||||
if self.mainGui.project.tree.isTrash(tHandle) or nwItem.isRootType():
|
||||
status = self.permDeleteItem(tHandle)
|
||||
else:
|
||||
status = self.moveItemToTrash(tHandle)
|
||||
@@ -830,7 +828,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.error("No project open")
|
||||
return False
|
||||
|
||||
trashHandle = self.theProject.tree.trashRoot()
|
||||
trashHandle = self.mainGui.project.tree.trashRoot()
|
||||
|
||||
logger.debug("Emptying Trash folder")
|
||||
if trashHandle is None:
|
||||
@@ -873,13 +871,13 @@ class GuiProjectTree(QTreeWidget):
|
||||
so such a request is cancelled.
|
||||
"""
|
||||
trItemS = self._getTreeItem(tHandle)
|
||||
nwItemS = self.theProject.tree[tHandle]
|
||||
nwItemS = self.mainGui.project.tree[tHandle]
|
||||
|
||||
if trItemS is None or nwItemS is None:
|
||||
logger.error("Could not find tree item for deletion")
|
||||
return False
|
||||
|
||||
if self.theProject.tree.isTrash(tHandle):
|
||||
if self.mainGui.project.tree.isTrash(tHandle):
|
||||
logger.error("Item is already in the Trash folder")
|
||||
return False
|
||||
|
||||
@@ -923,7 +921,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
Root items are handled a little different than other items.
|
||||
"""
|
||||
trItemS = self._getTreeItem(tHandle)
|
||||
nwItemS = self.theProject.tree[tHandle]
|
||||
nwItemS = self.mainGui.project.tree[tHandle]
|
||||
if trItemS is None or nwItemS is None:
|
||||
logger.error("Could not find tree item for deletion")
|
||||
return False
|
||||
@@ -940,7 +938,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
tIndex = self.indexOfTopLevelItem(trItemS)
|
||||
self.takeTopLevelItem(tIndex)
|
||||
self.theProject.removeItem(tHandle)
|
||||
self.mainGui.project.removeItem(tHandle)
|
||||
self._treeMap.pop(tHandle, None)
|
||||
self._alertTreeChange(tHandle, flush=True)
|
||||
|
||||
@@ -969,7 +967,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
for dHandle in reversed(self.getTreeFromHandle(tHandle)):
|
||||
if self.mainGui.docEditor.docHandle() == dHandle:
|
||||
self.mainGui.closeDocument()
|
||||
self.theProject.removeItem(dHandle)
|
||||
self.mainGui.project.removeItem(dHandle)
|
||||
self._treeMap.pop(dHandle, None)
|
||||
|
||||
self._alertTreeChange(tHandle, flush=flush)
|
||||
@@ -987,7 +985,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
already coming from the project tree.
|
||||
"""
|
||||
trItem = self._getTreeItem(tHandle)
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = self.mainGui.project.tree[tHandle]
|
||||
if trItem is None or nwItem is None:
|
||||
return
|
||||
|
||||
@@ -1049,10 +1047,10 @@ class GuiProjectTree(QTreeWidget):
|
||||
pHandle = pItem.data(self.C_DATA, self.D_HANDLE)
|
||||
|
||||
if pHandle:
|
||||
if self.theProject.tree.checkType(pHandle, nwItemType.FILE):
|
||||
if self.mainGui.project.tree.checkType(pHandle, nwItemType.FILE):
|
||||
# A file has an internal word count we need to account
|
||||
# for, but a folder always has 0 words on its own.
|
||||
pCount += self.theProject.index.getCounts(pHandle)[1]
|
||||
pCount += self.mainGui.project.index.getCounts(pHandle)[1]
|
||||
|
||||
self.propagateCount(pHandle, pCount, countChildren=False)
|
||||
|
||||
@@ -1067,7 +1065,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.debug("Building the project tree ...")
|
||||
self.clearTree()
|
||||
count = 0
|
||||
for nwItem in self.theProject.getProjectItems():
|
||||
for nwItem in self.mainGui.project.getProjectItems():
|
||||
count += 1
|
||||
self._addTreeItem(nwItem)
|
||||
if count > 0:
|
||||
@@ -1180,7 +1178,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
if tHandle is None:
|
||||
return
|
||||
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is None:
|
||||
return
|
||||
|
||||
@@ -1202,7 +1200,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
selItem = self.itemAt(clickPos)
|
||||
if isinstance(selItem, QTreeWidgetItem):
|
||||
tHandle = selItem.data(self.C_DATA, self.D_HANDLE)
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
hasChild = selItem.childCount() > 0
|
||||
|
||||
if tItem is None or tHandle is None:
|
||||
@@ -1214,7 +1212,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
# Trash Folder
|
||||
# ============
|
||||
|
||||
trashHandle = self.theProject.tree.trashRoot()
|
||||
trashHandle = self.mainGui.project.tree.trashRoot()
|
||||
if tItem.itemHandle == trashHandle and trashHandle is not None:
|
||||
# The trash folder only has one option
|
||||
aEmptyTrash = ctxMenu.addAction(self.tr("Empty Trash"))
|
||||
@@ -1253,7 +1251,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
checkMark = f" ({nwUnicode.U_CHECK})"
|
||||
if tItem.isNovelLike():
|
||||
mStatus = ctxMenu.addMenu(self.tr("Set Status to ..."))
|
||||
for n, (key, entry) in enumerate(self.theProject.data.itemStatus.items()):
|
||||
for n, (key, entry) in enumerate(self.mainGui.project.data.itemStatus.items()):
|
||||
entryName = entry["name"] + (checkMark if tItem.itemStatus == key else "")
|
||||
aStatus = mStatus.addAction(entry["icon"], entryName)
|
||||
aStatus.triggered.connect(
|
||||
@@ -1266,7 +1264,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
)
|
||||
else:
|
||||
mImport = ctxMenu.addMenu(self.tr("Set Importance to ..."))
|
||||
for n, (key, entry) in enumerate(self.theProject.data.itemImport.items()):
|
||||
for n, (key, entry) in enumerate(self.mainGui.project.data.itemImport.items()):
|
||||
entryName = entry["name"] + (checkMark if tItem.itemImport == key else "")
|
||||
aImport = mImport.addAction(entry["icon"], entryName)
|
||||
aImport.triggered.connect(
|
||||
@@ -1378,7 +1376,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
return
|
||||
|
||||
tHandle = selItem.data(self.C_DATA, self.D_HANDLE)
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is None:
|
||||
return
|
||||
|
||||
@@ -1422,7 +1420,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
def _postItemMove(self, tHandle: str, wCount: int) -> bool:
|
||||
"""Run various maintenance tasks for a moved item."""
|
||||
trItemS = self._getTreeItem(tHandle)
|
||||
nwItemS = self.theProject.tree[tHandle]
|
||||
nwItemS = self.mainGui.project.tree[tHandle]
|
||||
trItemP = trItemS.parent() if trItemS else None
|
||||
if trItemP is None or nwItemS is None:
|
||||
logger.error("Failed to find new parent item of '%s'", tHandle)
|
||||
@@ -1439,13 +1437,13 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.debug("A total of %d item(s) were moved", len(mHandles))
|
||||
for mHandle in mHandles:
|
||||
logger.debug("Updating item '%s'", mHandle)
|
||||
self.theProject.tree.updateItemData(mHandle)
|
||||
self.mainGui.project.tree.updateItemData(mHandle)
|
||||
|
||||
# Update the index
|
||||
if nwItemS.isInactiveClass():
|
||||
self.theProject.index.deleteHandle(mHandle)
|
||||
self.mainGui.project.index.deleteHandle(mHandle)
|
||||
else:
|
||||
self.theProject.index.reIndexHandle(mHandle)
|
||||
self.mainGui.project.index.reIndexHandle(mHandle)
|
||||
|
||||
self.setTreeItemValues(mHandle)
|
||||
|
||||
@@ -1465,7 +1463,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
def _toggleItemActive(self, tHandle: str) -> None:
|
||||
"""Toggle the active status of an item."""
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is not None:
|
||||
tItem.setActive(not tItem.isActive)
|
||||
self.setTreeItemValues(tItem.itemHandle)
|
||||
@@ -1486,7 +1484,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
def _changeItemStatus(self, tHandle: str, tStatus: str) -> None:
|
||||
"""Set a new status value of an item."""
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is not None:
|
||||
tItem.setStatus(tStatus)
|
||||
self.setTreeItemValues(tItem.itemHandle)
|
||||
@@ -1495,7 +1493,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
def _changeItemImport(self, tHandle: str, tImport: str) -> None:
|
||||
"""Set a new importance value of an item."""
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is not None:
|
||||
tItem.setImport(tImport)
|
||||
self.setTreeItemValues(tItem.itemHandle)
|
||||
@@ -1504,7 +1502,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
def _changeItemLayout(self, tHandle: str, itemLayout: nwItemLayout) -> None:
|
||||
"""Set a new item layout value of an item."""
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is not None:
|
||||
if itemLayout == nwItemLayout.DOCUMENT and tItem.documentAllowed():
|
||||
tItem.setLayout(nwItemLayout.DOCUMENT)
|
||||
@@ -1518,7 +1516,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
def _covertFolderToFile(self, tHandle: str, itemLayout: nwItemLayout) -> None:
|
||||
"""Convert a folder to a note or document."""
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is not None and tItem.isFolderType():
|
||||
msgYes = self.mainGui.askQuestion(self.tr(
|
||||
"Do you want to convert the folder to a {0}? "
|
||||
@@ -1543,7 +1541,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.info("Request to merge items under handle '%s'", tHandle)
|
||||
itemList = self.getTreeFromHandle(tHandle)
|
||||
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is None:
|
||||
return False
|
||||
|
||||
@@ -1569,7 +1567,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
self.mainGui.saveDocument()
|
||||
|
||||
# Create merge object, and append docs
|
||||
docMerger = DocMerger(self.theProject)
|
||||
docMerger = DocMerger(self.mainGui.project)
|
||||
mLabel = self.tr("Merged")
|
||||
|
||||
if newFile:
|
||||
@@ -1591,7 +1589,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
)
|
||||
return False
|
||||
|
||||
self.theProject.index.reIndexHandle(mHandle)
|
||||
self.mainGui.project.index.reIndexHandle(mHandle)
|
||||
if newFile:
|
||||
self.revealNewTreeItem(mHandle, nHandle=tHandle, wordCount=True)
|
||||
|
||||
@@ -1616,7 +1614,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
"""Split a document into multiple documents."""
|
||||
logger.info("Request to split items with handle '%s'", tHandle)
|
||||
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem is None:
|
||||
return False
|
||||
|
||||
@@ -1635,7 +1633,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
intoFolder = splitData.get("intoFolder", False)
|
||||
docHierarchy = splitData.get("docHierarchy", False)
|
||||
|
||||
docSplit = DocSplitter(self.theProject, tHandle)
|
||||
docSplit = DocSplitter(self.mainGui.project, tHandle)
|
||||
if intoFolder:
|
||||
fHandle = docSplit.newParentFolder(tItem.itemParent, tItem.itemName)
|
||||
self.revealNewTreeItem(fHandle, nHandle=tHandle)
|
||||
@@ -1645,7 +1643,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
|
||||
docSplit.splitDocument(headerList, splitText)
|
||||
for writeOk, dHandle, nHandle in docSplit.writeDocuments(docHierarchy):
|
||||
self.theProject.index.reIndexHandle(dHandle)
|
||||
self.mainGui.project.index.reIndexHandle(dHandle)
|
||||
self.revealNewTreeItem(dHandle, nHandle=nHandle, wordCount=True)
|
||||
self._alertTreeChange(dHandle, flush=False)
|
||||
if not writeOk:
|
||||
@@ -1679,10 +1677,10 @@ class GuiProjectTree(QTreeWidget):
|
||||
if not self.mainGui.askQuestion(question):
|
||||
return False
|
||||
|
||||
docDup = DocDuplicator(self.theProject)
|
||||
docDup = DocDuplicator(self.mainGui.project)
|
||||
dupCount = 0
|
||||
for dHandle, nHandle in docDup.duplicate(itemTree):
|
||||
self.theProject.index.reIndexHandle(dHandle)
|
||||
self.mainGui.project.index.reIndexHandle(dHandle)
|
||||
self.revealNewTreeItem(dHandle, nHandle=nHandle, wordCount=True)
|
||||
self._alertTreeChange(dHandle, flush=False)
|
||||
dupCount += 1
|
||||
@@ -1702,7 +1700,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
cCount = tItem.childCount()
|
||||
|
||||
# Update tree-related meta data
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem = self.mainGui.project.tree[tHandle]
|
||||
if nwItem is not None:
|
||||
nwItem.setExpanded(tItem.isExpanded() and cCount > 0)
|
||||
nwItem.setOrder(tIndex)
|
||||
@@ -1769,13 +1767,13 @@ class GuiProjectTree(QTreeWidget):
|
||||
"""Adds the trash root folder if it doesn't already exist in the
|
||||
project tree.
|
||||
"""
|
||||
trashHandle = self.theProject.trashFolder()
|
||||
trashHandle = self.mainGui.project.trashFolder()
|
||||
if trashHandle is None:
|
||||
return None
|
||||
|
||||
trItem = self._getTreeItem(trashHandle)
|
||||
if trItem is None:
|
||||
trItem = self._addTreeItem(self.theProject.tree[trashHandle])
|
||||
trItem = self._addTreeItem(self.mainGui.project.tree[trashHandle])
|
||||
if trItem is not None:
|
||||
trItem.setExpanded(True)
|
||||
self._alertTreeChange(trashHandle, flush=True)
|
||||
@@ -1788,14 +1786,14 @@ class GuiProjectTree(QTreeWidget):
|
||||
deleted.
|
||||
"""
|
||||
self._timeChanged = time()
|
||||
self.theProject.setProjectChanged(True)
|
||||
self.mainGui.project.setProjectChanged(True)
|
||||
if flush:
|
||||
self.saveTreeOrder()
|
||||
|
||||
if tHandle is None or tHandle not in self.theProject.tree:
|
||||
if tHandle is None or tHandle not in self.mainGui.project.tree:
|
||||
return
|
||||
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
tItem = self.mainGui.project.tree[tHandle]
|
||||
if tItem and tItem.isRootType():
|
||||
self.projView.rootFolderChanged.emit(tHandle)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user