Allow up to 4 dialogue line symbols

This commit is contained in:
Veronica Berglyd Olsen
2024-11-01 20:07:35 +01:00
parent d9582436d4
commit 66567b6d6f
2 changed files with 16 additions and 15 deletions
+8 -8
View File
@@ -34,7 +34,7 @@ from PyQt5.QtWidgets import (
) )
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.common import describeFont, uniqueCompact from novelwriter.common import compact, describeFont, uniqueCompact
from novelwriter.constants import nwUnicode from novelwriter.constants import nwUnicode
from novelwriter.dialogs.quotes import GuiQuoteSelect from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm from novelwriter.extensions.configlayout import NColourLabel, NScrollableForm
@@ -133,7 +133,7 @@ class GuiPreferences(NDialog):
"""Build the settings form.""" """Build the settings form."""
section = 0 section = 0
iSz = SHARED.theme.baseIconSize iSz = SHARED.theme.baseIconSize
boxFixed = 5*SHARED.theme.textNWidth boxFixed = 6*SHARED.theme.textNWidth
minWidth = CONFIG.pxInt(200) minWidth = CONFIG.pxInt(200)
fontWidth = CONFIG.pxInt(162) fontWidth = CONFIG.pxInt(162)
@@ -568,13 +568,13 @@ class GuiPreferences(NDialog):
) )
self.dialogLine = QLineEdit(self) self.dialogLine = QLineEdit(self)
self.dialogLine.setMaxLength(1) self.dialogLine.setMaxLength(4)
self.dialogLine.setFixedWidth(boxFixed) self.dialogLine.setFixedWidth(boxFixed)
self.dialogLine.setAlignment(QtAlignCenter) self.dialogLine.setAlignment(QtAlignCenter)
self.dialogLine.setText(CONFIG.dialogLine) self.dialogLine.setText(CONFIG.dialogLine)
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Dialogue line symbol"), self.dialogLine, self.tr("Dialogue line symbols"), self.dialogLine,
self.tr("Lines starting with this symbol are dialogue.") self.tr("Lines starting with these symbols are always dialogue.")
) )
self.narratorBreak = QLineEdit(self) self.narratorBreak = QLineEdit(self)
@@ -953,9 +953,9 @@ class GuiPreferences(NDialog):
dialogueStyle = self.dialogStyle.currentData() dialogueStyle = self.dialogStyle.currentData()
allowOpenDial = self.allowOpenDial.isChecked() allowOpenDial = self.allowOpenDial.isChecked()
narratorBreak = self.narratorBreak.text().strip() narratorBreak = self.narratorBreak.text().strip()
dialogueLine = self.dialogLine.text().strip() dialogueLine = uniqueCompact(self.dialogLine.text())
altDialogOpen = self.altDialogOpen.text() altDialogOpen = compact(self.altDialogOpen.text())
altDialogClose = self.altDialogClose.text() altDialogClose = compact(self.altDialogClose.text())
highlightEmph = self.highlightEmph.isChecked() highlightEmph = self.highlightEmph.isChecked()
showMultiSpaces = self.showMultiSpaces.isChecked() showMultiSpaces = self.showMultiSpaces.isChecked()
+8 -7
View File
@@ -26,6 +26,7 @@ from __future__ import annotations
import re import re
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.common import compact, uniqueCompact
from novelwriter.constants import nwRegEx from novelwriter.constants import nwRegEx
@@ -88,11 +89,11 @@ class RegExPatterns:
symO = "" symO = ""
symC = "" symC = ""
if CONFIG.dialogStyle in (1, 3): if CONFIG.dialogStyle in (1, 3):
symO += CONFIG.fmtSQuoteOpen symO += CONFIG.fmtSQuoteOpen.strip()[:1]
symC += CONFIG.fmtSQuoteClose symC += CONFIG.fmtSQuoteClose.strip()[:1]
if CONFIG.dialogStyle in (2, 3): if CONFIG.dialogStyle in (2, 3):
symO += CONFIG.fmtDQuoteOpen symO += CONFIG.fmtDQuoteOpen.strip()[:1]
symC += CONFIG.fmtDQuoteClose symC += CONFIG.fmtDQuoteClose.strip()[:1]
rxEnd = "|$" if CONFIG.allowOpenDial else "" rxEnd = "|$" if CONFIG.allowOpenDial else ""
return re.compile(f"\\B[{symO}].*?(?:[{symC}]\\B{rxEnd})", re.UNICODE) return re.compile(f"\\B[{symO}].*?(?:[{symC}]\\B{rxEnd})", re.UNICODE)
@@ -102,8 +103,8 @@ class RegExPatterns:
def altDialogStyle(self) -> re.Pattern | None: def altDialogStyle(self) -> re.Pattern | None:
"""Dialogue alternative rule based on user settings.""" """Dialogue alternative rule based on user settings."""
if CONFIG.altDialogOpen and CONFIG.altDialogClose: if CONFIG.altDialogOpen and CONFIG.altDialogClose:
symO = re.escape(CONFIG.altDialogOpen) symO = re.escape(compact(CONFIG.altDialogOpen))
symC = re.escape(CONFIG.altDialogClose) symC = re.escape(compact(CONFIG.altDialogClose))
return re.compile(f"\\B{symO}.*?{symC}\\B", re.UNICODE) return re.compile(f"\\B{symO}.*?{symC}\\B", re.UNICODE)
return None return None
@@ -132,7 +133,7 @@ class DialogParser:
"""Init parser settings. Must be called when config changes.""" """Init parser settings. Must be called when config changes."""
punct = re.escape("!?.,:;") punct = re.escape("!?.,:;")
self._quotes = REGEX_PATTERNS.dialogStyle self._quotes = REGEX_PATTERNS.dialogStyle
self._dialog = CONFIG.dialogLine self._dialog = uniqueCompact(CONFIG.dialogLine)
self._narrator = CONFIG.narratorBreak.strip()[:1] self._narrator = CONFIG.narratorBreak.strip()[:1]
self._break = re.compile( self._break = re.compile(
f"({self._narrator}\\s?.*?\\s?(?:{self._narrator}[{punct}]?|$))", re.UNICODE f"({self._narrator}\\s?.*?\\s?(?:{self._narrator}[{punct}]?|$))", re.UNICODE