Added the option to show tabs and spaces and line endings.

This commit is contained in:
Veronica K. B. Olsen
2019-10-29 18:38:16 +01:00
parent e2b8ce1f89
commit 9fb28281f3
3 changed files with 82 additions and 44 deletions
+22 -16
View File
@@ -86,6 +86,8 @@ class Config:
self.doReplaceDash = True
self.doReplaceDots = True
self.wordCountTimer = 5.0
self.showTabsNSpaces = False
self.showLineEndings = False
self.fmtSingleQuotes = [nwUnicode.U_LSQUO,nwUnicode.U_RSQUO]
self.fmtDoubleQuotes = [nwUnicode.U_LDQUO,nwUnicode.U_RDQUO]
@@ -233,6 +235,8 @@ class Config:
self.fmtSingleQuotes = self._parseLine(cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes)
self.fmtDoubleQuotes = self._parseLine(cnfParse, cnfSec, "fmtdoublequote", self.CNF_LIST, self.fmtDoubleQuotes)
self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage)
self.showTabsNSpaces = self._parseLine(cnfParse, cnfSec, "showtabsnspaces", self.CNF_BOOL, self.showTabsNSpaces)
self.showLineEndings = self._parseLine(cnfParse, cnfSec, "showlineendings", self.CNF_BOOL, self.showLineEndings)
## Backup
cnfSec = "Backup"
@@ -282,22 +286,24 @@ class Config:
## Editor
cnfSec = "Editor"
cnfParse.add_section(cnfSec)
cnfParse.set(cnfSec,"textfont", str(self.textFont))
cnfParse.set(cnfSec,"textsize", str(self.textSize))
cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW))
cnfParse.set(cnfSec,"width", str(self.textWidth))
cnfParse.set(cnfSec,"margin", str(self.textMargin))
cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth))
cnfParse.set(cnfSec,"justify", str(self.doJustify))
cnfParse.set(cnfSec,"autoselect", str(self.autoSelect))
cnfParse.set(cnfSec,"autoreplace", str(self.doReplace))
cnfParse.set(cnfSec,"repsquotes", str(self.doReplaceSQuote))
cnfParse.set(cnfSec,"repdquotes", str(self.doReplaceDQuote))
cnfParse.set(cnfSec,"repdash", str(self.doReplaceDash))
cnfParse.set(cnfSec,"repdots", str(self.doReplaceDots))
cnfParse.set(cnfSec,"fmtsinglequote",self._packList(self.fmtSingleQuotes))
cnfParse.set(cnfSec,"fmtdoublequote",self._packList(self.fmtDoubleQuotes))
cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage))
cnfParse.set(cnfSec,"textfont", str(self.textFont))
cnfParse.set(cnfSec,"textsize", str(self.textSize))
cnfParse.set(cnfSec,"fixedwidth", str(self.textFixedW))
cnfParse.set(cnfSec,"width", str(self.textWidth))
cnfParse.set(cnfSec,"margin", str(self.textMargin))
cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth))
cnfParse.set(cnfSec,"justify", str(self.doJustify))
cnfParse.set(cnfSec,"autoselect", str(self.autoSelect))
cnfParse.set(cnfSec,"autoreplace", str(self.doReplace))
cnfParse.set(cnfSec,"repsquotes", str(self.doReplaceSQuote))
cnfParse.set(cnfSec,"repdquotes", str(self.doReplaceDQuote))
cnfParse.set(cnfSec,"repdash", str(self.doReplaceDash))
cnfParse.set(cnfSec,"repdots", str(self.doReplaceDots))
cnfParse.set(cnfSec,"fmtsinglequote", self._packList(self.fmtSingleQuotes))
cnfParse.set(cnfSec,"fmtdoublequote", self._packList(self.fmtDoubleQuotes))
cnfParse.set(cnfSec,"spellcheck", str(self.spellLanguage))
cnfParse.set(cnfSec,"showtabsnspaces", str(self.showTabsNSpaces))
cnfParse.set(cnfSec,"showlineendings", str(self.showLineEndings))
## Backup
cnfSec = "Backup"
+52 -27
View File
@@ -200,27 +200,25 @@ class GuiConfigEditGeneral(QWidget):
self.projBackupGetPath = QPushButton(self.theTheme.getIcon("folder"),"")
self.projBackupGetPath.clicked.connect(self._backupFolder)
self.projBackupClose = QCheckBox(self)
self.projBackupClose = QCheckBox("Run on close",self)
self.projBackupClose.setToolTip("Backup automatically on project close.")
if self.mainConf.backupOnClose:
self.projBackupClose.setCheckState(Qt.Checked)
else:
self.projBackupClose.setCheckState(Qt.Unchecked)
self.projBackupAsk = QCheckBox(self)
self.projBackupAsk = QCheckBox("Ask before backup",self)
self.projBackupAsk.setToolTip("Ask before backup.")
if self.mainConf.askBeforeBackup:
self.projBackupAsk.setCheckState(Qt.Checked)
else:
self.projBackupAsk.setCheckState(Qt.Unchecked)
self.projBackupForm.addWidget(QLabel("Backup Folder"), 0, 0)
self.projBackupForm.addWidget(self.projBackupPath, 0, 1, 1, 3)
self.projBackupForm.addWidget(self.projBackupGetPath, 0, 4)
self.projBackupForm.addWidget(QLabel("Run on Close"), 1, 0)
self.projBackupForm.addWidget(self.projBackupClose, 1, 1)
self.projBackupForm.addWidget(QLabel("Ask Before Backuo"), 1, 2)
self.projBackupForm.addWidget(self.projBackupAsk, 1, 3)
self.projBackupForm.addWidget(QLabel("Backup folder"), 0, 0)
self.projBackupForm.addWidget(self.projBackupPath, 0, 1)
self.projBackupForm.addWidget(self.projBackupGetPath, 0, 2)
self.projBackupForm.addWidget(self.projBackupClose, 1, 0)
self.projBackupForm.addWidget(self.projBackupAsk, 1, 1, 1, 2)
# Assemble
self.outerBox.addWidget(self.guiLook, 0, 0)
@@ -311,7 +309,7 @@ class GuiConfigEditEditor(QWidget):
self.textStyleSize.setSingleStep(1)
self.textStyleSize.setValue(self.mainConf.textSize)
self.textStyleForm.addWidget(QLabel("Font Family"), 0, 0)
self.textStyleForm.addWidget(QLabel("Font family"), 0, 0)
self.textStyleForm.addWidget(self.textStyleFont, 0, 1)
self.textStyleForm.addWidget(QLabel("Size"), 0, 2)
self.textStyleForm.addWidget(self.textStyleSize, 0, 3)
@@ -322,7 +320,7 @@ class GuiConfigEditEditor(QWidget):
self.textFlowForm = QGridLayout(self)
self.textFlow.setLayout(self.textFlowForm)
self.textFlowFixed = QCheckBox(self)
self.textFlowFixed = QCheckBox("Fixed width",self)
self.textFlowFixed.setToolTip("Make text in editor fixed width and scale margins instead.")
if self.mainConf.textFixedW:
self.textFlowFixed.setCheckState(Qt.Checked)
@@ -334,19 +332,17 @@ class GuiConfigEditEditor(QWidget):
self.textFlowWidth.setSingleStep(10)
self.textFlowWidth.setValue(self.mainConf.textWidth)
self.textFlowJustify = QCheckBox(self)
self.textFlowJustify = QCheckBox("Justify text",self)
self.textFlowJustify.setToolTip("Justify text in main document editor.")
if self.mainConf.doJustify:
self.textFlowJustify.setCheckState(Qt.Checked)
else:
self.textFlowJustify.setCheckState(Qt.Unchecked)
self.textFlowForm.addWidget(QLabel("Fixed Width"), 0, 0)
self.textFlowForm.addWidget(self.textFlowFixed, 0, 1)
self.textFlowForm.addWidget(self.textFlowWidth, 0, 2)
self.textFlowForm.addWidget(QLabel("px"), 0, 3)
self.textFlowForm.addWidget(QLabel("Justify Text"), 1, 0)
self.textFlowForm.addWidget(self.textFlowJustify, 1, 1)
self.textFlowForm.addWidget(self.textFlowFixed, 0, 0)
self.textFlowForm.addWidget(self.textFlowWidth, 0, 1)
self.textFlowForm.addWidget(QLabel("px"), 0, 2)
self.textFlowForm.addWidget(self.textFlowJustify, 1, 0)
self.textFlowForm.setColumnStretch(4, 1)
# Text Margins
@@ -365,11 +361,12 @@ class GuiConfigEditEditor(QWidget):
self.textMarginTab.setMaximum(200)
self.textMarginTab.setSingleStep(1)
self.textMarginTab.setValue(self.mainConf.tabWidth)
self.textMarginTab.setToolTip("Requires Qt 5.9 or later.")
self.textMarginForm.addWidget(QLabel("Document"), 0, 0)
self.textMarginForm.addWidget(self.textMarginDoc, 0, 1)
self.textMarginForm.addWidget(QLabel("px"), 0, 2)
self.textMarginForm.addWidget(QLabel("Tab Width"), 2, 0)
self.textMarginForm.addWidget(QLabel("Tab width"), 2, 0)
self.textMarginForm.addWidget(self.textMarginTab, 2, 1)
self.textMarginForm.addWidget(QLabel("px"), 2, 2)
self.textMarginForm.setColumnStretch(4, 1)
@@ -421,19 +418,20 @@ class GuiConfigEditEditor(QWidget):
else:
self.autoReplaceDots.setCheckState(Qt.Unchecked)
self.autoReplaceForm.addWidget(QLabel("Auto-Select Text"), 0, 0)
self.autoReplaceForm.addWidget(QLabel("Auto-select text"), 0, 0)
self.autoReplaceForm.addWidget(self.autoSelect, 0, 1)
self.autoReplaceForm.addWidget(QLabel("Auto-Replace:"), 1, 0)
self.autoReplaceForm.addWidget(QLabel("Auto-replace:"), 1, 0)
self.autoReplaceForm.addWidget(self.autoReplaceMain, 1, 1)
self.autoReplaceForm.addWidget(QLabel("\u2192 Single Quotes"), 2, 0)
self.autoReplaceForm.addWidget(QLabel("\u2192 Single quotes"), 2, 0)
self.autoReplaceForm.addWidget(self.autoReplaceSQ, 2, 1)
self.autoReplaceForm.addWidget(QLabel("\u2192 Double Quotes"), 3, 0)
self.autoReplaceForm.addWidget(QLabel("\u2192 Double quotes"), 3, 0)
self.autoReplaceForm.addWidget(self.autoReplaceDQ, 3, 1)
self.autoReplaceForm.addWidget(QLabel("\u2192 Hyphens with Dash"), 4, 0)
self.autoReplaceForm.addWidget(QLabel("\u2192 Hyphens with dash"), 4, 0)
self.autoReplaceForm.addWidget(self.autoReplaceDash, 4, 1)
self.autoReplaceForm.addWidget(QLabel("\u2192 Dots with Ellipsis"), 5, 0)
self.autoReplaceForm.addWidget(QLabel("\u2192 Dots with ellipsis"), 5, 0)
self.autoReplaceForm.addWidget(self.autoReplaceDots, 5, 1)
self.autoReplaceForm.setColumnStretch(2, 1)
self.autoReplaceForm.setRowStretch(6, 1)
# Quote Style
self.quoteStyle = QGroupBox("Quotation Style", self)
@@ -477,12 +475,33 @@ class GuiConfigEditEditor(QWidget):
self.quoteStyleForm.setColumnStretch(4, 1)
self.quoteStyleForm.setRowStretch(4, 1)
# Writing Guides
self.showGuides = QGroupBox("Writing Guides", self)
self.showGuidesForm = QGridLayout(self)
self.showGuides.setLayout(self.showGuidesForm)
self.showTabsNSpaces = QCheckBox("Show tabs and spaces",self)
if self.mainConf.showTabsNSpaces:
self.showTabsNSpaces.setCheckState(Qt.Checked)
else:
self.showTabsNSpaces.setCheckState(Qt.Unchecked)
self.showLineEndings = QCheckBox("Show line endings",self)
if self.mainConf.showTabsNSpaces:
self.showLineEndings.setCheckState(Qt.Checked)
else:
self.showLineEndings.setCheckState(Qt.Unchecked)
self.showGuidesForm.addWidget(self.showTabsNSpaces, 0, 0)
self.showGuidesForm.addWidget(self.showLineEndings, 1, 0)
# Assemble
self.outerBox.addWidget(self.textStyle, 0, 0, 1, 2)
self.outerBox.addWidget(self.textFlow, 1, 0)
self.outerBox.addWidget(self.textMargin, 1, 1)
self.outerBox.addWidget(self.autoReplace, 2, 0)
self.outerBox.addWidget(self.quoteStyle, 2, 1)
self.outerBox.addWidget(self.quoteStyle, 2, 0)
self.outerBox.addWidget(self.autoReplace, 2, 1, 2, 1)
self.outerBox.addWidget(self.showGuides, 3, 0)
self.outerBox.setColumnStretch(2, 1)
self.setLayout(self.outerBox)
@@ -555,6 +574,12 @@ class GuiConfigEditEditor(QWidget):
self.theParent.makeAlert("Invalid quote symbol: %s" % fmtDoubleQuotesC, nwAlert.ERROR)
validEntries = False
showTabsNSpaces = self.showTabsNSpaces.isChecked()
showLineEndings = self.showLineEndings.isChecked()
self.mainConf.showTabsNSpaces = showTabsNSpaces
self.mainConf.showLineEndings = showLineEndings
self.mainConf.confChanged = True
return validEntries, False
+8 -1
View File
@@ -126,7 +126,7 @@ class GuiDocEditor(QTextEdit):
# Reload dictionaries
self.setDictionaries()
# Set Font
# Set font
theFont = QFont()
if self.mainConf.textFont is None:
# If none is defined, set the default back to config
@@ -145,13 +145,20 @@ class GuiDocEditor(QTextEdit):
# Also set the document text options for the document text flow
theOpt = QTextOption()
if self.mainConf.tabWidth is not None:
if self.mainConf.verQtValue >= 51000:
theOpt.setTabStopDistance(self.mainConf.tabWidth)
if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify)
if self.mainConf.showTabsNSpaces:
theOpt.setFlags(theOpt.flags() | QTextOption.ShowTabsAndSpaces)
if self.mainConf.showLineEndings:
theOpt.setFlags(theOpt.flags() | QTextOption.ShowLineAndParagraphSeparators)
self.qDocument.setDefaultTextOption(theOpt)
# Initialise the syntax highlighter
self.hLight.initHighlighter()
# If we have a document open, we should reload it in case the font changed