diff --git a/novelwriter/config.py b/novelwriter/config.py index d651908d..f9cd6a08 100644 --- a/novelwriter/config.py +++ b/novelwriter/config.py @@ -344,7 +344,7 @@ class Config: self._outlnPanePos = [int(x/self.guiScale) for x in pos] return - def setLastPath(self, path: str | Path, key: str | None = None) -> None: + def setLastPath(self, key: str, path: str | Path) -> None: """Set the last used path. Only the folder is saved, so if the path is not a folder, the parent of the path is used instead. """ @@ -353,7 +353,7 @@ class Config: if not path.is_dir(): path = path.parent if path.is_dir(): - self._recentPaths.setPath(key or "default", path) + self._recentPaths.setPath(key, path) self._recentPaths.saveCache() return diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index d404794a..aa3d756d 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -523,12 +523,12 @@ class GuiOutlineTree(QTreeWidget): @pyqtSlot() def exportOutline(self) -> None: """Export the outline as a CSV file.""" - path = CONFIG.lastPath() / f"{makeFileNameSafe(SHARED.project.data.name)}.csv" + path = CONFIG.lastPath("outline") / f"{makeFileNameSafe(SHARED.project.data.name)}.csv" path, _ = QFileDialog.getSaveFileName( self, self.tr("Save Outline As"), str(path), formatFileFilter(["*.csv", "*"]) ) if path: - CONFIG.setLastPath(path) + CONFIG.setLastPath("outline", path) logger.info("Writing CSV file: %s", path) cols = [col for col in self._treeOrder if not self._colHidden[col]] order = [self._colIdx[col] for col in cols] diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 6fd1e1be..ed4b1650 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -652,7 +652,7 @@ class GuiMain(QMainWindow): logger.error("No project open") return False - lastPath = CONFIG.lastPath() + lastPath = CONFIG.lastPath("import") ffilter = formatFileFilter(["*.txt", "*.md", "*.nwd", "*"]) loadFile, _ = QFileDialog.getOpenFileName( self, self.tr("Import File"), str(lastPath), filter=ffilter @@ -667,7 +667,7 @@ class GuiMain(QMainWindow): try: with open(loadFile, mode="rt", encoding="utf-8") as inFile: text = inFile.read() - CONFIG.setLastPath(loadFile) + CONFIG.setLastPath("import", loadFile) except Exception as exc: SHARED.error(self.tr( "Could not read file. The file must be an existing text file." diff --git a/novelwriter/tools/welcome.py b/novelwriter/tools/welcome.py index 3f47b707..a4405d1b 100644 --- a/novelwriter/tools/welcome.py +++ b/novelwriter/tools/welcome.py @@ -220,8 +220,8 @@ class GuiWelcome(NDialog): @pyqtSlot() def _browseForProject(self) -> None: """Browse for a project to open.""" - if path := SHARED.getProjectPath(self, path=CONFIG.lastPath(), allowZip=False): - CONFIG.setLastPath(path) + if path := SHARED.getProjectPath(self, path=CONFIG.lastPath("project"), allowZip=False): + CONFIG.setLastPath("project", path) self._openProjectPath(path) return diff --git a/novelwriter/tools/writingstats.py b/novelwriter/tools/writingstats.py index 8e42a0c0..864ad177 100644 --- a/novelwriter/tools/writingstats.py +++ b/novelwriter/tools/writingstats.py @@ -384,14 +384,14 @@ class GuiWritingStats(NToolDialog): return False # Generate the file name - savePath = CONFIG.lastPath() / f"sessionStats.{fileExt}" + savePath = CONFIG.lastPath("stats") / f"sessionStats.{fileExt}" savePath, _ = QFileDialog.getSaveFileName( self, self.tr("Save Data As"), str(savePath), f"{textFmt} (*.{fileExt})" ) if not savePath: return False - CONFIG.setLastPath(savePath) + CONFIG.setLastPath("stats", savePath) # Do the actual writing wSuccess = False