Add build details widget to manuscript tool
This commit is contained in:
@@ -319,7 +319,6 @@ class BuildSettings:
|
||||
value = min(max(value, definition[2]), definition[3])
|
||||
self._changed = value != self._settings[key]
|
||||
self._settings[key] = value
|
||||
logger.debug(f"Build Setting '{key}' set to: {value}")
|
||||
return True
|
||||
|
||||
##
|
||||
@@ -457,6 +456,8 @@ class BuildCollection:
|
||||
def __init__(self, project: NWProject) -> None:
|
||||
self._project = project
|
||||
self._builds = {}
|
||||
self._lastBuild = ""
|
||||
self._defaultBuild = ""
|
||||
self._loadCollection()
|
||||
return
|
||||
|
||||
@@ -465,7 +466,21 @@ class BuildCollection:
|
||||
return len(self._builds)
|
||||
|
||||
##
|
||||
# Methods
|
||||
# Properties
|
||||
##
|
||||
|
||||
@property
|
||||
def lastBuild(self) -> str:
|
||||
"""Return the last active build."""
|
||||
return self._lastBuild
|
||||
|
||||
@property
|
||||
def defaultBuild(self) -> str:
|
||||
"""Return the default build."""
|
||||
return self._defaultBuild
|
||||
|
||||
##
|
||||
# Getters
|
||||
##
|
||||
|
||||
def getBuild(self, buildID: str) -> BuildSettings | None:
|
||||
@@ -476,6 +491,24 @@ class BuildCollection:
|
||||
build.unpack(self._builds[buildID])
|
||||
return build
|
||||
|
||||
##
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setLastBuild(self, buildID: str) -> None:
|
||||
"""Set the last active build id."""
|
||||
if buildID != self._lastBuild:
|
||||
self._lastBuild = buildID
|
||||
self._saveCollection()
|
||||
return
|
||||
|
||||
def setDefaultBuild(self, buildID: str) -> None:
|
||||
"""Set the default build id."""
|
||||
if buildID != self._defaultBuild:
|
||||
self._defaultBuild = buildID
|
||||
self._saveCollection()
|
||||
return
|
||||
|
||||
def setBuild(self, build: BuildSettings) -> None:
|
||||
"""Set build settings data in the collection."""
|
||||
if isinstance(build, BuildSettings):
|
||||
@@ -484,6 +517,10 @@ class BuildCollection:
|
||||
self._saveCollection()
|
||||
return
|
||||
|
||||
##
|
||||
# Methods
|
||||
##
|
||||
|
||||
def removeBuild(self, buildID: str) -> None:
|
||||
"""Remove the a build from the collection."""
|
||||
self._builds.pop(buildID, None)
|
||||
@@ -527,7 +564,11 @@ class BuildCollection:
|
||||
return False
|
||||
|
||||
for key, entry in builds.items():
|
||||
if isinstance(entry, dict):
|
||||
if key == "lastBuild":
|
||||
self._lastBuild = str(entry)
|
||||
elif key == "defaultBuild":
|
||||
self._defaultBuild = str(entry)
|
||||
elif isinstance(entry, dict):
|
||||
self._builds[key] = entry
|
||||
|
||||
return True
|
||||
@@ -540,9 +581,13 @@ class BuildCollection:
|
||||
|
||||
logger.debug("Saving builds file")
|
||||
try:
|
||||
data = {"novelWriter.builds": self._builds}
|
||||
data = {
|
||||
"lastBuild": self._lastBuild,
|
||||
"defaultBuild": self._defaultBuild,
|
||||
}
|
||||
data.update(self._builds)
|
||||
with open(buildsFile, mode="w+", encoding="utf-8") as outFile:
|
||||
outFile.write(jsonEncode(data, nmax=4))
|
||||
outFile.write(jsonEncode({"novelWriter.builds": data}, nmax=4))
|
||||
except Exception:
|
||||
logger.error("Failed to save builds file")
|
||||
logException()
|
||||
|
||||
@@ -58,13 +58,14 @@ VALID_MAP = {
|
||||
"GuiWordList": {"winWidth", "winHeight"},
|
||||
"GuiNovelView": {"lastCol", "lastColSize"},
|
||||
"GuiBuildSettings": {
|
||||
"winWidth", "winHeight", "treeWidth", "filterWidth"
|
||||
"winWidth", "winHeight", "treeWidth", "filterWidth",
|
||||
},
|
||||
"GuiManuscript": {
|
||||
"winWidth", "winHeight", "optsWidth", "viewWidth"
|
||||
"winWidth", "winHeight", "optsWidth", "viewWidth", "listHeight",
|
||||
"detailsHeight", "detailsWidth", "detailsExpanded",
|
||||
},
|
||||
"GuiManuscriptBuild": {
|
||||
"winWidth", "winHeight", "fmtWidth", "sumWidth"
|
||||
"winWidth", "winHeight", "fmtWidth", "sumWidth",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ from functools import partial
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication, QRegularExpression
|
||||
|
||||
from novelwriter import SHARED
|
||||
from novelwriter.enum import nwItemLayout
|
||||
from novelwriter.common import formatTimeStamp, numberToRoman, checkInt
|
||||
from novelwriter.constants import nwConst, nwHeadFmt, nwRegEx, nwUnicode
|
||||
@@ -147,7 +148,7 @@ class Tokenizer(ABC):
|
||||
self._linkHeaders = False # Add an anchor before headers
|
||||
|
||||
# Instance Variables
|
||||
self._hFormatter = HeadingFormatter(self._project)
|
||||
self._hFormatter = HeadingFormatter()
|
||||
self._firstScene = False # Flag to indicate that the first scene of the chapter
|
||||
|
||||
# This File
|
||||
@@ -771,8 +772,7 @@ class Tokenizer(ABC):
|
||||
|
||||
class HeadingFormatter:
|
||||
|
||||
def __init__(self, project: NWProject) -> None:
|
||||
self._project = project
|
||||
def __init__(self) -> None:
|
||||
self._chCount = 0
|
||||
self._scChCount = 0
|
||||
self._scAbsCount = 0
|
||||
@@ -801,7 +801,7 @@ class HeadingFormatter:
|
||||
hFormat = hFormat.replace(nwHeadFmt.SC_NUM, str(self._scChCount))
|
||||
hFormat = hFormat.replace(nwHeadFmt.SC_ABS, str(self._scAbsCount))
|
||||
if nwHeadFmt.CH_WORD in hFormat:
|
||||
chWord = self._project.localLookup(self._chCount)
|
||||
chWord = SHARED.project.localLookup(self._chCount)
|
||||
hFormat = hFormat.replace(nwHeadFmt.CH_WORD, chWord)
|
||||
if nwHeadFmt.CH_ROML in hFormat:
|
||||
chRom = numberToRoman(self._chCount, toLower=True)
|
||||
|
||||
Reference in New Issue
Block a user