Added some smart filters for quote settings
This commit is contained in:
@@ -577,6 +577,15 @@ class Config:
|
||||
# Check Certain Values for None
|
||||
self.spellLanguage = self._checkNone(self.spellLanguage)
|
||||
|
||||
# If we're using straight quotes, disable auto-replace
|
||||
if self.fmtSingleQuotes == ["'", "'"] and self.doReplaceSQuote:
|
||||
logger.info("Using straight single quotes, so disabling auto-replace")
|
||||
self.doReplaceSQuote = False
|
||||
|
||||
if self.fmtDoubleQuotes == ["\"", "\""] and self.doReplaceDQuote:
|
||||
logger.info("Using straight double quotes, so disabling auto-replace")
|
||||
self.doReplaceDQuote = False
|
||||
|
||||
return True
|
||||
|
||||
def saveConfig(self):
|
||||
|
||||
+17
-12
@@ -147,24 +147,29 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
|
||||
# Quoted Strings
|
||||
if self.mainConf.highlightQuotes:
|
||||
fmtDO = self.mainConf.fmtDoubleQuotes[0]
|
||||
fmtDC = self.mainConf.fmtDoubleQuotes[1]
|
||||
fmtSO = self.mainConf.fmtSingleQuotes[0]
|
||||
fmtSC = self.mainConf.fmtSingleQuotes[1]
|
||||
fmtDbl = self.mainConf.fmtDoubleQuotes
|
||||
fmtSng = self.mainConf.fmtSingleQuotes
|
||||
|
||||
# Straight Quotes
|
||||
if fmtDbl != ["\"", "\""]:
|
||||
self.hRules.append((
|
||||
"(\\B\")(.*?)(\"\\B)", {
|
||||
0 : self.hStyles["dialogue1"],
|
||||
}
|
||||
))
|
||||
|
||||
# Double Quotes
|
||||
dblEnd = "|$" if self.mainConf.allowOpenDQuote else ""
|
||||
sngEnd = "|$" if self.mainConf.allowOpenSQuote else ""
|
||||
self.hRules.append((
|
||||
"\\B\"(.*?)\"\\B", {
|
||||
0 : self.hStyles["dialogue1"],
|
||||
}
|
||||
))
|
||||
self.hRules.append((
|
||||
f"(\\B{fmtDO})(.*?)({fmtDC}\\B{dblEnd})", {
|
||||
f"(\\B{fmtDbl[0]})(.*?)({fmtDbl[1]}\\B{dblEnd})", {
|
||||
0 : self.hStyles["dialogue2"],
|
||||
}
|
||||
))
|
||||
|
||||
# Single Quotes
|
||||
sngEnd = "|$" if self.mainConf.allowOpenSQuote else ""
|
||||
self.hRules.append((
|
||||
f"(\\B{fmtSO})(.*?)({fmtSC}\\B{sngEnd})", {
|
||||
f"(\\B{fmtSng[0]})(.*?)({fmtSng[1]}\\B{sngEnd})", {
|
||||
0 : self.hStyles["dialogue3"],
|
||||
}
|
||||
))
|
||||
|
||||
@@ -170,6 +170,28 @@ def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir):
|
||||
assert tstConf.loadConfig()
|
||||
assert tstConf.saveConfig()
|
||||
|
||||
# Test Correcting Quote Settings
|
||||
origDbl = tstConf.fmtDoubleQuotes
|
||||
origSng = tstConf.fmtSingleQuotes
|
||||
orDoDbl = tstConf.doReplaceDQuote
|
||||
orDoSng = tstConf.doReplaceSQuote
|
||||
|
||||
tstConf.fmtDoubleQuotes = ["\"", "\""]
|
||||
tstConf.fmtSingleQuotes = ["'", "'"]
|
||||
tstConf.doReplaceDQuote = True
|
||||
tstConf.doReplaceSQuote = True
|
||||
assert tstConf.saveConfig()
|
||||
|
||||
assert tstConf.loadConfig()
|
||||
assert not tstConf.doReplaceDQuote
|
||||
assert not tstConf.doReplaceSQuote
|
||||
|
||||
tstConf.fmtDoubleQuotes = origDbl
|
||||
tstConf.fmtSingleQuotes = origSng
|
||||
tstConf.doReplaceDQuote = orDoDbl
|
||||
tstConf.doReplaceSQuote = orDoSng
|
||||
assert tstConf.saveConfig()
|
||||
|
||||
copyfile(confFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [2, 9])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user