Change the storage format of auto-replace in the XML

This commit is contained in:
Veronica K. B. Olsen
2020-06-26 19:30:51 +02:00
parent 216d3f2ce4
commit e2f5ddf5f5
2 changed files with 28 additions and 14 deletions
+22 -8
View File
@@ -449,7 +449,15 @@ class NWProject():
self.importItems.unpackEntries(xItem) self.importItems.unpackEntries(xItem)
elif xItem.tag == "autoReplace": elif xItem.tag == "autoReplace":
for xEntry in xItem: for xEntry in xItem:
self.autoReplace[xEntry.tag] = checkString(xEntry.text, None, False) if xEntry.tag == "entry":
if "key" in xEntry.attrib:
self.autoReplace[xEntry.attrib["key"]] = checkString(
xEntry.text, None, False
)
else: # Old format
self.autoReplace[xEntry.tag] = checkString(
xEntry.text, None, False
)
elif xItem.tag == "titleFormat": elif xItem.tag == "titleFormat":
titleFormat = self.titleFormat.copy() titleFormat = self.titleFormat.copy()
for xEntry in xItem: for xEntry in xItem:
@@ -501,7 +509,7 @@ class NWProject():
# Root element and project details # Root element and project details
logger.debug("Writing project meta") logger.debug("Writing project meta")
nwXML = etree.Element("novelWriterXML",attrib={ nwXML = etree.Element("novelWriterXML", attrib={
"appVersion" : str(nw.__version__), "appVersion" : str(nw.__version__),
"hexVersion" : str(nw.__hexversion__), "hexVersion" : str(nw.__hexversion__),
"fileVersion" : "1.1", "fileVersion" : "1.1",
@@ -533,11 +541,7 @@ class NWProject():
self._packProjectValue(xSettings, "lastWordCount", self.currWCount) self._packProjectValue(xSettings, "lastWordCount", self.currWCount)
self._packProjectValue(xSettings, "novelWordCount", wcNovel) self._packProjectValue(xSettings, "novelWordCount", wcNovel)
self._packProjectValue(xSettings, "notesWordCount", wcNotes) self._packProjectValue(xSettings, "notesWordCount", wcNotes)
self._packProjectKeyValue(xSettings, "autoReplace", self.autoReplace)
xAutoRep = etree.SubElement(xSettings, "autoReplace")
for aKey, aValue in self.autoReplace.items():
if len(aKey) > 0:
self._packProjectValue(xAutoRep, aKey, aValue)
xTitleFmt = etree.SubElement(xSettings, "titleFormat") xTitleFmt = etree.SubElement(xSettings, "titleFormat")
for aKey, aValue in self.titleFormat.items(): for aKey, aValue in self.titleFormat.items():
@@ -1041,10 +1045,20 @@ class NWProject():
if not isinstance(aValue, str): if not isinstance(aValue, str):
aValue = str(aValue) aValue = str(aValue)
if aValue == "" and not allowNone: continue if aValue == "" and not allowNone: continue
xItem = etree.SubElement(xParent,theName) xItem = etree.SubElement(xParent, theName)
xItem.text = aValue xItem.text = aValue
return return
def _packProjectKeyValue(self, xParent, theName, theDict):
"""Pack the entries in the auto-replace dictionary.
"""
xAutoRep = etree.SubElement(xParent, theName)
for aKey, aValue in theDict.items():
if len(aKey) > 0:
xEntry = etree.SubElement(xAutoRep, "entry", attrib={"key": aKey})
xEntry.text = aValue
return
def _scanProjectFolder(self): def _scanProjectFolder(self):
"""Scan the project folder and check that the files in it are """Scan the project folder and check that the files in it are
also in the project XML file. If they aren't, import them as also in the project XML file. If they aren't, import them as
+6 -6
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.10.0rc1" hexVersion="0x001000c1" fileVersion="1.1" timeStamp="2020-06-26 18:36:47"> <novelWriterXML appVersion="0.10.0rc1" hexVersion="0x001000c1" fileVersion="1.1" timeStamp="2020-06-26 19:29:32">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
<author>Jane Smith</author> <author>Jane Smith</author>
<author>Jay Doh</author> <author>Jay Doh</author>
<saveCount>587</saveCount> <saveCount>589</saveCount>
<autoCount>102</autoCount> <autoCount>102</autoCount>
<editTime>24235</editTime> <editTime>24247</editTime>
</project> </project>
<settings> <settings>
<doBackup>False</doBackup> <doBackup>False</doBackup>
@@ -19,9 +19,9 @@
<novelWordCount>606</novelWordCount> <novelWordCount>606</novelWordCount>
<notesWordCount>376</notesWordCount> <notesWordCount>376</notesWordCount>
<autoReplace> <autoReplace>
<A>B</A> <entry key="A">B</entry>
<B>E</B> <entry key="B">E</entry>
<C>D</C> <entry key="C">D</entry>
</autoReplace> </autoReplace>
<titleFormat> <titleFormat>
<title>%title%</title> <title>%title%</title>