Add format and insert features (#1214)

This commit is contained in:
Veronica Berglyd Olsen
2022-10-29 01:33:42 +02:00
committed by GitHub
7 changed files with 53 additions and 33 deletions
+1
View File
@@ -137,6 +137,7 @@ a key or key combination for the inserted content.
":kbd:`Ctrl`:kbd:`K`, :kbd:`F`", "Insert a ``@focus`` keyword."
":kbd:`Ctrl`:kbd:`K`, :kbd:`C`", "Insert a ``@char`` keyword."
":kbd:`Ctrl`:kbd:`K`, :kbd:`P`", "Insert a ``@plot`` keyword."
":kbd:`Ctrl`:kbd:`K`, :kbd:`S`", "Insert a synopsis comment."
":kbd:`Ctrl`:kbd:`K`, :kbd:`T`", "Insert a ``@time`` keyword."
":kbd:`Ctrl`:kbd:`K`, :kbd:`L`", "Insert a ``@location`` keyword."
":kbd:`Ctrl`:kbd:`K`, :kbd:`O`", "Insert an ``@object`` keyword."
+4 -4
View File
@@ -183,7 +183,7 @@ class GuiPreferencesGeneral(QWidget):
self.mainForm.addRow(
self.tr("Main GUI language"),
self.guiLang,
self.tr("Requires restart.")
self.tr("Requires restart to take effect.")
)
# Select Theme
@@ -199,7 +199,7 @@ class GuiPreferencesGeneral(QWidget):
self.mainForm.addRow(
self.tr("Main GUI theme"),
self.guiTheme,
self.tr("Requires restart.")
self.tr("General colour theme and icons.")
)
# Editor Theme
@@ -229,7 +229,7 @@ class GuiPreferencesGeneral(QWidget):
self.mainForm.addRow(
self.tr("Font family"),
self.guiFont,
self.tr("Requires restart."),
self.tr("Requires restart to take effect."),
theButton=self.fontButton
)
@@ -242,7 +242,7 @@ class GuiPreferencesGeneral(QWidget):
self.mainForm.addRow(
self.tr("Font size"),
self.guiFontSize,
self.tr("Requires restart."),
self.tr("Requires restart to take effect."),
theUnit=self.tr("pt")
)
+4 -3
View File
@@ -112,9 +112,10 @@ class nwDocInsert(Enum):
QUOTE_RS = 2
QUOTE_LD = 3
QUOTE_RD = 4
NEW_PAGE = 5
VSPACE_S = 6
VSPACE_M = 7
SYNOPSIS = 5
NEW_PAGE = 6
VSPACE_S = 7
VSPACE_M = 8
# END Enum nwDocInsert
+10 -6
View File
@@ -877,6 +877,7 @@ class GuiDocEditor(QTextEdit):
return False
newBlock = False
goAfter = False
if isinstance(theInsert, str):
theText = theInsert
@@ -889,22 +890,29 @@ class GuiDocEditor(QTextEdit):
theText = self._typDQOpen
elif theInsert == nwDocInsert.QUOTE_RD:
theText = self._typDQClose
elif theInsert == nwDocInsert.SYNOPSIS:
theText = "% Synopsis: "
newBlock = True
goAfter = True
elif theInsert == nwDocInsert.NEW_PAGE:
theText = "[NEW PAGE]"
newBlock = True
goAfter = False
elif theInsert == nwDocInsert.VSPACE_S:
theText = "[VSPACE]"
newBlock = True
goAfter = False
elif theInsert == nwDocInsert.VSPACE_M:
theText = "[VSPACE:2]"
newBlock = True
goAfter = False
else:
return False
else:
return False
if newBlock:
self.insertNewBlock(theText, defaultAfter=False)
self.insertNewBlock(theText, defaultAfter=goAfter)
else:
theCursor = self.textCursor()
theCursor.beginEditBlock()
@@ -1709,12 +1717,8 @@ class GuiDocEditor(QTextEdit):
logger.debug("Invalid block selected for action '%s'", str(docAction))
return False
theText = theBlock.text()
if len(theText.strip()) == 0:
logger.debug("Empty block selected for action '%s'", str(docAction))
return False
# Remove existing format first, if any
theText = theBlock.text()
if theText.startswith("@"):
logger.error("Cannot apply block format to keyword/value line")
return False
+9
View File
@@ -554,6 +554,15 @@ class GuiMainMenu(QMenuBar):
)
self.mInsKeywords.addAction(self.mInsKWItems[keyWord][0])
# Insert > Special Comments
self.mInsComments = self.insertMenu.addMenu(self.tr("Special Comments"))
# Insert > Synopsis Comment
self.aInsSynopsis = QAction(self.tr("Synopsis Comment"), self)
self.aInsSynopsis.setShortcut("Ctrl+K, S")
self.aInsSynopsis.triggered.connect(lambda: self._docInsert(nwDocInsert.SYNOPSIS))
self.mInsComments.addAction(self.aInsSynopsis)
# Insert > Symbols
self.mInsBreaks = self.insertMenu.addMenu(self.tr("Page Break and Space"))
-4
View File
@@ -783,10 +783,6 @@ def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumTex
mp.setattr(QTextBlock, "isValid", lambda *a, **k: False)
assert nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT) is False
# Empty Block
assert nwGUI.docEditor.setCursorLine(1) is True
assert nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT) is False
# Keyword
assert nwGUI.docEditor.replaceText("@pov: Jane\n\n") is True
assert nwGUI.docEditor.setCursorPosition(5) is True
+25 -16
View File
@@ -116,6 +116,16 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, nwLipsum):
fmtStr = "#### Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[39:91] == fmtStr
# Title Format
nwGUI.mainMenu.aFmtTitle.activate(QAction.Trigger)
fmtStr = "#! Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[39:89] == fmtStr
# Unnumbered Chapter
nwGUI.mainMenu.aFmtUnNum.activate(QAction.Trigger)
fmtStr = "##! Pellentesque nec erat ut nulla posuere commodo."
assert nwGUI.docEditor.getText()[39:90] == fmtStr
# Clear Format
nwGUI.mainMenu.aFmtNoFormat.activate(QAction.Trigger)
assert nwGUI.docEditor.getText()[39:86] == cleanText
@@ -314,10 +324,6 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, nwLipsum):
assert nwGUI.docEditor.setCursorPosition(17)
assert not nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT)
# Cannot Format Empty Line
assert nwGUI.docEditor.setCursorPosition(13)
assert not nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT)
# Invalid Action
assert nwGUI.docEditor.setCursorPosition(30)
assert not nwGUI.docEditor._formatBlock(nwDocAction.NO_ACTION)
@@ -531,9 +537,8 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
assert nwGUI.docEditor.getText() == nwUnicode.U_THNBSP
nwGUI.docEditor.clear()
##
# Insert Keywords
##
# Insert Keywords
# ===============
nwGUI.docEditor.setText("Stuff")
nwGUI.mainMenu.mInsKWItems[nwKeyWords.TAG_KEY][0].activate(QAction.Trigger)
@@ -583,9 +588,15 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
nwGUI.docEditor.clear()
##
# Insert Break or Space
##
# Insert Special Comments
# =======================
nwGUI.docEditor.setText("Stuff\n")
nwGUI.mainMenu.aInsSynopsis.activate(QAction.Trigger)
assert nwGUI.docEditor.getText() == "Stuff\n% Synopsis: \n"
# Insert Break or Space
# =====================
nwGUI.docEditor.setText("### Stuff\n")
nwGUI.mainMenu.aInsNewPage.activate(QAction.Trigger)
@@ -601,9 +612,8 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
nwGUI.docEditor.clear()
##
# Insert text from file
##
# Insert Text from File
# =====================
nwGUI.closeDocument()
@@ -639,9 +649,8 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
nwGUI.mainMenu.aImportFile.activate(QAction.Trigger)
assert nwGUI.docEditor.getText() == "Foo"
##
# Reveal file location
##
# Reveal File Location
# ====================
theMessage = ""