From 557b86af642b5c760474bfeafdfc6453eb792bbe Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 30 Oct 2019 15:47:12 +0100 Subject: [PATCH] Add the option to expand ~ to user home directory in export and project path --- nw/gui/export.py | 14 ++++++++++++++ nw/project/project.py | 2 ++ 2 files changed, 16 insertions(+) diff --git a/nw/gui/export.py b/nw/gui/export.py index 1b33ade6..1032bb08 100644 --- a/nw/gui/export.py +++ b/nw/gui/export.py @@ -122,6 +122,15 @@ class GuiExport(QDialog): pFormat = self.tabPandoc.outputFormat.currentData() tFormat = GuiExportPandoc.FMT_VIA[pFormat] + if saveTo.startswith("~"): + saveTo = path.expanduser(saveTo) + + exportDir = path.dirname(saveTo) + if not path.isdir(exportDir): + self.theParent.makeAlert("The export folder does not exist.",nwAlert.ERROR) + self.exportStatus.setText("Export failed ...") + return False + nItems = len(self.theProject.treeOrder) if eFormat == GuiExportMain.FMT_PDOC: nItems += int(0.2*nItems) @@ -288,6 +297,9 @@ class GuiExport(QDialog): hScene = self.tabMain.hideScene.isChecked() hSection = self.tabMain.hideSection.isChecked() + if saveTo.startswith("~"): + saveTo = path.expanduser(saveTo) + self.optState.setSetting("wNovel", wNovel) self.optState.setSetting("wNotes", wNotes) self.optState.setSetting("eFormat", eFormat) @@ -563,6 +575,8 @@ class GuiExportMain(QWidget): def _checkFileExtension(self): saveTo = self.exportPath.text() + if saveTo.startswith("~"): + saveTo = path.expanduser(saveTo) fileBits = path.splitext(saveTo) if self.currFormat > 0 and fileBits[0].strip() != "": saveTo = fileBits[0]+self.FMT_EXT[self.currFormat] diff --git a/nw/project/project.py b/nw/project/project.py index 62345a63..df298dc8 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -358,6 +358,8 @@ class NWProject(): if projPath is None or projPath == "": self.projPath = None else: + if projPath.startswith("~"): + projPath = path.expanduser(projPath) self.projPath = projPath self.setProjectChanged(True) return True