Skip to content

Commit ec9e478

Browse files
committed
Improve dialogue line symbol setting box (#2453)
1 parent dadc7ed commit ec9e478

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

novelwriter/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def uniqueCompact(text: str) -> str:
301301
def processDialogSymbols(symbols: str) -> str:
302302
"""Process dialogue line symbols."""
303303
result = ""
304-
for c in uniqueCompact(symbols):
304+
for c in uniqueCompact("".join(symbols.split())):
305305
if c in nwQuotes.ALLOWED:
306306
result += c
307307
return result

novelwriter/dialogs/preferences.py

Lines changed: 25 additions & 5 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

@@ -639,14 +639,26 @@ def buildForm(self) -> None:
639639
)
640640

641641
# 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+
)
649+
642650
self.dialogLine = QLineEdit(self)
643-
self.dialogLine.setMaxLength(4)
644-
self.dialogLine.setFixedWidth(boxFixed)
651+
self.dialogLine.setMinimumWidth(100)
645652
self.dialogLine.setAlignment(QtAlignCenter)
646-
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+
647658
self.mainForm.addRow(
648659
self.tr("Dialogue line symbols"), self.dialogLine,
649-
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
650662
)
651663

652664
# Narrator Break
@@ -913,6 +925,14 @@ def _toggledBackupOnClose(self, state: bool) -> None:
913925
self.askBeforeBackup.setEnabled(state)
914926
return
915927

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+
916936
@pyqtSlot(bool)
917937
def _toggleAutoReplaceMain(self, state: bool) -> None:
918938
"""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)