From cea22b6147ab5456d0ebd67475a62fe38785ec2b Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 21 May 2022 17:58:47 +0200 Subject: [PATCH] Clean up new project creation function --- novelwriter/core/project.py | 51 ++++++++++--------- .../coreProject_NewCustomA_nwProject.nwx | 16 ++++-- .../coreProject_NewCustomB_nwProject.nwx | 16 ++++-- .../coreProject_NewMinimal_nwProject.nwx | 40 ++++++++------- 4 files changed, 73 insertions(+), 50 deletions(-) diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 9cabb53e..0557ce6e 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -264,42 +264,41 @@ class NWProject(): self.setBookTitle(projTitle) self.setBookAuthors(projAuthors) + hNovelRoot = self.newRoot( + trConst(nwLabels.CLASS_NAME[nwItemClass.NOVEL]), nwItemClass.NOVEL + ) + titlePage = "#! %s\n\n" % (self.bookTitle if self.bookTitle else self.projName) if self.bookAuthors: titlePage = "%s>> %s %s <<\n" % (titlePage, self.tr("By"), self.getAuthors()) + hTitlePage = self.newFile(self.tr("Title Page"), hNovelRoot) + aDoc = NWDoc(self, hTitlePage) + aDoc.writeDocument(titlePage) + if popMinimal: # Creating a minimal project with a few root folders and a - # single chapter folder with a single file. - xHandle = {} - xHandle[1] = self.newRoot(self.tr("Novel"), nwItemClass.NOVEL) - xHandle[2] = self.newRoot(self.tr("Plot"), nwItemClass.PLOT) - xHandle[3] = self.newRoot(self.tr("Characters"), nwItemClass.CHARACTER) - xHandle[4] = self.newRoot(self.tr("World"), nwItemClass.WORLD) - xHandle[5] = self.newFile(self.tr("Title Page"), xHandle[1]) - xHandle[6] = self.newFile(self.tr("New Chapter"), xHandle[1]) - xHandle[7] = self.newFile(self.tr("New Scene"), xHandle[6]) - - aDoc = NWDoc(self, xHandle[5]) - aDoc.writeDocument(titlePage) - - aDoc = NWDoc(self, xHandle[6]) + # single chapter with a single scene. + hChapter = self.newFile(self.tr("New Chapter"), hNovelRoot) + aDoc = NWDoc(self, hChapter) aDoc.writeDocument("## %s\n\n" % self.tr("New Chapter")) - aDoc = NWDoc(self, xHandle[7]) + hScene = self.newFile(self.tr("New Scene"), hChapter) + aDoc = NWDoc(self, hScene) aDoc.writeDocument("### %s\n\n" % self.tr("New Scene")) + minClasses = [ + nwItemClass.PLOT, nwItemClass.CHARACTER, + nwItemClass.WORLD, nwItemClass.ARCHIVE + ] + for minClass in minClasses: + self.newRoot(trConst(nwLabels.CLASS_NAME[minClass]), minClass) + elif popCustom: # Create a project structure based on selected root folders # and a number of chapters and scenes selected in the # wizard's custom page. - # Create novel folders - nHandle = self.newRoot(self.tr("Novel"), nwItemClass.NOVEL) - tHandle = self.newFile(self.tr("Title Page"), nHandle) - aDoc = NWDoc(self, tHandle) - aDoc.writeDocument(titlePage) - # Create chapters and scenes numChapters = projData.get("numChapters", 0) numScenes = projData.get("numScenes", 0) @@ -311,7 +310,7 @@ class NWProject(): if numChapters > 0: for ch in range(numChapters): chTitle = self.tr("Chapter {0}").format(f"{ch+1:d}") - cHandle = self.newFile(chTitle, nHandle) + cHandle = self.newFile(chTitle, hNovelRoot) aDoc = NWDoc(self, cHandle) aDoc.writeDocument(f"## {chTitle}\n\n% Synopsis: {chSynop}\n\n") @@ -327,7 +326,7 @@ class NWProject(): elif numScenes > 0: for sc in range(numScenes): scTitle = self.tr("Scene {0}").format(f"{sc+1:d}") - sHandle = self.newFile(scTitle, nHandle) + sHandle = self.newFile(scTitle, hNovelRoot) aDoc = NWDoc(self, sHandle) aDoc.writeDocument(f"### {scTitle}\n\n% Synopsis: {scSynop}\n\n") @@ -341,13 +340,17 @@ class NWProject(): addNotes = projData.get("addNotes", False) for newRoot in projData.get("addRoots", []): if newRoot in nwItemClass: - rHandle = self.newRoot(nwLabels.CLASS_NAME[newRoot], newRoot) + rHandle = self.newRoot(trConst(nwLabels.CLASS_NAME[newRoot]), newRoot) if addNotes: aHandle = self.newFile(noteTitles[newRoot], rHandle) ntTag = simplified(noteTitles[newRoot]).replace(" ", "") aDoc = NWDoc(self, aHandle) aDoc.writeDocument(f"# {noteTitles[newRoot]}\n\n@tag: {ntTag}\n\n") + # Also add the archive and trash folders + self.newRoot(trConst(nwLabels.CLASS_NAME[nwItemClass.ARCHIVE]), nwItemClass.ARCHIVE) + self.trashFolder() + # Finalise if popCustom or popMinimal: self.projOpened = time() diff --git a/tests/reference/coreProject_NewCustomA_nwProject.nwx b/tests/reference/coreProject_NewCustomA_nwProject.nwx index 4e201ccd..be4845bf 100644 --- a/tests/reference/coreProject_NewCustomA_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomA_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -29,19 +29,19 @@
- New + New Note Draft Finished - New + New Minor Major Main - + Novel @@ -122,5 +122,13 @@ Main Location + + + Archive + + + + Trash +
diff --git a/tests/reference/coreProject_NewCustomB_nwProject.nwx b/tests/reference/coreProject_NewCustomB_nwProject.nwx index 6b45cbbc..12f911cd 100644 --- a/tests/reference/coreProject_NewCustomB_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomB_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -29,19 +29,19 @@
- New + New Note Draft Finished - New + New Minor Major Main - + Novel @@ -98,5 +98,13 @@ Main Location + + + Archive + + + + Trash +
diff --git a/tests/reference/coreProject_NewMinimal_nwProject.nwx b/tests/reference/coreProject_NewMinimal_nwProject.nwx index 68e08580..422bb6b2 100644 --- a/tests/reference/coreProject_NewMinimal_nwProject.nwx +++ b/tests/reference/coreProject_NewMinimal_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project @@ -27,7 +27,7 @@
- New + New Note Draft Finished @@ -39,34 +39,38 @@ Main - + Novel - - - Plot - - - - Characters - - - - World - - + Title Page - + New Chapter - + New Scene + + + Plot + + + + Characters + + + + Locations + + + + Archive +