Folders can now be deleted as well, and depth and haschildren flags removed from item meta data.
This commit is contained in:
+41
-14
@@ -81,12 +81,9 @@ class GuiDocTree(QTreeWidget):
|
||||
##
|
||||
|
||||
def clearTree(self):
|
||||
|
||||
self.clear()
|
||||
|
||||
self.theMap = {}
|
||||
self.orphRoot = None
|
||||
|
||||
return
|
||||
|
||||
def newTreeItem(self, itemType, itemClass):
|
||||
@@ -185,12 +182,21 @@ class GuiDocTree(QTreeWidget):
|
||||
]
|
||||
return retVals
|
||||
|
||||
def deleteItem(self):
|
||||
tHandle = self.getSelectedHandle()
|
||||
def deleteItem(self, tHandle=None):
|
||||
"""Delete items from the tree. Note that this does not delete the item from the item tree in
|
||||
the project object. However, since this is only meta data, there isn't really a need to do
|
||||
that to save memory. As items not in the tree are not saved to the project file, a loaded
|
||||
project will be clean anyway.
|
||||
"""
|
||||
|
||||
if tHandle is None:
|
||||
tHandle = self.getSelectedHandle()
|
||||
|
||||
trItemS = self._getTreeItem(tHandle)
|
||||
nwItemS = self.theProject.getItem(tHandle)
|
||||
|
||||
if nwItemS.itemType == nwItemType.FILE:
|
||||
logger.debug("User requested item %s moved to trash" % tHandle)
|
||||
logger.debug("User requested file %s moved to trash" % tHandle)
|
||||
trItemP = trItemS.parent()
|
||||
trItemT = self._addTrashRoot()
|
||||
if trItemP is None or trItemT is None:
|
||||
@@ -200,6 +206,33 @@ class GuiDocTree(QTreeWidget):
|
||||
trItemC = trItemP.takeChild(tIndex)
|
||||
trItemT.addChild(trItemC)
|
||||
nwItemS.setParent(self.theProject.trashRoot)
|
||||
self.clearSelection()
|
||||
trItemP.setSelected(True)
|
||||
|
||||
elif nwItemS.itemType == nwItemType.FOLDER:
|
||||
logger.debug("User requested folder %s deleted" % tHandle)
|
||||
trItemP = trItemS.parent()
|
||||
if trItemP is None:
|
||||
logger.error("Could not delete folder")
|
||||
return
|
||||
tIndex = trItemP.indexOfChild(trItemS)
|
||||
if trItemS.childCount() == 0:
|
||||
trItemP.takeChild(tIndex)
|
||||
self.clearSelection()
|
||||
trItemP.setSelected(True)
|
||||
else:
|
||||
self.theParent.makeAlert(["Cannot delete folder.","It is not empty."],2)
|
||||
return
|
||||
|
||||
elif nwItemS.itemType == nwItemType.ROOT:
|
||||
logger.debug("User requested root folder %s deleted" % tHandle)
|
||||
tIndex = self.indexOfTopLevelItem(trItemS)
|
||||
if trItemS.childCount() == 0:
|
||||
self.takeTopLevelItem(tIndex)
|
||||
self.theParent.mainMenu.setAvailableRoot()
|
||||
else:
|
||||
self.theParent.makeAlert(["Cannot delete root folder.","It is not empty."],2)
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
@@ -233,7 +266,7 @@ class GuiDocTree(QTreeWidget):
|
||||
for i in range(pItem.childCount()):
|
||||
pCount += int(pItem.child(i).text(self.C_COUNT))
|
||||
pHandle = pItem.text(self.C_HANDLE)
|
||||
if not nDepth > NWItem.MAX_DEPTH and pHandle != "":
|
||||
if not nDepth > 200 and pHandle != "":
|
||||
self.propagateCount(pHandle, pCount, nDepth+1)
|
||||
return
|
||||
|
||||
@@ -271,11 +304,6 @@ class GuiDocTree(QTreeWidget):
|
||||
self._scanChildren(theList, theItem.child(i), i)
|
||||
return theList
|
||||
|
||||
def _scanParents(self, theItem, theCount=0):
|
||||
if theItem.parent() is not None:
|
||||
theItem, theCount = self._scanParents(theItem.parent(), theCount)
|
||||
return theItem, theCount+1
|
||||
|
||||
def _addTreeItem(self, nwItem):
|
||||
|
||||
tHandle = nwItem.itemHandle
|
||||
@@ -341,7 +369,7 @@ class GuiDocTree(QTreeWidget):
|
||||
self.orphRoot = newItem
|
||||
newItem.setExpanded(True)
|
||||
return
|
||||
|
||||
|
||||
def _cleanOrphanedRoot(self):
|
||||
if self.orphRoot.childCount() == 0:
|
||||
self.takeTopLevelItem(self.indexOfTopLevelItem(self.orphRoot))
|
||||
@@ -371,7 +399,6 @@ class GuiDocTree(QTreeWidget):
|
||||
return
|
||||
pHandle = trItemP.text(self.C_HANDLE)
|
||||
nwItemS.setParent(pHandle)
|
||||
nwItemS.setDepth(self.theProject.countItemDepth(tHandle))
|
||||
self.setTreeItemValues(tHandle)
|
||||
return
|
||||
|
||||
|
||||
+1
-1
@@ -187,7 +187,7 @@ class GuiMainMenu(QMenuBar):
|
||||
menuItem = QAction(QIcon.fromTheme("edit-delete"), "&Delete Item", self)
|
||||
menuItem.setStatusTip("Delete Selected Item")
|
||||
menuItem.setShortcut("Ctrl+Del")
|
||||
menuItem.triggered.connect(self.theParent.treeView.deleteItem)
|
||||
menuItem.triggered.connect(lambda : self.theParent.treeView.deleteItem(None))
|
||||
self.projMenu.addAction(menuItem)
|
||||
|
||||
# Project > Separator
|
||||
|
||||
+6
-16
@@ -35,7 +35,6 @@ class NWItem():
|
||||
self.itemClass = nwItemClass.NO_CLASS
|
||||
self.itemLayout = nwItemLayout.NO_LAYOUT
|
||||
self.itemStatus = 0
|
||||
self.itemDepth = None
|
||||
self.isExpanded = False
|
||||
|
||||
self.charCount = 0
|
||||
@@ -54,12 +53,11 @@ class NWItem():
|
||||
"parent" : str(self.parHandle),
|
||||
"order" : str(self.itemOrder),
|
||||
})
|
||||
xSub = self._subPack(xPack,"name", text=str(self.itemName))
|
||||
xSub = self._subPack(xPack,"type", text=str(self.itemType.name))
|
||||
xSub = self._subPack(xPack,"class", text=str(self.itemClass.name))
|
||||
xSub = self._subPack(xPack,"status", text=str(self.itemStatus))
|
||||
xSub = self._subPack(xPack,"depth", text=str(self.itemDepth))
|
||||
xSub = self._subPack(xPack,"expanded", text=str(self.isExpanded))
|
||||
xSub = self._subPack(xPack,"name", text=str(self.itemName))
|
||||
xSub = self._subPack(xPack,"type", text=str(self.itemType.name))
|
||||
xSub = self._subPack(xPack,"class", text=str(self.itemClass.name))
|
||||
xSub = self._subPack(xPack,"status", text=str(self.itemStatus))
|
||||
xSub = self._subPack(xPack,"expanded", text=str(self.isExpanded))
|
||||
if self.itemType == nwItemType.FILE:
|
||||
xSub = self._subPack(xPack,"layout", text=str(self.itemLayout.name))
|
||||
xSub = self._subPack(xPack,"charCount", text=str(self.charCount), none=False)
|
||||
@@ -87,7 +85,7 @@ class NWItem():
|
||||
elif tagName == "class": self.setClass(tagValue)
|
||||
elif tagName == "layout": self.setLayout(tagValue)
|
||||
elif tagName == "status": self.setStatus(tagValue)
|
||||
elif tagName == "depth": self.setDepth(tagValue)
|
||||
elif tagName == "children": self.setChildren(tagValue)
|
||||
elif tagName == "expanded": self.setExpanded(tagValue)
|
||||
elif tagName == "charCount": self.setCharCount(tagValue)
|
||||
elif tagName == "wordCount": self.setWordCount(tagValue)
|
||||
@@ -160,14 +158,6 @@ class NWItem():
|
||||
self.itemStatus = theStatus
|
||||
return
|
||||
|
||||
def setDepth(self, theDepth):
|
||||
theDepth = self._checkInt(theDepth,-1)
|
||||
if theDepth >= 0 and theDepth <= self.MAX_DEPTH:
|
||||
self.itemDepth = theDepth
|
||||
else:
|
||||
logger.error("Invalid item depth %d" % theDepth)
|
||||
return
|
||||
|
||||
def setExpanded(self, expState):
|
||||
if isinstance(expState, str):
|
||||
self.isExpanded = expState == str(True)
|
||||
|
||||
+2
-17
@@ -102,6 +102,7 @@ class NWProject():
|
||||
|
||||
hNovel = self.newRoot("Novel", nwItemClass.NOVEL)
|
||||
hChars = self.newRoot("Characters", nwItemClass.CHARACTER)
|
||||
hWorld = self.newRoot("Plot", nwItemClass.PLOT)
|
||||
hWorld = self.newRoot("World", nwItemClass.WORLD)
|
||||
hChapt = self.newFolder("New Chapter", nwItemClass.NOVEL, hNovel)
|
||||
hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt)
|
||||
@@ -234,7 +235,7 @@ class NWProject():
|
||||
|
||||
# Save Tree Content
|
||||
logger.debug("Writing project content")
|
||||
xContent = etree.SubElement(nwXML,"content",attrib={"count":str(len(self.projTree))})
|
||||
xContent = etree.SubElement(nwXML,"content",attrib={"count":str(len(self.treeOrder))})
|
||||
for tHandle in self.treeOrder:
|
||||
self.projTree[tHandle].packXML(xContent)
|
||||
|
||||
@@ -373,16 +374,6 @@ class NWProject():
|
||||
|
||||
return
|
||||
|
||||
def countItemDepth(self, tHandle):
|
||||
theDepth = 0
|
||||
nwItem = self.getItem(tHandle)
|
||||
while nwItem.parHandle is not None:
|
||||
theDepth += 1
|
||||
nwItem = self.getItem(nwItem.parHandle)
|
||||
if theDepth > NWItem.MAX_DEPTH:
|
||||
return None
|
||||
return theDepth
|
||||
|
||||
def _appendItem(self, tHandle, pHandle, nwItem):
|
||||
tHandle = self._checkString(tHandle,self._makeHandle(),False)
|
||||
pHandle = self._checkString(pHandle,None,True)
|
||||
@@ -405,12 +396,6 @@ class NWProject():
|
||||
else:
|
||||
logger.error("Only one trash folder allowed")
|
||||
|
||||
itemDepth = self.countItemDepth(tHandle)
|
||||
if itemDepth is None:
|
||||
logger.error("The depth of entry %s could not be determined" % tHandle)
|
||||
else:
|
||||
nwItem.setDepth(itemDepth)
|
||||
|
||||
return
|
||||
|
||||
def _makeStatusIcons(self):
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# Very Deep File
|
||||
@@ -1,19 +1,17 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2019-05-04 11:53:50">
|
||||
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2019-05-04 17:22:40">
|
||||
<project>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
<author>Jane Smith</author>
|
||||
<author>Jay Doh</author>
|
||||
</project>
|
||||
<content count="12">
|
||||
<content count="14">
|
||||
<item handle="7031beac91f75" order="0" parent="None">
|
||||
<name>Novel</name>
|
||||
<type>ROOT</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<depth>0</depth>
|
||||
<children>True</children>
|
||||
<expanded>True</expanded>
|
||||
</item>
|
||||
<item handle="53b69b83cdafc" order="0" parent="7031beac91f75">
|
||||
@@ -21,8 +19,6 @@
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
<status>2</status>
|
||||
<depth>1</depth>
|
||||
<children>False</children>
|
||||
<expanded>False</expanded>
|
||||
<layout>TITLE</layout>
|
||||
<charCount>23</charCount>
|
||||
@@ -34,8 +30,6 @@
|
||||
<type>FOLDER</type>
|
||||
<class>NOVEL</class>
|
||||
<status>1</status>
|
||||
<depth>1</depth>
|
||||
<children>True</children>
|
||||
<expanded>True</expanded>
|
||||
</item>
|
||||
<item handle="96b68994dfa3d" order="0" parent="e7ded148d6e4a">
|
||||
@@ -43,8 +37,6 @@
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
<status>2</status>
|
||||
<depth>2</depth>
|
||||
<children>False</children>
|
||||
<expanded>False</expanded>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>2571</charCount>
|
||||
@@ -56,8 +48,6 @@
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
<status>1</status>
|
||||
<depth>2</depth>
|
||||
<children>False</children>
|
||||
<expanded>False</expanded>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>376</charCount>
|
||||
@@ -69,8 +59,6 @@
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<depth>2</depth>
|
||||
<children>False</children>
|
||||
<expanded>False</expanded>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>0</charCount>
|
||||
@@ -82,8 +70,6 @@
|
||||
<type>ROOT</type>
|
||||
<class>CHARACTER</class>
|
||||
<status>0</status>
|
||||
<depth>0</depth>
|
||||
<children>True</children>
|
||||
<expanded>True</expanded>
|
||||
</item>
|
||||
<item handle="f7e2d9f330615" order="0" parent="f6622b4617424">
|
||||
@@ -91,8 +77,6 @@
|
||||
<type>FOLDER</type>
|
||||
<class>CHARACTER</class>
|
||||
<status>0</status>
|
||||
<depth>1</depth>
|
||||
<children>True</children>
|
||||
<expanded>True</expanded>
|
||||
</item>
|
||||
<item handle="14298de4d9524" order="0" parent="f7e2d9f330615">
|
||||
@@ -100,8 +84,6 @@
|
||||
<type>FILE</type>
|
||||
<class>CHARACTER</class>
|
||||
<status>0</status>
|
||||
<depth>2</depth>
|
||||
<children>False</children>
|
||||
<expanded>False</expanded>
|
||||
<layout>NOTE</layout>
|
||||
<charCount>42</charCount>
|
||||
@@ -113,8 +95,6 @@
|
||||
<type>FILE</type>
|
||||
<class>CHARACTER</class>
|
||||
<status>0</status>
|
||||
<depth>2</depth>
|
||||
<children>False</children>
|
||||
<expanded>False</expanded>
|
||||
<layout>NOTE</layout>
|
||||
<charCount>51</charCount>
|
||||
@@ -126,8 +106,6 @@
|
||||
<type>ROOT</type>
|
||||
<class>WORLD</class>
|
||||
<status>0</status>
|
||||
<depth>0</depth>
|
||||
<children>True</children>
|
||||
<expanded>True</expanded>
|
||||
</item>
|
||||
<item handle="b3e74dbc1f584" order="0" parent="73eee34351f85">
|
||||
@@ -135,13 +113,29 @@
|
||||
<type>FILE</type>
|
||||
<class>WORLD</class>
|
||||
<status>0</status>
|
||||
<depth>1</depth>
|
||||
<children>False</children>
|
||||
<expanded>False</expanded>
|
||||
<layout>NOTE</layout>
|
||||
<charCount>66</charCount>
|
||||
<wordCount>13</wordCount>
|
||||
<paraCount>1</paraCount>
|
||||
</item>
|
||||
<item handle="f75dac270c2a7" order="3" parent="None">
|
||||
<name>Trash</name>
|
||||
<type>TRASH</type>
|
||||
<class>TRASH</class>
|
||||
<status>0</status>
|
||||
<expanded>True</expanded>
|
||||
</item>
|
||||
<item handle="4cd0bd12b087d" order="0" parent="f75dac270c2a7">
|
||||
<name>New File</name>
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
<status>0</status>
|
||||
<expanded>False</expanded>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>3</charCount>
|
||||
<wordCount>1</wordCount>
|
||||
<paraCount>0</paraCount>
|
||||
</item>
|
||||
</content>
|
||||
</novelWriterXML>
|
||||
|
||||
Reference in New Issue
Block a user