From 5e90b1ff77497bb59fc89565f2315de9c6543eb3 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 14 Apr 2020 22:20:40 +0200 Subject: [PATCH 1/3] Clear the outline header between projects --- nw/gui/elements/outline.py | 15 ++++++++++----- nw/guimain.py | 1 + nw/tools/optionstate.py | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/nw/gui/elements/outline.py b/nw/gui/elements/outline.py index 7d5ab4a5..51b6817f 100644 --- a/nw/gui/elements/outline.py +++ b/nw/gui/elements/outline.py @@ -97,24 +97,29 @@ class GuiProjectOutline(QTreeWidget): self.colIndex = {} self.treeNCols = 0 - self.initOutline() + self.clearOutline() self.headerMenu.setHiddenState(self.colHidden) logger.debug("ProjectOutline initialisation complete") return - def initOutline(self): - """Set the default values for the Outline tree. + def clearOutline(self): + """Clear the tree and header and set the default values for the + columns arrays. """ + self.clear() + self.setColumnCount(1) + self.setHeaderLabel(nwLabels.OUTLINE_COLS[nwOutline.TITLE]) + self.treeOrder = [] self.colWidth = {} self.colHidden = {} self.colIndex = {} self.treeNCols = 0 - for hItem in nwOutline: + for i, hItem in enumerate(nwOutline): self.treeOrder.append(hItem) self.colWidth[hItem] = self.DEF_WIDTH[hItem] self.colHidden[hItem] = self.DEF_HIDDEN[hItem] @@ -153,7 +158,7 @@ class GuiProjectOutline(QTreeWidget): """Called before a project is closed. """ self._saveHeaderState() - self.clear() + self.clearOutline() self.firstView = True return diff --git a/nw/guimain.py b/nw/guimain.py index cb1331bc..43dea7fb 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -315,6 +315,7 @@ class GuiMain(QMainWindow): self.theIndex.clearIndex() self.clearGUI() self.hasProject = False + self.tabWidget.setCurrentWidget(self.splitView) return saveOK diff --git a/nw/tools/optionstate.py b/nw/tools/optionstate.py index 881ff4e5..2f0fa554 100644 --- a/nw/tools/optionstate.py +++ b/nw/tools/optionstate.py @@ -38,6 +38,9 @@ class OptionState(): """Load the options dictionary from the project settings file. """ + if self.theProject.projMeta is None: + return False + stateFile = path.join(self.theProject.projMeta, nwFiles.OPTS_FILE) theState = {} @@ -60,6 +63,9 @@ class OptionState(): """Save the options dictionary to the project settings file. """ + if self.theProject.projMeta is None: + return False + stateFile = path.join(self.theProject.projMeta, nwFiles.OPTS_FILE) logger.debug("Saving GUI options file") From 4abec49b0aa569df4bdd238f4dfd09578acc7ff7 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 14 Apr 2020 22:49:25 +0200 Subject: [PATCH 2/3] The opren recent project dialog now remembers column width and projects can be opened with double click --- nw/config.py | 10 ++++++++++ nw/gui/dialogs/projectload.py | 23 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/nw/config.py b/nw/config.py index 94c30f71..0e5e01b2 100644 --- a/nw/config.py +++ b/nw/config.py @@ -73,6 +73,7 @@ class Config: ## Sizes self.winGeometry = [1100, 650] self.treeColWidth = [120, 30, 50] + self.projColWidth = [140, 55, 140] self.mainPanePos = [300, 800] self.docPanePos = [400, 400] self.isFullScreen = False @@ -295,6 +296,9 @@ class Config: self.treeColWidth = self._parseLine( cnfParse, cnfSec, "treecols", self.CNF_LIST, self.treeColWidth ) + self.projColWidth = self._parseLine( + cnfParse, cnfSec, "projcols", self.CNF_LIST, self.projColWidth + ) self.mainPanePos = self._parseLine( cnfParse, cnfSec, "mainpane", self.CNF_LIST, self.mainPanePos ) @@ -432,6 +436,7 @@ class Config: cnfParse.add_section(cnfSec) cnfParse.set(cnfSec,"geometry", self._packList(self.winGeometry)) cnfParse.set(cnfSec,"treecols", self._packList(self.treeColWidth)) + cnfParse.set(cnfSec,"projcols", self._packList(self.projColWidth)) cnfParse.set(cnfSec,"mainpane", self._packList(self.mainPanePos)) cnfParse.set(cnfSec,"docpane", self._packList(self.docPanePos)) cnfParse.set(cnfSec,"fullscreen", str(self.isFullScreen)) @@ -619,6 +624,11 @@ class Config: self.confChanged = True return True + def setProjColWidths(self, colWidths): + self.projColWidth = colWidths + self.confChanged = True + return True + def setMainPanePos(self, panePos): self.mainPanePos = panePos self.confChanged = True diff --git a/nw/gui/dialogs/projectload.py b/nw/gui/dialogs/projectload.py index 3e773a9d..2ccfbb5a 100644 --- a/nw/gui/dialogs/projectload.py +++ b/nw/gui/dialogs/projectload.py @@ -54,11 +54,13 @@ class GuiProjectLoad(QDialog): self.listBox.setSelectionMode(QAbstractItemView.SingleSelection) self.listBox.setDragDropMode(QAbstractItemView.NoDragDrop) self.listBox.setColumnCount(4) - self.listBox.setHeaderLabels(["Working Title","Words","Accessed","Path"]) + self.listBox.setHeaderLabels(["Working Title","Words","Last Opened","Path"]) self.listBox.setRootIsDecorated(False) + self.listBox.itemDoubleClicked.connect(self._doOpenRecent) treeHead = self.listBox.headerItem() treeHead.setTextAlignment(1, Qt.AlignRight) + treeHead.setTextAlignment(2, Qt.AlignRight) self.recentButton = QPushButton("Open") self.recentButton.clicked.connect(self._doOpenRecent) @@ -95,7 +97,7 @@ class GuiProjectLoad(QDialog): """Close the dialog window with a recent project selected. """ logger.verbose("GuiProjectLoad open button clicked") - + self._saveDialogState() selItems = self.listBox.selectedItems() if selItems: self.openPath = selItems[0].text(3) @@ -110,6 +112,7 @@ class GuiProjectLoad(QDialog): project browser dialog. """ logger.verbose("GuiProjectLoad browse button clicked") + self._saveDialogState() self.openPath = None self.accept() return @@ -118,6 +121,7 @@ class GuiProjectLoad(QDialog): """Close the dialog window without doing anything. """ logger.verbose("GuiProjectLoad close button clicked") + self._saveDialogState() self.close() return @@ -125,6 +129,15 @@ class GuiProjectLoad(QDialog): # Internal Functions ## + def _saveDialogState(self): + """Save the changes made to the dialog. + """ + colWidths = [50]*3 + for i in range(3): + colWidths[i] = self.listBox.columnWidth(i) + self.mainConf.setProjColWidths(colWidths) + return + def _populateList(self): """Populate the list box with recent project data. """ @@ -155,14 +168,14 @@ class GuiProjectLoad(QDialog): newItem.setText(2, datetime.fromtimestamp(timeStamp).strftime("%x %X")) newItem.setText(3, listData[timeStamp][2]) newItem.setTextAlignment(1, Qt.AlignRight) + newItem.setTextAlignment(2, Qt.AlignRight) self.listBox.addTopLevelItem(newItem) if not hasSelection: newItem.setSelected(True) hasSelection = True - self.listBox.resizeColumnToContents(0) - self.listBox.resizeColumnToContents(1) - self.listBox.resizeColumnToContents(2) + for i in range(3): + self.listBox.setColumnWidth(i, self.mainConf.projColWidth[i]) return From b4a90f4b028898dc805919f5b945e8881f0c627b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 14 Apr 2020 22:49:40 +0200 Subject: [PATCH 3/3] Fixed tests --- tests/reference/novelwriter.conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/reference/novelwriter.conf b/tests/reference/novelwriter.conf index bac82e44..ad20b354 100644 --- a/tests/reference/novelwriter.conf +++ b/tests/reference/novelwriter.conf @@ -1,5 +1,5 @@ [Main] -timestamp = 2020-02-26 18:10:35 +timestamp = 2020-04-14 22:47:16 theme = default syntax = default_light guidark = False @@ -7,6 +7,7 @@ guidark = False [Sizes] geometry = 1100, 650 treecols = 120, 30, 50 +projcols = 140, 55, 140 mainpane = 300, 800 docpane = 400, 400 fullscreen = False