From 9258d49bc8984fc61f7e10005a86985eaa6ac78a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 5 Jun 2020 19:17:00 +0200 Subject: [PATCH 1/2] Some minor fixes and improvements to the OptionState class --- nw/core/project.py | 64 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/nw/core/project.py b/nw/core/project.py index 213426d86..b163cbd17 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -2015,10 +2015,43 @@ def __init__(self, theProject): self.mainConf = nw.CONFIG self.theProject = theProject - self.theState = {} - self.stringOpt = () - self.boolOpt = () - self.intOpt = () + + self.theState = {} + self.validMap = { + "GuiSession": set([ + "widthCol0", + "widthCol1", + "widthCol2", + "sortCol", + "sortOrder", + "hideZeros", + "hideNegative", + ]), + "GuiDocSplit": set([ + "spLevel", + ]), + "GuiBuildNovel": set([ + "winWidth", + "winHeight", + "addNovel", + "addNotes", + "ignoreFlag", + "justifyText", + "excludeBody", + "textFont", + "textSize", + "noStyling", + "incSynopsis", + "incComments", + "incKeywords", + "incBodyText", + ]), + "GuiOutline": set([ + "headerOrder", + "columnWidth", + "columnHidden", + ]) + } return @@ -2045,8 +2078,14 @@ def loadSettings(self): logger.error("Failed to load GUI options file") logger.error(str(e)) return False - for anOpt in theState: - self.theState[anOpt] = theState[anOpt] + + # Filter out unused variables + for aGroup in theState: + if aGroup in self.validMap: + self.theState[aGroup] = {} + for anOpt in theState[aGroup]: + if anOpt in self.validMap[aGroup]: + self.theState[aGroup][anOpt] = theState[aGroup][anOpt] return True @@ -2076,9 +2115,19 @@ def saveSettings(self): def setValue(self, setGroup, setName, setValue): """Saves a value, with a given group and name. """ + if not setGroup in self.validMap: + logger.error("Unknown option group '%s'" % setGroup) + return False + + if not setName in self.validMap[setGroup]: + logger.error("Unknown option name '%s'" % setName) + return False + if not setGroup in self.theState: self.theState[setGroup] = {} + self.theState[setGroup][setName] = setValue + return True ## @@ -2106,7 +2155,8 @@ def getString(self, getGroup, getName, defaultValue): if getName in self.theState[getGroup]: try: return str(self.theState[getGroup][getName]) - except: + except Exception as e: + logger.warning(str(e)) return defaultValue return defaultValue From 213889e9d5a7ab40eddd8ef6490e93e82f9133e3 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 5 Jun 2020 19:46:51 +0200 Subject: [PATCH 2/2] Added open and view document to the project tree context menu --- nw/gui/mainmenu.py | 4 ++-- nw/gui/projtree.py | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index fc170377c..7cd20565d 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -233,14 +233,14 @@ def _buildProjectMenu(self): self.projMenu.addSeparator() # Project > Edit - self.aEditItem = QAction("&Edit Item", self) + self.aEditItem = QAction("&Edit Project Item", self) self.aEditItem.setStatusTip("Change item settings") self.aEditItem.setShortcuts(["Ctrl+E", "F2"]) self.aEditItem.triggered.connect(self.theParent.editItem) self.projMenu.addAction(self.aEditItem) # Project > Delete - self.aDeleteItem = QAction("&Delete Item", self) + self.aDeleteItem = QAction("&Delete Project Item", self) self.aDeleteItem.setStatusTip("Delete selected item") self.aDeleteItem.setShortcut("Ctrl+Del") self.aDeleteItem.triggered.connect(lambda : self.theParent.treeView.deleteItem(None)) diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 5bef07bf0..66ba46394 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -836,7 +836,15 @@ def __init__(self, theTree): self.theTree = theTree self.theItem = None - self.editItem = QAction("Edit Item", self) + self.openItem = QAction("Open Document", self) + self.openItem.triggered.connect(self._doOpenItem) + self.addAction(self.openItem) + + self.viewItem = QAction("View Document", self) + self.viewItem.triggered.connect(self._doViewItem) + self.addAction(self.viewItem) + + self.editItem = QAction("Edit Project Item", self) self.editItem.triggered.connect(self._doEditItem) self.addAction(self.editItem) @@ -876,6 +884,8 @@ def filterActions(self, theItem): isFile = theItem.itemType == nwItemType.FILE isOrph = isFile and theItem.parHandle is None + showOpen = isFile + showView = isFile showEdit = not isTrash and not isOrph showExport = isFile and not inTrash and not isOrph showNewFile = not isTrash and not inTrash and not isOrph @@ -883,6 +893,8 @@ def filterActions(self, theItem): showDelete = not isTrash showEmpty = isTrash + self.openItem.setVisible(showOpen) + self.viewItem.setVisible(showView) self.editItem.setVisible(showEdit) self.toggleExp.setVisible(showExport) self.newFile.setVisible(showNewFile) @@ -896,6 +908,20 @@ def filterActions(self, theItem): # Slots ## + def _doOpenItem(self): + """Forward the open document call to the main GUI window. + """ + if self.theItem is not None: + self.theTree.theParent.openDocument(self.theItem.itemHandle) + return + + def _doViewItem(self): + """Forward the view document call to the main GUI window. + """ + if self.theItem is not None: + self.theTree.theParent.viewDocument(self.theItem.itemHandle) + return + def _doEditItem(self): """Forward the edit item call to the main GUI window. """