Change how spel checking and booleans in general are saved in the XML
This commit is contained in:
@@ -88,9 +88,10 @@ def checkBool(value, default):
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
elif isinstance(value, str):
|
||||
if value == "True":
|
||||
check = value.lower()
|
||||
if check in ("true", "yes", "on"):
|
||||
return True
|
||||
elif value == "False":
|
||||
elif check in ("false", "no", "off"):
|
||||
return False
|
||||
else:
|
||||
return default
|
||||
@@ -259,6 +260,12 @@ def simplified(string):
|
||||
return " ".join(str(string).strip().split())
|
||||
|
||||
|
||||
def yesNo(value):
|
||||
"""Convert a boolean evaluated variable to a yes or no.
|
||||
"""
|
||||
return "yes" if value else "no"
|
||||
|
||||
|
||||
def splitVersionNumber(value):
|
||||
"""Split a version string on the form aa.bb.cc into major, minor
|
||||
and patch, and computes an integer value aabbcc.
|
||||
|
||||
@@ -27,7 +27,7 @@ import logging
|
||||
|
||||
from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout
|
||||
from novelwriter.common import (
|
||||
checkInt, isHandle, isItemClass, isItemLayout, isItemType, simplified
|
||||
checkInt, isHandle, isItemClass, isItemLayout, isItemType, simplified, yesNo
|
||||
)
|
||||
from novelwriter.constants import nwHeaders, nwLabels, trConst
|
||||
|
||||
@@ -162,7 +162,7 @@ class NWItem:
|
||||
item["order"] = str(self._order)
|
||||
item["type"] = str(self._type.name)
|
||||
item["class"] = str(self._class.name)
|
||||
meta["expanded"] = str(self._expanded)
|
||||
meta["expanded"] = yesNo(self._expanded)
|
||||
name["status"] = str(self._status)
|
||||
name["import"] = str(self._import)
|
||||
|
||||
@@ -173,7 +173,7 @@ class NWItem:
|
||||
meta["wordCount"] = str(self._wordCount)
|
||||
meta["paraCount"] = str(self._paraCount)
|
||||
meta["cursorPos"] = str(self._cursorPos)
|
||||
name["active"] = str(self._active)
|
||||
name["active"] = yesNo(self._active)
|
||||
|
||||
data = {
|
||||
"name": str(self._name),
|
||||
|
||||
@@ -33,7 +33,8 @@ from time import time
|
||||
from pathlib import Path
|
||||
|
||||
from novelwriter.common import (
|
||||
checkBool, checkInt, checkStringNone, formatTimeStamp, simplified, checkString
|
||||
checkBool, checkInt, checkString, checkStringNone, formatTimeStamp,
|
||||
simplified, yesNo
|
||||
)
|
||||
from novelwriter.constants import nwFiles
|
||||
|
||||
@@ -270,10 +271,9 @@ class ProjectXMLReader:
|
||||
projData.setDoBackup(xItem.text)
|
||||
elif xItem.tag == "language":
|
||||
projData.setLanguage(xItem.text)
|
||||
elif xItem.tag == "spellCheck":
|
||||
projData.setSpellCheck(xItem.text)
|
||||
elif xItem.tag == "spellLang":
|
||||
elif xItem.tag == "spellChecking":
|
||||
projData.setSpellLang(xItem.text)
|
||||
projData.setSpellCheck(xItem.attrib.get("auto", False))
|
||||
elif xItem.tag == "status":
|
||||
self._parseStatusImport(xItem, projData.itemStatus)
|
||||
elif xItem.tag == "importance":
|
||||
@@ -296,7 +296,11 @@ class ProjectXMLReader:
|
||||
# Deprecated Nodes
|
||||
if self._version < HEX_VERSION:
|
||||
for xItem in xSection:
|
||||
if xItem.tag == "novelWordCount": # Moved to content attribute in 1.5
|
||||
if xItem.tag == "spellCheck": # Changed to spellChecking in 1.5
|
||||
projData.setSpellCheck(xItem.text)
|
||||
elif xItem.tag == "spellLang": # Changed to spellChecking in 1.5
|
||||
projData.setSpellLang(xItem.text)
|
||||
elif xItem.tag == "novelWordCount": # Moved to content attribute in 1.5
|
||||
projData.setInitCounts(novel=xItem.text)
|
||||
elif xItem.tag == "notesWordCount": # Moved to content attribute in 1.5
|
||||
projData.setInitCounts(notes=xItem.text)
|
||||
@@ -517,10 +521,11 @@ class ProjectXMLWriter:
|
||||
|
||||
# Save Project Settings
|
||||
xSettings = etree.SubElement(xRoot, "settings")
|
||||
self._packSingleValue(xSettings, "doBackup", projData.doBackup)
|
||||
self._packSingleValue(xSettings, "doBackup", yesNo(projData.doBackup))
|
||||
self._packSingleValue(xSettings, "language", projData.language)
|
||||
self._packSingleValue(xSettings, "spellCheck", projData.spellCheck)
|
||||
self._packSingleValue(xSettings, "spellLang", projData.spellLang)
|
||||
self._packSingleValue(xSettings, "spellChecking", projData.spellLang, attrib={
|
||||
"auto": yesNo(projData.spellCheck)
|
||||
})
|
||||
self._packDictKeyValue(xSettings, "lastHandle", projData.lastHandle)
|
||||
self._packDictKeyValue(xSettings, "autoReplace", projData.autoReplace)
|
||||
self._packDictKeyValue(xSettings, "titleFormat", projData.titleFormat)
|
||||
@@ -536,7 +541,7 @@ class ProjectXMLWriter:
|
||||
|
||||
# Save Tree Content
|
||||
contAttr = {
|
||||
"itemCount": str(len(projContent)),
|
||||
"items": str(len(projContent)),
|
||||
"novelWords": str(projData.currCounts[0]),
|
||||
"notesWords": str(projData.currCounts[1]),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user