From e00b3b4c20c6db97273ec2e529d9bd644532cf57 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 28 Apr 2019 12:32:05 +0200 Subject: [PATCH] Connected the make root menu options. --- nw/gui/doctree.py | 3 ++- nw/gui/mainmenu.py | 14 ++++++++++++++ nw/project/item.py | 3 ++- nw/project/project.py | 12 ++++++------ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/nw/gui/doctree.py b/nw/gui/doctree.py index 42d05be2..9297285c 100644 --- a/nw/gui/doctree.py +++ b/nw/gui/doctree.py @@ -72,7 +72,7 @@ class GuiDocTree(QTreeWidget): itemClass = self.theProject.getItem(pHandle).itemClass logger.verbose("Adding new item of type %s and class %s to handle %s" % ( - itemType.name,itemClass.name,str(pHandle)) + itemType.name, itemClass.name, str(pHandle)) ) if itemType == nwItemType.ROOT: @@ -220,6 +220,7 @@ class GuiDocTree(QTreeWidget): if nwItem.itemType == nwItemType.ROOT: newItem.setIcon(self.C_NAME, QIcon.fromTheme("drive-harddisk")) + self.theParent.mainMenu.setAvailableRoot() elif nwItem.itemType == nwItemType.FOLDER: newItem.setIcon(self.C_NAME, QIcon.fromTheme("folder")) elif nwItem.itemType == nwItemType.FILE: diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 62877a91..c9379549 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -52,6 +52,14 @@ class GuiMainMenu(QMenuBar): self.theParent.openProject(self.mainConf.recentList[recentItem]) return True + def setAvailableRoot(self): + for itemClass in nwItemClass: + if itemClass != nwItemClass.NO_CLASS: + self.rootItems[itemClass].setEnabled( + self.theProject.checkRootUnique(itemClass) + ) + return + ## # Menu Action ## @@ -122,6 +130,12 @@ class GuiMainMenu(QMenuBar): self.rootItems[nwItemClass.TIMELINE] = QAction(QIcon.fromTheme("folder-new"), "Timeline Root", rootMenu) self.rootItems[nwItemClass.OBJECT] = QAction(QIcon.fromTheme("folder-new"), "Object Root", rootMenu) self.rootItems[nwItemClass.CUSTOM] = QAction(QIcon.fromTheme("folder-new"), "Custom Root", rootMenu) + nCount = 0 + for itemClass in self.rootItems.keys(): + nCount += 1 # This forces the lambdas to be unique + self.rootItems[itemClass].triggered.connect( + lambda nCount, itemClass=itemClass : self._newTreeItem(nwItemType.ROOT, itemClass) + ) rootMenu.addActions(self.rootItems.values()) # Project > New Folder diff --git a/nw/project/item.py b/nw/project/item.py index dfcfc97d..3d098e0e 100644 --- a/nw/project/item.py +++ b/nw/project/item.py @@ -35,13 +35,14 @@ class NWItem(): nwItemClass.CUSTOM : "Custom", } CLASS_FLAG = { - nwItemClass.NO_CLASS : "X", + nwItemClass.NO_CLASS : "0", nwItemClass.NOVEL : "N", nwItemClass.PLOT : "P", nwItemClass.CHARACTER : "C", nwItemClass.WORLD : "L", nwItemClass.TIMELINE : "T", nwItemClass.OBJECT : "O", + nwItemClass.CUSTOM : "X", } LAYOUT_NAME = { nwItemLayout.NO_LAYOUT : "None", diff --git a/nw/project/project.py b/nw/project/project.py index 37188075..beed9984 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -281,7 +281,7 @@ class NWProject(): if tHandle is None: validActions[nwItemAction.ADD_ROOT] = { "Type" : nwItemType.ROOT, - "Class" : [x for x in nwItemClass if self._checkRootUnique(x)] + "Class" : [x for x in nwItemClass if self.checkRootUnique(x)] } return validActions @@ -343,11 +343,7 @@ class NWProject(): return validActions - ## - # Internal Functions - ## - - def _checkRootUnique(self, theClass): + def checkRootUnique(self, theClass): """Checks if there already is a root entry of class 'theClass' in the root of the project tree. """ @@ -358,6 +354,10 @@ class NWProject(): return False return True + ## + # Internal Functions + ## + def _countItemDepth(self, tHandle): theDepth = 0 nwItem = self.getItem(tHandle)