Auto-replace values now loaded and saved.

This commit is contained in:
Veronica K. B. Olsen
2019-06-08 20:02:09 +02:00
parent f219d1f8bb
commit 2d55ec06cc
4 changed files with 80 additions and 39 deletions
+19 -8
View File
@@ -50,7 +50,7 @@ class GuiProjectEditor(QDialog):
self.tabMain = GuiProjectEditMain(self.theParent, self.theProject)
self.tabStatus = GuiProjectEditStatus(self.theParent, self.theProject.statusItems)
self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject.importItems)
self.tabReplace = GuiProjectEditReplace(self.theParent, self.theProject.importItems)
self.tabReplace = GuiProjectEditReplace(self.theParent, self.theProject)
self.tabWidget = QTabWidget()
self.tabWidget.addTab(self.tabMain, "Settings")
@@ -75,12 +75,6 @@ class GuiProjectEditor(QDialog):
return
# def keyPressEvent(self, theEvent):
# if theEvent.key() == Qt.Key_Enter or theEvent.key() == Qt.Key_Return:
# return
# QDialog.keyPressEvent(self, theEvent)
# return
def _doSave(self):
logger.verbose("ProjectEditor save button clicked")
@@ -99,6 +93,9 @@ class GuiProjectEditor(QDialog):
self.theProject.setImportColours(importCol)
if self.tabStatus.colChanged or self.tabImport.colChanged:
self.theParent.rebuildTree()
if self.tabReplace.arChanged:
newList = self.tabReplace.getNewList()
self.theProject.setAutoReplace(newList)
self.close()
@@ -313,9 +310,13 @@ class GuiProjectEditReplace(QWidget):
self.outerBox = QVBoxLayout()
self.bottomBox = QHBoxLayout()
self.listBox = QTreeWidget()
self.listBox.setHeaderLabels(["Keyword","Value"])
self.listBox.setHeaderLabels(["Keyword","Replace With"])
self.listBox.setIndentation(0)
for aKey, aVal in self.theProject.autoReplace.items():
newItem = QTreeWidgetItem(["<%s>" % aKey, aVal])
self.listBox.addTopLevelItem(newItem)
self.editKey = QLineEdit()
self.editValue = QLineEdit()
self.addButton = QPushButton(QIcon.fromTheme("list-add"),"")
@@ -362,4 +363,14 @@ class GuiProjectEditReplace(QWidget):
self.arChanged = True
return True
def getNewList(self):
newList = {}
for n in range(self.listBox.topLevelItemCount()):
tItem = self.listBox.topLevelItem(n)
aKey = tItem.text(0)
aVal = tItem.text(1)
if len(aKey) > 2:
newList[aKey[1:-1]] = aVal
return newList
# END Class GuiProjectEditReplace
+44 -29
View File
@@ -32,37 +32,40 @@ class NWProject():
def __init__(self, theParent):
# Internal
self.theParent = theParent
self.mainConf = self.theParent.mainConf
self.projChanged = None
self.projOpened = None
self.theParent = theParent
self.mainConf = self.theParent.mainConf
self.projChanged = None
self.projOpened = None
# Debug
self.handleSeed = None
self.handleSeed = None
# Class Settings
self.projTree = None
self.treeOrder = None
self.treeRoots = None
self.trashRoot = None
self.projPath = None
self.projMeta = None
self.projCache = None
self.projFile = None
self.projTree = None
self.treeOrder = None
self.treeRoots = None
self.trashRoot = None
self.projPath = None
self.projMeta = None
self.projCache = None
self.projFile = None
# Project Meta
self.projName = None
self.bookTitle = None
self.bookAuthors = None
self.projName = None
self.bookTitle = None
self.bookAuthors = None
# Various
self.autoReplace = None
# Project Settings
self.spellCheck = False
self.statusItems = None
self.importItems = None
self.lastEdited = None
self.lastViewed = None
self.lastWCount = 0
self.currWCount = 0
self.spellCheck = False
self.statusItems = None
self.importItems = None
self.lastEdited = None
self.lastViewed = None
self.lastWCount = 0
self.currWCount = 0
# Set Defaults
self.clearProject()
@@ -150,6 +153,7 @@ class NWProject():
self.projName = ""
self.bookTitle = ""
self.bookAuthors = []
self.autoReplace = {}
self.spellCheck = False
self.statusItems = NWStatus()
self.statusItems.addEntry("New", (100,100,100))
@@ -220,16 +224,19 @@ class NWProject():
if xItem.text is None: continue
if xItem.tag == "spellCheck":
self.spellCheck = checkBool(xItem.text,False)
if xItem.tag == "lastEdited":
elif xItem.tag == "lastEdited":
self.lastEdited = checkString(xItem.text,None,True)
if xItem.tag == "lastViewed":
elif xItem.tag == "lastViewed":
self.lastViewed = checkString(xItem.text,None,True)
if xItem.tag == "lastWordCount":
elif xItem.tag == "lastWordCount":
self.lastWCount = checkInt(xItem.text,0,False)
if xItem.tag == "status":
elif xItem.tag == "status":
self.statusItems.unpackEntries(xItem)
if xItem.tag == "importance":
elif xItem.tag == "importance":
self.importItems.unpackEntries(xItem)
elif xItem.tag == "autoReplace":
for xEntry in xItem:
self.autoReplace[xEntry.tag] = checkString(xEntry.text,None,False)
elif xChild.tag == "content":
logger.debug("Found project content")
for xItem in xChild:
@@ -292,6 +299,10 @@ class NWProject():
self._saveProjectValue(xSettings,"lastEdited", self.lastEdited)
self._saveProjectValue(xSettings,"lastViewed", self.lastViewed)
self._saveProjectValue(xSettings,"lastWordCount",self.currWCount)
xAutoRep = etree.SubElement(xSettings,"autoReplace")
for aKey, aValue in self.autoReplace.items():
if len(aKey) > 0:
self._saveProjectValue(xAutoRep,aKey,aValue)
xStatus = etree.SubElement(xSettings,"status")
self.statusItems.packEntries(xStatus)
@@ -401,7 +412,7 @@ class NWProject():
self.setProjectChanged(True)
return
def setImportColours(self, newCols,):
def setImportColours(self, newCols):
replaceMap = self.importItems.setNewEntries(newCols)
if self.projTree is not None:
for nwItem in self.projTree.values():
@@ -411,6 +422,10 @@ class NWProject():
self.setProjectChanged(True)
return
def setAutoReplace(self, autoReplace):
self.autoReplace = autoReplace
return
def setProjectChanged(self, bValue):
self.projChanged = bValue
self.theParent.setProjectStatus(self.projChanged)
+11
View File
@@ -171,3 +171,14 @@ Start: 2019-06-04 23:01:25 End: 2019-06-04 23:02:29 Words: 0
Start: 2019-06-04 23:09:01 End: 2019-06-04 23:10:26 Words: 0
Start: 2019-06-04 23:12:15 End: 2019-06-04 23:16:42 Words: 0
Start: 2019-06-04 23:18:50 End: 2019-06-04 23:19:16 Words: 0
Start: 2019-06-08 16:44:12 End: 2019-06-08 16:45:11 Words: -565
Start: 2019-06-08 18:54:03 End: 2019-06-08 18:54:45 Words: -565
Start: 2019-06-08 18:57:25 End: 2019-06-08 18:57:37 Words: -565
Start: 2019-06-08 19:03:33 End: 2019-06-08 19:04:20 Words: 0
Start: 2019-06-08 19:05:20 End: 2019-06-08 19:05:46 Words: 0
Start: 2019-06-08 19:06:44 End: 2019-06-08 19:07:35 Words: 0
Start: 2019-06-08 19:14:43 End: 2019-06-08 19:15:11 Words: 0
Start: 2019-06-08 19:20:15 End: 2019-06-08 19:20:41 Words: 0
Start: 2019-06-08 19:54:27 End: 2019-06-08 19:54:38 Words: 0
Start: 2019-06-08 19:58:46 End: 2019-06-08 19:58:50 Words: 0
Start: 2019-06-08 20:01:07 End: 2019-06-08 20:01:18 Words: 0
+6 -2
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.4" fileVersion="1.0" timeStamp="2019-06-04 23:19:16">
<novelWriterXML appVersion="0.1.4" fileVersion="1.0" timeStamp="2019-06-08 20:01:18">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
@@ -10,7 +10,11 @@
<spellCheck>True</spellCheck>
<lastEdited>636b6aa9b697b</lastEdited>
<lastViewed>None</lastViewed>
<lastWordCount>565</lastWordCount>
<lastWordCount>0</lastWordCount>
<autoReplace>
<A>B</A>
<C>D</C>
</autoReplace>
<status>
<entry blue="100" green="100" red="100">New</entry>
<entry blue="0" green="50" red="200">Notes</entry>