Improve Open Project error handling (#1740)
This commit is contained in:
@@ -183,11 +183,15 @@ class NWStorage:
|
|||||||
# 2. A full path to an nwProject.nwx file
|
# 2. A full path to an nwProject.nwx file
|
||||||
if inPath.is_dir() and inPath != Path.home().resolve():
|
if inPath.is_dir() and inPath != Path.home().resolve():
|
||||||
nwxFile = inPath / nwFiles.PROJ_FILE
|
nwxFile = inPath / nwFiles.PROJ_FILE
|
||||||
elif inPath.is_file() and inPath.name == nwFiles.PROJ_FILE:
|
elif inPath.is_file():
|
||||||
nwxFile = inPath
|
if inPath.name == nwFiles.PROJ_FILE:
|
||||||
|
nwxFile = inPath
|
||||||
|
else:
|
||||||
|
logger.error("Not a novelWriter project")
|
||||||
|
return NWStorageOpen.UNKOWN
|
||||||
else:
|
else:
|
||||||
logger.error("Not a novelWriter project")
|
logger.error("Not found: %s", inPath)
|
||||||
return NWStorageOpen.UNKOWN
|
return NWStorageOpen.NOT_FOUND
|
||||||
|
|
||||||
if not nwxFile.exists():
|
if not nwxFile.exists():
|
||||||
# The .nwx file must exist to continue
|
# The .nwx file must exist to continue
|
||||||
|
|||||||
@@ -796,7 +796,7 @@ class GuiMain(QMainWindow):
|
|||||||
def showWelcomeDialog(self) -> None:
|
def showWelcomeDialog(self) -> None:
|
||||||
"""Open the welcome dialog."""
|
"""Open the welcome dialog."""
|
||||||
dialog = GuiWelcome(self)
|
dialog = GuiWelcome(self)
|
||||||
dialog.openProjectRequest.connect(self._openProject)
|
dialog.openProjectRequest.connect(self._openProjectFromWelcome)
|
||||||
dialog.exec_()
|
dialog.exec_()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1132,10 +1132,12 @@ class GuiMain(QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(Path)
|
@pyqtSlot(Path)
|
||||||
def _openProject(self, path: Path) -> None:
|
def _openProjectFromWelcome(self, path: Path) -> None:
|
||||||
"""Handle an open project request."""
|
"""Handle an open project request from the welcome dialog."""
|
||||||
qApp.processEvents()
|
qApp.processEvents()
|
||||||
self.openProject(path)
|
self.openProject(path)
|
||||||
|
if not SHARED.hasProject:
|
||||||
|
self.showWelcomeDialog()
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(str, nwDocMode, str, bool)
|
@pyqtSlot(str, nwDocMode, str, bool)
|
||||||
|
|||||||
@@ -111,12 +111,15 @@ def testCoreStorage_InitProjectStorage(mockGUI, fncPath, mockRnd):
|
|||||||
buildTestProject(project, fncPath)
|
buildTestProject(project, fncPath)
|
||||||
|
|
||||||
# Init with the wrong file
|
# Init with the wrong file
|
||||||
|
foo = fncPath / "foobar.txt"
|
||||||
|
foo.touch()
|
||||||
assert storage.initProjectStorage(fncPath / "foobar.txt") == NWStorageOpen.UNKOWN
|
assert storage.initProjectStorage(fncPath / "foobar.txt") == NWStorageOpen.UNKOWN
|
||||||
|
foo.unlink()
|
||||||
storage._clearLockFile()
|
storage._clearLockFile()
|
||||||
storage.clear()
|
storage.clear()
|
||||||
|
|
||||||
# Init with the user's home dir
|
# Init with the user's home dir
|
||||||
assert storage.initProjectStorage(Path.home()) == NWStorageOpen.UNKOWN
|
assert storage.initProjectStorage(Path.home()) == NWStorageOpen.NOT_FOUND
|
||||||
storage._clearLockFile()
|
storage._clearLockFile()
|
||||||
storage.clear()
|
storage.clear()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user