Also make tree and options properties of the project
This commit is contained in:
@@ -2701,15 +2701,15 @@ class GuiDocEditHeader(QWidget):
|
||||
|
||||
if self.mainConf.showFullPath:
|
||||
tTitle = []
|
||||
tTree = self.theProject.projTree.getItemPath(tHandle)
|
||||
tTree = self.theProject.tree.getItemPath(tHandle)
|
||||
for aHandle in reversed(tTree):
|
||||
nwItem = self.theProject.projTree[aHandle]
|
||||
nwItem = self.theProject.tree[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.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
if nwItem is None:
|
||||
return False
|
||||
self.theTitle.setText(nwItem.itemName)
|
||||
@@ -2795,7 +2795,6 @@ class GuiDocEditFooter(QWidget):
|
||||
self.theParent = docEditor.theParent
|
||||
self.theProject = docEditor.theProject
|
||||
self.theTheme = docEditor.theTheme
|
||||
self.optState = docEditor.theProject.optState
|
||||
|
||||
self._theItem = None
|
||||
self._docHandle = None
|
||||
@@ -2918,7 +2917,7 @@ class GuiDocEditFooter(QWidget):
|
||||
logger.verbose("No handle set, so clearing the editor footer")
|
||||
self._theItem = None
|
||||
else:
|
||||
self._theItem = self.theProject.projTree[self._docHandle]
|
||||
self._theItem = self.theProject.tree[self._docHandle]
|
||||
|
||||
self.setHasSelection(False)
|
||||
self.updateInfo()
|
||||
|
||||
@@ -288,7 +288,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
if theText.startswith("@"): # Keywords and commands
|
||||
self.setCurrentBlockState(self.BLOCK_META)
|
||||
pIndex = self.theProject.index
|
||||
tItem = self.theParent.theProject.projTree[self.theHandle]
|
||||
tItem = self.theParent.theProject.tree[self.theHandle]
|
||||
isValid, theBits, thePos = pIndex.scanThis(theText)
|
||||
isGood = pIndex.checkThese(theBits, tItem)
|
||||
if isValid:
|
||||
|
||||
@@ -160,7 +160,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
def loadText(self, tHandle, updateHistory=True):
|
||||
"""Load text into the viewer from an item handle.
|
||||
"""
|
||||
if not self.theProject.projTree.checkType(tHandle, nwItemType.FILE):
|
||||
if not self.theProject.tree.checkType(tHandle, nwItemType.FILE):
|
||||
logger.warning("Item not found")
|
||||
return False
|
||||
|
||||
@@ -863,15 +863,15 @@ class GuiDocViewHeader(QWidget):
|
||||
|
||||
if self.mainConf.showFullPath:
|
||||
tTitle = []
|
||||
tTree = self.theProject.projTree.getItemPath(tHandle)
|
||||
tTree = self.theProject.tree.getItemPath(tHandle)
|
||||
for aHandle in reversed(tTree):
|
||||
nwItem = self.theProject.projTree[aHandle]
|
||||
nwItem = self.theProject.tree[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.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
if nwItem is None:
|
||||
return False
|
||||
self.theTitle.setText(nwItem.itemName)
|
||||
@@ -1202,7 +1202,7 @@ class GuiDocViewDetails(QScrollArea):
|
||||
theRefs = self.theProject.index.getBackReferenceList(tHandle)
|
||||
theList = []
|
||||
for tHandle in theRefs:
|
||||
tItem = self.theProject.projTree[tHandle]
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
if tItem is not None:
|
||||
theList.append("<a href='%s#%s' %s>%s</a>" % (
|
||||
tHandle, theRefs[tHandle], self.linkStyle, tItem.itemName
|
||||
|
||||
@@ -227,7 +227,7 @@ class GuiItemDetails(QWidget):
|
||||
self.clearDetails()
|
||||
return
|
||||
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
if nwItem is None:
|
||||
self.clearDetails()
|
||||
return
|
||||
|
||||
@@ -91,7 +91,6 @@ class GuiOutline(QTreeWidget):
|
||||
self.theParent = theParent
|
||||
self.theProject = theParent.theProject
|
||||
self.theTheme = theParent.theTheme
|
||||
self.optState = theParent.theProject.optState
|
||||
self.headerMenu = GuiOutlineHeaderMenu(self)
|
||||
|
||||
self.setFrameStyle(QFrame.NoFrame)
|
||||
@@ -273,10 +272,12 @@ class GuiOutline(QTreeWidget):
|
||||
"""Load the state of the main tree header, that is, column order
|
||||
and column width.
|
||||
"""
|
||||
pOptions = self.theProject.options
|
||||
|
||||
# Load whatever we saved last time, regardless of wether it
|
||||
# contains the correct names or number of columns. The names
|
||||
# must be valid though.
|
||||
tempOrder = self.optState.getValue("GuiOutline", "headerOrder", [])
|
||||
tempOrder = pOptions.getValue("GuiOutline", "headerOrder", [])
|
||||
treeOrder = []
|
||||
for hName in tempOrder:
|
||||
try:
|
||||
@@ -299,14 +300,14 @@ class GuiOutline(QTreeWidget):
|
||||
|
||||
# We load whatever column widths and hidden states we find in
|
||||
# the file, and leave the rest in their default state.
|
||||
tmpWidth = self.optState.getValue("GuiOutline", "columnWidth", {})
|
||||
tmpWidth = pOptions.getValue("GuiOutline", "columnWidth", {})
|
||||
for hName in tmpWidth:
|
||||
try:
|
||||
self._colWidth[nwOutline[hName]] = self.mainConf.pxInt(tmpWidth[hName])
|
||||
except Exception:
|
||||
logger.warning("Ignored unknown outline column '%s'", str(hName))
|
||||
|
||||
tmpHidden = self.optState.getValue("GuiOutline", "columnHidden", {})
|
||||
tmpHidden = pOptions.getValue("GuiOutline", "columnHidden", {})
|
||||
for hName in tmpHidden:
|
||||
try:
|
||||
self._colHidden[nwOutline[hName]] = tmpHidden[hName]
|
||||
@@ -347,10 +348,11 @@ class GuiOutline(QTreeWidget):
|
||||
if not logHidden and logWidth > 0:
|
||||
colWidth[hName] = logWidth
|
||||
|
||||
self.optState.setValue("GuiOutline", "headerOrder", treeOrder)
|
||||
self.optState.setValue("GuiOutline", "columnWidth", colWidth)
|
||||
self.optState.setValue("GuiOutline", "columnHidden", colHidden)
|
||||
self.optState.saveSettings()
|
||||
pOptions = self.theProject.options
|
||||
pOptions.setValue("GuiOutline", "headerOrder", treeOrder)
|
||||
pOptions.setValue("GuiOutline", "columnWidth", colWidth)
|
||||
pOptions.setValue("GuiOutline", "columnHidden", colHidden)
|
||||
pOptions.saveSettings()
|
||||
|
||||
return
|
||||
|
||||
@@ -437,7 +439,7 @@ class GuiOutline(QTreeWidget):
|
||||
def _createTreeItem(self, tHandle, sTitle, novIdx):
|
||||
"""Populate a tree item with all the column values.
|
||||
"""
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
newItem = QTreeWidgetItem()
|
||||
hIcon = "doc_%s" % novIdx["level"].lower()
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ class GuiOutlineDetails(QScrollArea):
|
||||
self.theParent = theParent
|
||||
self.theProject = theParent.theProject
|
||||
self.theTheme = theParent.theTheme
|
||||
self.optState = theParent.theProject.optState
|
||||
|
||||
# Sizes
|
||||
minTitle = 30*self.theTheme.textNWidth
|
||||
@@ -283,7 +282,7 @@ class GuiOutlineDetails(QScrollArea):
|
||||
number pointing to a header.
|
||||
"""
|
||||
pIndex = self.theProject.index
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
novIdx = pIndex.getNovelData(tHandle, sTitle)
|
||||
theRefs = pIndex.getReferences(tHandle, sTitle)
|
||||
if nwItem is None or novIdx is None:
|
||||
|
||||
+22
-22
@@ -180,14 +180,14 @@ class GuiProjectTree(QTreeWidget):
|
||||
elif itemType in (nwItemType.FILE, nwItemType.FOLDER):
|
||||
|
||||
sHandle = self.getSelectedHandle()
|
||||
if sHandle is None or sHandle not in self.theProject.projTree:
|
||||
if sHandle is None or sHandle not in self.theProject.tree:
|
||||
self.theParent.makeAlert(self.tr(
|
||||
"Did not find anywhere to add the file or folder!"
|
||||
), nwAlert.ERROR)
|
||||
return False
|
||||
|
||||
# If the selected item is a file, the new item will be a sibling
|
||||
pItem = self.theProject.projTree[sHandle]
|
||||
pItem = self.theProject.tree[sHandle]
|
||||
if pItem.itemType == nwItemType.FILE:
|
||||
nHandle = sHandle
|
||||
sHandle = pItem.itemParent
|
||||
@@ -195,7 +195,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.error("Internal error") # Bug
|
||||
return False
|
||||
|
||||
if self.theProject.projTree.isTrash(sHandle):
|
||||
if self.theProject.tree.isTrash(sHandle):
|
||||
self.theParent.makeAlert(self.tr(
|
||||
"Cannot add new files or folders to the Trash folder."
|
||||
), nwAlert.ERROR)
|
||||
@@ -221,7 +221,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
# Add the new item to the tree
|
||||
self.revealNewTreeItem(tHandle, nHandle)
|
||||
self.theParent.editItem(tHandle)
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
|
||||
# If this is a folder, return here
|
||||
if nwItem.itemType != nwItemType.FILE:
|
||||
@@ -254,7 +254,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
def revealNewTreeItem(self, tHandle, nHandle=None):
|
||||
"""Reveal a newly added project item in the project tree.
|
||||
"""
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
if nwItem is None:
|
||||
return False
|
||||
|
||||
@@ -375,7 +375,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.error("No project open")
|
||||
return False
|
||||
|
||||
trashHandle = self.theProject.projTree.trashRoot()
|
||||
trashHandle = self.theProject.tree.trashRoot()
|
||||
|
||||
logger.debug("Emptying Trash folder")
|
||||
if trashHandle is None:
|
||||
@@ -436,7 +436,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
return False
|
||||
|
||||
trItemS = self._getTreeItem(tHandle)
|
||||
nwItemS = self.theProject.projTree[tHandle]
|
||||
nwItemS = self.theProject.tree[tHandle]
|
||||
|
||||
if trItemS is None or nwItemS is None:
|
||||
logger.error("Could not find tree item for deletion")
|
||||
@@ -477,7 +477,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
logger.error("Could not delete item")
|
||||
return False
|
||||
|
||||
if self.theProject.projTree.isTrash(tHandle):
|
||||
if self.theProject.tree.isTrash(tHandle):
|
||||
# If the file is in the trash folder already, as the
|
||||
# user if they want to permanently delete the file.
|
||||
doPermanent = False
|
||||
@@ -531,7 +531,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
already coming from the project tree.
|
||||
"""
|
||||
trItem = self._getTreeItem(tHandle)
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
if trItem is None or nwItem is None:
|
||||
return
|
||||
|
||||
@@ -596,7 +596,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
pHandle = pItem.data(self.C_NAME, Qt.UserRole)
|
||||
|
||||
if pHandle:
|
||||
if self.theProject.projTree.checkType(pHandle, nwItemType.FILE):
|
||||
if self.theProject.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]
|
||||
@@ -711,7 +711,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
if isinstance(selItem, QTreeWidgetItem):
|
||||
tHandle = selItem.data(self.C_NAME, Qt.UserRole)
|
||||
self.setSelectedHandle(tHandle) # Just to be safe
|
||||
tItem = self.theProject.projTree[tHandle]
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
if tItem is not None:
|
||||
if self.ctxMenu.filterActions(tItem):
|
||||
# Only open menu if any actions remain after filter
|
||||
@@ -749,7 +749,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
return
|
||||
|
||||
tHandle = selItem.data(self.C_NAME, Qt.UserRole)
|
||||
tItem = self.theProject.projTree[tHandle]
|
||||
tItem = self.theProject.tree[tHandle]
|
||||
if tItem is None:
|
||||
return
|
||||
|
||||
@@ -797,7 +797,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
"""Run various maintenance tasks for a moved item.
|
||||
"""
|
||||
trItemS = self._getTreeItem(tHandle)
|
||||
nwItemS = self.theProject.projTree[tHandle]
|
||||
nwItemS = self.theProject.tree[tHandle]
|
||||
trItemP = trItemS.parent()
|
||||
if trItemP is None:
|
||||
logger.error("Failed to find new parent item of '%s'", tHandle)
|
||||
@@ -814,7 +814,7 @@ 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.projTree.updateItemData(mHandle)
|
||||
self.theProject.tree.updateItemData(mHandle)
|
||||
|
||||
# Update the index
|
||||
if nwItemS.isInactive():
|
||||
@@ -847,7 +847,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
def _deleteTreeItem(self, tHandle):
|
||||
"""Permanently delete a tree item from the project and the map.
|
||||
"""
|
||||
if self.theProject.projTree.checkType(tHandle, nwItemType.FILE):
|
||||
if self.theProject.tree.checkType(tHandle, nwItemType.FILE):
|
||||
delDoc = NWDoc(self.theProject, tHandle)
|
||||
if not delDoc.deleteDocument():
|
||||
self.theParent.makeAlert([
|
||||
@@ -856,7 +856,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
return False
|
||||
|
||||
self.theProject.index.deleteHandle(tHandle)
|
||||
del self.theProject.projTree[tHandle]
|
||||
del self.theProject.tree[tHandle]
|
||||
self._treeMap.pop(tHandle, None)
|
||||
|
||||
return True
|
||||
@@ -869,7 +869,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
cCount = tItem.childCount()
|
||||
|
||||
# Update tree-related meta data
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
nwItem.setExpanded(tItem.isExpanded() and cCount > 0)
|
||||
nwItem.setOrder(tIndex)
|
||||
|
||||
@@ -943,7 +943,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
trItem = self._getTreeItem(trashHandle)
|
||||
if trItem is None:
|
||||
trItem = self._addTreeItem(
|
||||
self.theProject.projTree[trashHandle]
|
||||
self.theProject.tree[trashHandle]
|
||||
)
|
||||
if trItem is not None:
|
||||
trItem.setExpanded(True)
|
||||
@@ -963,8 +963,8 @@ class GuiProjectTree(QTreeWidget):
|
||||
def _emitItemChange(self, tHandle):
|
||||
"""Emit an item change signal for a given handle.
|
||||
"""
|
||||
if self.theProject.projTree.checkType(tHandle, nwItemType.FILE):
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
if self.theProject.tree.checkType(tHandle, nwItemType.FILE):
|
||||
nwItem = self.theProject.tree[tHandle]
|
||||
if nwItem.isNovelLike():
|
||||
self.novelItemChanged.emit()
|
||||
else:
|
||||
@@ -1047,9 +1047,9 @@ class GuiProjectTreeMenu(QMenu):
|
||||
logger.error("Failed to extract information to build tree context menu")
|
||||
return False
|
||||
|
||||
trashHandle = self.theTree.theProject.projTree.trashRoot()
|
||||
trashHandle = self.theTree.theProject.tree.trashRoot()
|
||||
|
||||
inTrash = self.theTree.theProject.projTree.isTrash(theItem.itemHandle)
|
||||
inTrash = self.theTree.theProject.tree.isTrash(theItem.itemHandle)
|
||||
isTrash = theItem.itemHandle == trashHandle and trashHandle is not None
|
||||
isFile = theItem.itemType == nwItemType.FILE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user