diff --git a/novelwriter/core/coretools.py b/novelwriter/core/coretools.py index d283669c..4f9d4954 100644 --- a/novelwriter/core/coretools.py +++ b/novelwriter/core/coretools.py @@ -307,8 +307,6 @@ class ProjectBuilder: if not project.storage.openProjectInPlace(projPath, newProject=True): return False - project.projPath = projPath - lblNewProject = self.tr("New Project") lblNewChapter = self.tr("New Chapter") lblNewScene = self.tr("New Scene") diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index aef749a7..12ffcfac 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -83,7 +83,6 @@ class NWProject(QObject): self.lockedBy = None # Data on which computer has the project open # Class Settings - self.projPath = None # The full path to where the currently open project is saved self.projDict = None # The spell check dictionary self.projFiles = [] # A list of all files in the content folder on load @@ -250,7 +249,6 @@ class NWProject(QObject): self._data = NWProjectData(self) # Project Settings - self.projPath = None self.projDict = None self.projFiles = [] @@ -266,10 +264,7 @@ class NWProject(QObject): if not self._storage.openProjectInPlace(projPath): return False - # ToDo: These should not be set explicitly, and should stay as Path - self.projPath = str(self._storage.runtimePath) - - logger.info("Opening project: %s", self.projPath) + logger.info("Opening project: %s", projPath) self.projDict = str(self._storage.getMetaFile(nwFiles.PROJ_DICT)) @@ -368,7 +363,7 @@ class NWProject(QObject): # Update recent projects self.mainConf.updateRecentCache( - self.projPath, self._data.name, sum(self._data.initCounts), time() + self._storage.storagePath, self._data.name, sum(self._data.initCounts), time() ) self.mainConf.saveRecentCache() @@ -399,12 +394,6 @@ class NWProject(QObject): to make sure if the save fails, we're not left with a truncated file. """ - if self.projPath is None: - self.mainGui.makeAlert(self.tr( - "Project path not set, cannot save project." - ), nwAlert.ERROR) - return False - if not self._storage.isOpen(): self.mainGui.makeAlert(self.tr( "There is no project open." @@ -413,7 +402,7 @@ class NWProject(QObject): saveTime = time() - logger.info("Saving project: %s", self.projPath) + logger.info("Saving project: %s", self._storage.storagePath) if autoSave: self._data.incAutoCount() @@ -442,7 +431,7 @@ class NWProject(QObject): # Update recent projects self.mainConf.updateRecentCache( - self.projPath, self._data.name, sum(self._data.currCounts), saveTime + self._storage.storagePath, self._data.name, sum(self._data.currCounts), saveTime ) self.mainConf.saveRecentCache() @@ -455,7 +444,7 @@ class NWProject(QObject): def closeProject(self, idleTime=0.0): """Close the current project and clear all meta data. """ - logger.info("Closing project: %s", self.projPath) + logger.info("Closing project") self._options.saveSettings() self._tree.writeToCFile() self._appendSessionStats(idleTime) @@ -517,7 +506,7 @@ class NWProject(QObject): ), nwAlert.ERROR, exception=exc) return False - if baseDir and baseDir.startswith(self.projPath): + if baseDir and baseDir.startswith(str(self._storage.runtimePath)): self.mainGui.makeAlert(self.tr( "Cannot backup project because the backup path is within the " "project folder to be backed up. Please choose a different " @@ -530,7 +519,7 @@ class NWProject(QObject): try: self._storage.clearLockFile() - shutil.make_archive(baseName, "zip", self.projPath, ".") + shutil.make_archive(baseName, "zip", self._storage.runtimePath, ".") self._storage.writeLockFile() logger.info("Backup written to: %s", archName) if doNotify: diff --git a/novelwriter/core/storage.py b/novelwriter/core/storage.py index b79e98cb..ad90126e 100644 --- a/novelwriter/core/storage.py +++ b/novelwriter/core/storage.py @@ -67,6 +67,10 @@ class NWStorage: # Properties ## + @property + def storagePath(self): + return self._storagePath + @property def runtimePath(self): return self._runtimePath diff --git a/novelwriter/dialogs/projdetails.py b/novelwriter/dialogs/projdetails.py index 0f185e89..9f3999a4 100644 --- a/novelwriter/dialogs/projdetails.py +++ b/novelwriter/dialogs/projdetails.py @@ -260,7 +260,7 @@ class GuiProjectDetailsMain(QWidget): self.revCountVal.setText(f"{self.theProject.data.saveCount:n}") self.editTimeVal.setText(f"{edTime//3600:02d}:{edTime%3600//60:02d}") - self.projPathVal.setText(self.theProject.projPath) + self.projPathVal.setText(str(self.theProject.storage.storagePath)) return diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index c0745460..6537e7a0 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -1382,7 +1382,7 @@ class GuiMain(QMainWindow): """ doSave = self.hasProject doSave &= self.theProject.projChanged - doSave &= self.theProject.projPath is not None + doSave &= self.theProject.storage.isOpen() if doSave: logger.debug("Autosaving project") diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 8b3896d6..62e631c3 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -649,7 +649,8 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum): writeFile(tstPath, "\n") assert theProject.openProject(nwLipsum) - assert theProject.projPath is not None + assert theProject.storage.storagePath is not None + assert theProject.storage.runtimePath is not None assert theProject.tree["636b6aa9b697bb"] is None assert theProject.tree["abcdefghijklm"] is None diff --git a/tests/tools.py b/tests/tools.py index 07fa6aab..c2511b28 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -166,7 +166,6 @@ def buildTestProject(theObject, projPath): theProject = theObject.theProject theProject.clearProject() - theProject.projPath = projPath theProject.storage.openProjectInPlace(projPath) theProject.setDefaultStatusImport()