Skip to content

Commit 367bb2e

Browse files
authored
Improve dialogue highlighting settings (#2457)
2 parents e41f6a5 + a748a69 commit 367bb2e

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

novelwriter/dialogs/preferences.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from PyQt6.QtCore import Qt, pyqtSignal, pyqtSlot
3030
from PyQt6.QtGui import QAction, QCloseEvent, QKeyEvent, QKeySequence
3131
from PyQt6.QtWidgets import (
32-
QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout, QLineEdit,
32+
QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout, QLineEdit, QMenu,
3333
QPushButton, QVBoxLayout, QWidget
3434
)
3535

@@ -600,6 +600,7 @@ def buildForm(self) -> None:
600600
self.sidebar.addButton(title, section)
601601
self.mainForm.addGroupLabel(title, section)
602602

603+
# Dialogue Quotes
603604
self.dialogStyle = NComboBox(self)
604605
self.dialogStyle.addItem(self.tr("None"), 0)
605606
self.dialogStyle.addItem(self.tr("Single Quotes"), 1)
@@ -611,6 +612,15 @@ def buildForm(self) -> None:
611612
self.tr("Applies to the selected quote styles.")
612613
)
613614

615+
# Open-Ended Dialogue
616+
self.allowOpenDial = NSwitch(self)
617+
self.allowOpenDial.setChecked(CONFIG.allowOpenDial)
618+
self.mainForm.addRow(
619+
self.tr("Allow open-ended dialogue"), self.allowOpenDial,
620+
self.tr("Highlight dialogue line with no closing quote.")
621+
)
622+
623+
# Alternative Dialogue
614624
self.altDialogOpen = QLineEdit(self)
615625
self.altDialogOpen.setMaxLength(4)
616626
self.altDialogOpen.setFixedWidth(boxFixed)
@@ -628,23 +638,30 @@ def buildForm(self) -> None:
628638
self.tr("Custom highlighting of dialogue text.")
629639
)
630640

631-
self.allowOpenDial = NSwitch(self)
632-
self.allowOpenDial.setChecked(CONFIG.allowOpenDial)
633-
self.mainForm.addRow(
634-
self.tr("Allow open-ended dialogue"), self.allowOpenDial,
635-
self.tr("Highlight dialogue line with no closing quote.")
636-
)
641+
# Dialogue Line
642+
self.mnLineSymbols = QMenu(self)
643+
for symbol in nwQuotes.ALLOWED:
644+
label = trConst(nwQuotes.SYMBOLS.get(symbol, nwQuotes.DASHES.get(symbol, "None")))
645+
self.mnLineSymbols.addAction(
646+
f"[ {symbol } ] {label}",
647+
lambda symbol=symbol: self._insertDialogLineSymbol(symbol)
648+
)
637649

638650
self.dialogLine = QLineEdit(self)
639-
self.dialogLine.setMaxLength(4)
640-
self.dialogLine.setFixedWidth(boxFixed)
651+
self.dialogLine.setMinimumWidth(100)
641652
self.dialogLine.setAlignment(QtAlignCenter)
642-
self.dialogLine.setText(CONFIG.dialogLine)
653+
self.dialogLine.setText(" ".join(CONFIG.dialogLine))
654+
655+
self.dialogLineButton = NIconToolButton(self, iSz, "add", "green")
656+
self.dialogLineButton.setMenu(self.mnLineSymbols)
657+
643658
self.mainForm.addRow(
644659
self.tr("Dialogue line symbols"), self.dialogLine,
645-
self.tr("Lines starting with any of these symbols are dialogue.")
660+
self.tr("Lines starting with any of these symbols are dialogue."),
661+
button=self.dialogLineButton
646662
)
647663

664+
# Narrator Break
648665
self.narratorBreak = NComboBox(self)
649666
self.narratorDialog = NComboBox(self)
650667
for key, value in nwQuotes.DASHES.items():
@@ -664,13 +681,15 @@ def buildForm(self) -> None:
664681
self.tr("Alternates dialogue highlighting within any paragraph.")
665682
)
666683

684+
# Emphasis
667685
self.highlightEmph = NSwitch(self)
668686
self.highlightEmph.setChecked(CONFIG.highlightEmph)
669687
self.mainForm.addRow(
670688
self.tr("Add highlight colour to emphasised text"), self.highlightEmph,
671689
self.tr("Applies to the document editor only.")
672690
)
673691

692+
# Additional Spaces
674693
self.showMultiSpaces = NSwitch(self)
675694
self.showMultiSpaces.setChecked(CONFIG.showMultiSpaces)
676695
self.mainForm.addRow(
@@ -906,6 +925,14 @@ def _toggledBackupOnClose(self, state: bool) -> None:
906925
self.askBeforeBackup.setEnabled(state)
907926
return
908927

928+
@pyqtSlot(str)
929+
def _insertDialogLineSymbol(self, symbol: str) -> None:
930+
"""Insert a symbol in the dialogue line box."""
931+
current = self.dialogLine.text()
932+
values = processDialogSymbols(f"{current} {symbol}")
933+
self.dialogLine.setText(" ".join(values))
934+
return
935+
909936
@pyqtSlot(bool)
910937
def _toggleAutoReplaceMain(self, state: bool) -> None:
911938
"""Toggle switches controlled by the auto replace switch."""

tests/test_dialogs/test_dlg_preferences.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,17 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
268268
# Text Highlighting
269269
prefs.dialogStyle.setCurrentData(3, 0)
270270
prefs.allowOpenDial.setChecked(False)
271-
prefs.dialogLine.setText("–")
272-
prefs.narratorBreak.setCurrentData("–", "")
273-
prefs.narratorDialog.setCurrentData("–", "")
271+
prefs.dialogLine.setText(nwUnicode.U_EMDASH)
272+
prefs.narratorBreak.setCurrentData(nwUnicode.U_EMDASH, "")
273+
prefs.narratorDialog.setCurrentData(nwUnicode.U_EMDASH, "")
274274
prefs.altDialogOpen.setText("%") # Symbol also tests for #2455
275275
prefs.altDialogClose.setText("%") # Symbol also tests for #2455
276276
prefs.highlightEmph.setChecked(False)
277277
prefs.showMultiSpaces.setChecked(False)
278278

279+
prefs._insertDialogLineSymbol(nwUnicode.U_ENDASH)
280+
assert prefs.dialogLine.text() == f"{nwUnicode.U_ENDASH} {nwUnicode.U_EMDASH}"
281+
279282
assert CONFIG.dialogStyle == 2
280283
assert CONFIG.allowOpenDial is True
281284
assert CONFIG.dialogLine == ""
@@ -398,9 +401,9 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
398401
# Text Highlighting
399402
assert CONFIG.dialogStyle == 3
400403
assert CONFIG.allowOpenDial is False
401-
assert CONFIG.dialogLine == "–"
402-
assert CONFIG.narratorBreak == "–"
403-
assert CONFIG.narratorDialog == "–"
404+
assert CONFIG.dialogLine == f"{nwUnicode.U_ENDASH}{nwUnicode.U_EMDASH}"
405+
assert CONFIG.narratorBreak == nwUnicode.U_EMDASH
406+
assert CONFIG.narratorDialog == nwUnicode.U_EMDASH
404407
assert CONFIG.altDialogOpen == "%"
405408
assert CONFIG.altDialogClose == "%"
406409
assert CONFIG.highlightEmph is False

0 commit comments

Comments
 (0)