Update current usage of last path

This commit is contained in:
Veronica Berglyd Olsen
2024-06-16 00:22:38 +02:00
parent 2a99cafbf2
commit 928a116666
5 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -344,7 +344,7 @@ class Config:
self._outlnPanePos = [int(x/self.guiScale) for x in pos] self._outlnPanePos = [int(x/self.guiScale) for x in pos]
return 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 """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. path is not a folder, the parent of the path is used instead.
""" """
@@ -353,7 +353,7 @@ class Config:
if not path.is_dir(): if not path.is_dir():
path = path.parent path = path.parent
if path.is_dir(): if path.is_dir():
self._recentPaths.setPath(key or "default", path) self._recentPaths.setPath(key, path)
self._recentPaths.saveCache() self._recentPaths.saveCache()
return return
+2 -2
View File
@@ -523,12 +523,12 @@ class GuiOutlineTree(QTreeWidget):
@pyqtSlot() @pyqtSlot()
def exportOutline(self) -> None: def exportOutline(self) -> None:
"""Export the outline as a CSV file.""" """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( path, _ = QFileDialog.getSaveFileName(
self, self.tr("Save Outline As"), str(path), formatFileFilter(["*.csv", "*"]) self, self.tr("Save Outline As"), str(path), formatFileFilter(["*.csv", "*"])
) )
if path: if path:
CONFIG.setLastPath(path) CONFIG.setLastPath("outline", path)
logger.info("Writing CSV file: %s", path) logger.info("Writing CSV file: %s", path)
cols = [col for col in self._treeOrder if not self._colHidden[col]] cols = [col for col in self._treeOrder if not self._colHidden[col]]
order = [self._colIdx[col] for col in cols] order = [self._colIdx[col] for col in cols]
+2 -2
View File
@@ -652,7 +652,7 @@ class GuiMain(QMainWindow):
logger.error("No project open") logger.error("No project open")
return False return False
lastPath = CONFIG.lastPath() lastPath = CONFIG.lastPath("import")
ffilter = formatFileFilter(["*.txt", "*.md", "*.nwd", "*"]) ffilter = formatFileFilter(["*.txt", "*.md", "*.nwd", "*"])
loadFile, _ = QFileDialog.getOpenFileName( loadFile, _ = QFileDialog.getOpenFileName(
self, self.tr("Import File"), str(lastPath), filter=ffilter self, self.tr("Import File"), str(lastPath), filter=ffilter
@@ -667,7 +667,7 @@ class GuiMain(QMainWindow):
try: try:
with open(loadFile, mode="rt", encoding="utf-8") as inFile: with open(loadFile, mode="rt", encoding="utf-8") as inFile:
text = inFile.read() text = inFile.read()
CONFIG.setLastPath(loadFile) CONFIG.setLastPath("import", loadFile)
except Exception as exc: except Exception as exc:
SHARED.error(self.tr( SHARED.error(self.tr(
"Could not read file. The file must be an existing text file." "Could not read file. The file must be an existing text file."
+2 -2
View File
@@ -220,8 +220,8 @@ class GuiWelcome(NDialog):
@pyqtSlot() @pyqtSlot()
def _browseForProject(self) -> None: def _browseForProject(self) -> None:
"""Browse for a project to open.""" """Browse for a project to open."""
if path := SHARED.getProjectPath(self, path=CONFIG.lastPath(), allowZip=False): if path := SHARED.getProjectPath(self, path=CONFIG.lastPath("project"), allowZip=False):
CONFIG.setLastPath(path) CONFIG.setLastPath("project", path)
self._openProjectPath(path) self._openProjectPath(path)
return return
+2 -2
View File
@@ -384,14 +384,14 @@ class GuiWritingStats(NToolDialog):
return False return False
# Generate the file name # Generate the file name
savePath = CONFIG.lastPath() / f"sessionStats.{fileExt}" savePath = CONFIG.lastPath("stats") / f"sessionStats.{fileExt}"
savePath, _ = QFileDialog.getSaveFileName( savePath, _ = QFileDialog.getSaveFileName(
self, self.tr("Save Data As"), str(savePath), f"{textFmt} (*.{fileExt})" self, self.tr("Save Data As"), str(savePath), f"{textFmt} (*.{fileExt})"
) )
if not savePath: if not savePath:
return False return False
CONFIG.setLastPath(savePath) CONFIG.setLastPath("stats", savePath)
# Do the actual writing # Do the actual writing
wSuccess = False wSuccess = False