Update current usage of last path
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user