+9
-9
@@ -38,15 +38,15 @@ class nwItemClass(Enum):
|
|||||||
|
|
||||||
class nwItemLayout(Enum):
|
class nwItemLayout(Enum):
|
||||||
|
|
||||||
NO_LAYOUT = 0
|
NO_LAYOUT = 0
|
||||||
TITLE = 1
|
TITLE = 1
|
||||||
BOOK = 2
|
BOOK = 2
|
||||||
PAGE = 3
|
PAGE = 3
|
||||||
PARTITION = 4
|
PARTITION = 4
|
||||||
UNNUMBERED = 5
|
UNNUMBERED = 5
|
||||||
CHAPTER = 6
|
CHAPTER = 6
|
||||||
SCENE = 7
|
SCENE = 7
|
||||||
NOTE = 8
|
NOTE = 8
|
||||||
|
|
||||||
# END Enum nwItemLayout
|
# END Enum nwItemLayout
|
||||||
|
|
||||||
|
|||||||
+2
-6
@@ -92,11 +92,8 @@ class GuiDocTree(QTreeWidget):
|
|||||||
def newTreeItem(self, itemType, itemClass):
|
def newTreeItem(self, itemType, itemClass):
|
||||||
|
|
||||||
pHandle = self.getSelectedHandle()
|
pHandle = self.getSelectedHandle()
|
||||||
if pHandle is None:
|
|
||||||
self.makeAlert("No valid parent item selected", nwAlert.ERROR)
|
|
||||||
return False
|
|
||||||
|
|
||||||
if itemClass is None:
|
if itemClass is None and pHandle is not None:
|
||||||
itemClass = self.theProject.getItem(pHandle).itemClass
|
itemClass = self.theProject.getItem(pHandle).itemClass
|
||||||
if itemClass is None:
|
if itemClass is None:
|
||||||
self.makeAlert("Failed to find an appropriate item class for item %s" % pHandle, nwAlert.BUG)
|
self.makeAlert("Failed to find an appropriate item class for item %s" % pHandle, nwAlert.BUG)
|
||||||
@@ -296,8 +293,7 @@ class GuiDocTree(QTreeWidget):
|
|||||||
|
|
||||||
def buildTree(self):
|
def buildTree(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
for tHandle in self.theProject.treeOrder:
|
for nwItem in self.theProject.getProjectItems():
|
||||||
nwItem = self.theProject.projTree[tHandle]
|
|
||||||
self._addTreeItem(nwItem)
|
self._addTreeItem(nwItem)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -368,6 +368,47 @@ class NWProject():
|
|||||||
logger.error("No tree item with handle %s" % str(tHandle))
|
logger.error("No tree item with handle %s" % str(tHandle))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getProjectItems(self):
|
||||||
|
"""This function is called from the tree view when building the tree. Each item in the
|
||||||
|
project is returned in the order saved in the project file, but first it checks that it has
|
||||||
|
a parent item already sent to the tree.
|
||||||
|
"""
|
||||||
|
sentItems = []
|
||||||
|
iterItems = self.treeOrder.copy()
|
||||||
|
n = 0
|
||||||
|
nMax = len(iterItems)
|
||||||
|
while n < nMax:
|
||||||
|
tHandle = iterItems[n]
|
||||||
|
tItem = self.getItem(tHandle)
|
||||||
|
n += 1
|
||||||
|
if n > 10000:
|
||||||
|
return # Just in case
|
||||||
|
if tItem is None:
|
||||||
|
# Technically a bug since treeOrder is built from the same data as projTree
|
||||||
|
continue
|
||||||
|
elif tItem.parHandle is None:
|
||||||
|
# Item is a root, or already been identified as an orphaned item
|
||||||
|
sentItems.append(tHandle)
|
||||||
|
yield tItem
|
||||||
|
elif tItem.parHandle in sentItems:
|
||||||
|
# Item's parent has been sent, so all is fine
|
||||||
|
sentItems.append(tHandle)
|
||||||
|
yield tItem
|
||||||
|
elif tItem.parHandle in iterItems:
|
||||||
|
# Item's parent exists, but hasn't been sent yet, so add it again to the end
|
||||||
|
logger.warning("Item %s found before its parent" % tHandle)
|
||||||
|
iterItems.append(tHandle)
|
||||||
|
nMax = len(iterItems)
|
||||||
|
else:
|
||||||
|
# Item is orphaned
|
||||||
|
logger.error("Item %s has no parent in current tree" % tHandle)
|
||||||
|
tItem.setParent(None)
|
||||||
|
yield tItem
|
||||||
|
|
||||||
|
##
|
||||||
|
# Class Methods
|
||||||
|
##
|
||||||
|
|
||||||
def findRootItem(self, theClass):
|
def findRootItem(self, theClass):
|
||||||
for aRoot in self.treeRoots:
|
for aRoot in self.treeRoots:
|
||||||
if theClass == self.projTree[aRoot].itemClass:
|
if theClass == self.projTree[aRoot].itemClass:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<novelWriterXML appVersion="0.1.3" fileVersion="1.0" timeStamp="2019-05-18 20:51:40">
|
<novelWriterXML appVersion="0.1.3" fileVersion="1.0" timeStamp="2019-05-19 14:27:22">
|
||||||
<project>
|
<project>
|
||||||
<name>Sample Project</name>
|
<name>Sample Project</name>
|
||||||
<title>Sample Project</title>
|
<title>Sample Project</title>
|
||||||
@@ -8,10 +8,10 @@
|
|||||||
</project>
|
</project>
|
||||||
<settings>
|
<settings>
|
||||||
<spellCheck>True</spellCheck>
|
<spellCheck>True</spellCheck>
|
||||||
<lastEdited>636b6aa9b697b</lastEdited>
|
<lastEdited>4cd0bd12b087d</lastEdited>
|
||||||
<lastViewed>636b6aa9b697b</lastViewed>
|
<lastViewed>636b6aa9b697b</lastViewed>
|
||||||
</settings>
|
</settings>
|
||||||
<content count="15">
|
<content count="14">
|
||||||
<item handle="7031beac91f75" order="0" parent="None">
|
<item handle="7031beac91f75" order="0" parent="None">
|
||||||
<name>Novel</name>
|
<name>Novel</name>
|
||||||
<type>ROOT</type>
|
<type>ROOT</type>
|
||||||
@@ -112,55 +112,43 @@
|
|||||||
<paraCount>1</paraCount>
|
<paraCount>1</paraCount>
|
||||||
<cursorPos>0</cursorPos>
|
<cursorPos>0</cursorPos>
|
||||||
</item>
|
</item>
|
||||||
<item handle="73eee34351f85" order="2" parent="None">
|
<item handle="15c4492bd5107" order="2" parent="None">
|
||||||
<name>Locations</name>
|
<name>Locations</name>
|
||||||
<type>ROOT</type>
|
<type>ROOT</type>
|
||||||
<class>WORLD</class>
|
<class>WORLD</class>
|
||||||
<status>0</status>
|
<status>0</status>
|
||||||
<expanded>True</expanded>
|
<expanded>True</expanded>
|
||||||
</item>
|
</item>
|
||||||
<item handle="b3e74dbc1f584" order="0" parent="73eee34351f85">
|
<item handle="b3e74dbc1f584" order="0" parent="15c4492bd5107">
|
||||||
<name>Earth</name>
|
<name>Earth</name>
|
||||||
<type>FILE</type>
|
<type>FILE</type>
|
||||||
<class>WORLD</class>
|
<class>WORLD</class>
|
||||||
<status>0</status>
|
<status>0</status>
|
||||||
<expanded>False</expanded>
|
<expanded>False</expanded>
|
||||||
<layout>NOTE</layout>
|
<layout>NOTE</layout>
|
||||||
<charCount>66</charCount>
|
<charCount>0</charCount>
|
||||||
<wordCount>13</wordCount>
|
<wordCount>0</wordCount>
|
||||||
<paraCount>1</paraCount>
|
<paraCount>0</paraCount>
|
||||||
<cursorPos>0</cursorPos>
|
<cursorPos>0</cursorPos>
|
||||||
</item>
|
</item>
|
||||||
<item handle="f75dac270c2a7" order="3" parent="None">
|
<item handle="98acd8c76c93a" order="3" parent="None">
|
||||||
<name>Trash</name>
|
<name>Trash</name>
|
||||||
<type>TRASH</type>
|
<type>TRASH</type>
|
||||||
<class>TRASH</class>
|
<class>TRASH</class>
|
||||||
<status>0</status>
|
<status>0</status>
|
||||||
<expanded>True</expanded>
|
<expanded>True</expanded>
|
||||||
</item>
|
</item>
|
||||||
<item handle="4cd0bd12b087d" order="0" parent="f75dac270c2a7">
|
<item handle="4cd0bd12b087d" order="0" parent="98acd8c76c93a">
|
||||||
<name>Orphaned File 1</name>
|
<name>Orphaned File 2</name>
|
||||||
<type>FILE</type>
|
<type>FILE</type>
|
||||||
<class>NO_CLASS</class>
|
<class>NO_CLASS</class>
|
||||||
<status>0</status>
|
<status>0</status>
|
||||||
<expanded>False</expanded>
|
<expanded>False</expanded>
|
||||||
<layout>NO_LAYOUT</layout>
|
<layout>NO_LAYOUT</layout>
|
||||||
<charCount>0</charCount>
|
<charCount>14</charCount>
|
||||||
<wordCount>0</wordCount>
|
<wordCount>3</wordCount>
|
||||||
<paraCount>0</paraCount>
|
<paraCount>0</paraCount>
|
||||||
<cursorPos>0</cursorPos>
|
<cursorPos>1</cursorPos>
|
||||||
</item>
|
|
||||||
<item handle="879437bde105e" order="1" parent="f75dac270c2a7">
|
|
||||||
<name>New File</name>
|
|
||||||
<type>FILE</type>
|
|
||||||
<class>CHARACTER</class>
|
|
||||||
<status>0</status>
|
|
||||||
<expanded>False</expanded>
|
|
||||||
<layout>NOTE</layout>
|
|
||||||
<charCount>0</charCount>
|
|
||||||
<wordCount>0</wordCount>
|
|
||||||
<paraCount>0</paraCount>
|
|
||||||
<cursorPos>0</cursorPos>
|
|
||||||
</item>
|
</item>
|
||||||
</content>
|
</content>
|
||||||
</novelWriterXML>
|
</novelWriterXML>
|
||||||
|
|||||||
Reference in New Issue
Block a user