Change the storage format of auto-replace in the XML
This commit is contained in:
+22
-8
@@ -449,7 +449,15 @@ class NWProject():
|
||||
self.importItems.unpackEntries(xItem)
|
||||
elif xItem.tag == "autoReplace":
|
||||
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":
|
||||
titleFormat = self.titleFormat.copy()
|
||||
for xEntry in xItem:
|
||||
@@ -501,7 +509,7 @@ class NWProject():
|
||||
|
||||
# Root element and project details
|
||||
logger.debug("Writing project meta")
|
||||
nwXML = etree.Element("novelWriterXML",attrib={
|
||||
nwXML = etree.Element("novelWriterXML", attrib={
|
||||
"appVersion" : str(nw.__version__),
|
||||
"hexVersion" : str(nw.__hexversion__),
|
||||
"fileVersion" : "1.1",
|
||||
@@ -533,11 +541,7 @@ class NWProject():
|
||||
self._packProjectValue(xSettings, "lastWordCount", self.currWCount)
|
||||
self._packProjectValue(xSettings, "novelWordCount", wcNovel)
|
||||
self._packProjectValue(xSettings, "notesWordCount", wcNotes)
|
||||
|
||||
xAutoRep = etree.SubElement(xSettings, "autoReplace")
|
||||
for aKey, aValue in self.autoReplace.items():
|
||||
if len(aKey) > 0:
|
||||
self._packProjectValue(xAutoRep, aKey, aValue)
|
||||
self._packProjectKeyValue(xSettings, "autoReplace", self.autoReplace)
|
||||
|
||||
xTitleFmt = etree.SubElement(xSettings, "titleFormat")
|
||||
for aKey, aValue in self.titleFormat.items():
|
||||
@@ -1041,10 +1045,20 @@ class NWProject():
|
||||
if not isinstance(aValue, str):
|
||||
aValue = str(aValue)
|
||||
if aValue == "" and not allowNone: continue
|
||||
xItem = etree.SubElement(xParent,theName)
|
||||
xItem = etree.SubElement(xParent, theName)
|
||||
xItem.text = aValue
|
||||
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):
|
||||
"""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
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?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>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
<author>Jane Smith</author>
|
||||
<author>Jay Doh</author>
|
||||
<saveCount>587</saveCount>
|
||||
<saveCount>589</saveCount>
|
||||
<autoCount>102</autoCount>
|
||||
<editTime>24235</editTime>
|
||||
<editTime>24247</editTime>
|
||||
</project>
|
||||
<settings>
|
||||
<doBackup>False</doBackup>
|
||||
@@ -19,9 +19,9 @@
|
||||
<novelWordCount>606</novelWordCount>
|
||||
<notesWordCount>376</notesWordCount>
|
||||
<autoReplace>
|
||||
<A>B</A>
|
||||
<B>E</B>
|
||||
<C>D</C>
|
||||
<entry key="A">B</entry>
|
||||
<entry key="B">E</entry>
|
||||
<entry key="C">D</entry>
|
||||
</autoReplace>
|
||||
<titleFormat>
|
||||
<title>%title%</title>
|
||||
|
||||
Reference in New Issue
Block a user