Improve new project creation, and generate new id for sample projects
This commit is contained in:
@@ -416,13 +416,14 @@ class ProjectBuilder:
|
|||||||
|
|
||||||
self._path = project.storage.storagePath
|
self._path = project.storage.storagePath
|
||||||
|
|
||||||
lblNewProject = self.tr("New Project")
|
lblName = self.tr("New Project")
|
||||||
lblTitlePage = self.tr("Title Page")
|
lblAuthor = self.tr("Author")
|
||||||
|
lblTitlePage = self.tr("Title Page")
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
project.data.setUuid(None)
|
project.data.setUuid(None)
|
||||||
project.data.setName(data.get("name", lblNewProject))
|
project.data.setName(data.get("name", lblName))
|
||||||
project.data.setAuthor(data.get("author", ""))
|
project.data.setAuthor(data.get("author", lblAuthor))
|
||||||
project.data.setLanguage(CONFIG.guiLocale)
|
project.data.setLanguage(CONFIG.guiLocale)
|
||||||
project.setDefaultStatusImport()
|
project.setDefaultStatusImport()
|
||||||
project.session.startSession()
|
project.session.startSession()
|
||||||
@@ -446,18 +447,14 @@ class ProjectBuilder:
|
|||||||
"\n"
|
"\n"
|
||||||
">> {count}: [field:{field}] <<\n"
|
">> {count}: [field:{field}] <<\n"
|
||||||
).format(
|
).format(
|
||||||
author=project.data.author or "None",
|
author=project.data.author or lblAuthor,
|
||||||
address=self.tr("Address"),
|
address=self.tr("Address Line"),
|
||||||
title=project.data.name or "None",
|
title=project.data.name or lblName,
|
||||||
by=self.tr("By"),
|
by=self.tr("By"),
|
||||||
count=self.tr("Word Count"),
|
count=self.tr("Word Count"),
|
||||||
field=nwStats.WORDS_TEXT,
|
field=nwStats.WORDS_TEXT,
|
||||||
))
|
))
|
||||||
|
|
||||||
# Create a project structure based on selected root folders
|
|
||||||
# and a number of chapters and scenes selected in the
|
|
||||||
# wizard's custom page.
|
|
||||||
|
|
||||||
# Create chapters and scenes
|
# Create chapters and scenes
|
||||||
numChapters = data.get("chapters", 0)
|
numChapters = data.get("chapters", 0)
|
||||||
numScenes = data.get("scenes", 0)
|
numScenes = data.get("scenes", 0)
|
||||||
@@ -563,19 +560,7 @@ class ProjectBuilder:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Open the copied project and update settings
|
# Open the copied project and update settings
|
||||||
project = NWProject()
|
self._resetProject(dstPath, data.get("name", ""), data.get("author", ""))
|
||||||
project.openProject(dstPath)
|
|
||||||
project.data.setUuid("") # Creates a fresh uuid
|
|
||||||
project.data.setName(data.get("name", "None"))
|
|
||||||
project.data.setAuthor(data.get("author", ""))
|
|
||||||
project.data.setSpellCheck(True)
|
|
||||||
project.data.setSpellLang(None)
|
|
||||||
project.data.setDoBackup(True)
|
|
||||||
project.data.setSaveCount(0)
|
|
||||||
project.data.setAutoCount(0)
|
|
||||||
project.data.setEditTime(0)
|
|
||||||
project.saveProject()
|
|
||||||
project.closeProject()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -593,6 +578,7 @@ class ProjectBuilder:
|
|||||||
if (sample := CONFIG.assetPath("sample.zip")).is_file():
|
if (sample := CONFIG.assetPath("sample.zip")).is_file():
|
||||||
try:
|
try:
|
||||||
shutil.unpack_archive(sample, path)
|
shutil.unpack_archive(sample, path)
|
||||||
|
self._resetProject(path)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
SHARED.error(self.tr("Failed to create a new example project."), exc=exc)
|
SHARED.error(self.tr("Failed to create a new example project."), exc=exc)
|
||||||
return False
|
return False
|
||||||
@@ -605,3 +591,22 @@ class ProjectBuilder:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _resetProject(self, path: Path, name: str = "", author: str = "") -> None:
|
||||||
|
"""Open a project and reset/update its settings."""
|
||||||
|
project = NWProject()
|
||||||
|
project.openProject(path)
|
||||||
|
project.data.setUuid("") # Creates a fresh uuid
|
||||||
|
if name:
|
||||||
|
project.data.setName(name)
|
||||||
|
if author:
|
||||||
|
project.data.setAuthor(author)
|
||||||
|
project.data.setSpellCheck(True)
|
||||||
|
project.data.setSpellLang(None)
|
||||||
|
project.data.setDoBackup(True)
|
||||||
|
project.data.setSaveCount(0)
|
||||||
|
project.data.setAutoCount(0)
|
||||||
|
project.data.setEditTime(0)
|
||||||
|
project.saveProject()
|
||||||
|
project.closeProject()
|
||||||
|
return
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Jane Doe
|
Jane Doe
|
||||||
Address 1
|
Address Line 1
|
||||||
Address 2
|
Address Line 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ Test Project A
|
|||||||
|
|
||||||
**By Jane Doe**
|
**By Jane Doe**
|
||||||
|
|
||||||
Word Count: 11
|
Word Count: 13
|
||||||
|
|
||||||
# Chapter 1
|
# Chapter 1
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Jane Doe
|
Jane Doe
|
||||||
Address 1
|
Address Line 1
|
||||||
Address 2
|
Address Line 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ Test Project B
|
|||||||
|
|
||||||
**By Jane Doe**
|
**By Jane Doe**
|
||||||
|
|
||||||
Word Count: 11
|
Word Count: 13
|
||||||
|
|
||||||
* * *
|
* * *
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user