Tree context menu can now add files, folders and roots.

This commit is contained in:
Veronica K. B. Olsen
2019-04-23 21:42:11 +02:00
parent 06d1d3c7cc
commit 30c1241488
6 changed files with 98 additions and 116 deletions
+16 -5
View File
@@ -23,7 +23,16 @@ logger = logging.getLogger(__name__)
class NWItem():
MAX_DEPTH = 8
MAX_DEPTH = 8
CLASS_NAME = {
nwItemClass.NO_CLASS : "Folder",
nwItemClass.NOVEL : "Novel",
nwItemClass.PLOT : "Plot",
nwItemClass.CHARACTER : "Characters",
nwItemClass.WORLD : "Locations",
nwItemClass.TIMELINE : "Timeline",
nwItemClass.OBJECT : "Objects",
}
def __init__(self):
@@ -31,8 +40,8 @@ class NWItem():
self.itemHandle = None
self.parHandle = None
self.itemOrder = None
self.itemType = nwItemType.NONE
self.itemClass = nwItemClass.NONE
self.itemType = nwItemType.NO_TYPE
self.itemClass = nwItemClass.NO_CLASS
self.itemDepth = None
self.hasChildren = False
self.isExpanded = False
@@ -116,25 +125,27 @@ class NWItem():
def setType(self, theType):
if isinstance(theType, nwItemType):
self.itemType = theType
return
else:
for itemType in nwItemType:
if theType == itemType.name:
self.itemType = itemType
return
logger.error("Unrecognised item type '%s'" % theType)
self.itemType = nwItemType.NONE
self.itemType = nwItemType.NO_TYPE
return
def setClass(self, theClass):
if isinstance(theClass, nwItemClass):
self.itemClass = theClass
return
else:
for itemClass in nwItemClass:
if theClass == itemClass.name:
self.itemClass = itemClass
return
logger.error("Unrecognised item class '%s'" % theClass)
self.itemClass = nwItemClass.NONE
self.itemClass = nwItemClass.NO_CLASS
return
def setDepth(self, theDepth):
+3 -1
View File
@@ -245,7 +245,7 @@ class NWProject():
"""
validActions = {}
# If we're at root, or didn't select an utem, all we can add is root stuff
# If we're at root, or didn't select an item, all we can add is root stuff
if tHandle is None:
validActions[nwItemAction.ADD_ROOT] = {
"Type" : nwItemType.ROOT,
@@ -318,6 +318,8 @@ class NWProject():
"""Checks if there already is a root entry of class 'theClass' in the
root of the project tree.
"""
if theClass == nwItemClass.NO_CLASS:
return True
for aRoot in self.treeRoots:
if theClass == self.projTree[aRoot].itemClass:
return False