Add format and insert features (#1214)
This commit is contained in:
@@ -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:`F`", "Insert a ``@focus`` keyword."
|
||||||
":kbd:`Ctrl`:kbd:`K`, :kbd:`C`", "Insert a ``@char`` 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:`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:`T`", "Insert a ``@time`` keyword."
|
||||||
":kbd:`Ctrl`:kbd:`K`, :kbd:`L`", "Insert a ``@location`` keyword."
|
":kbd:`Ctrl`:kbd:`K`, :kbd:`L`", "Insert a ``@location`` keyword."
|
||||||
":kbd:`Ctrl`:kbd:`K`, :kbd:`O`", "Insert an ``@object`` keyword."
|
":kbd:`Ctrl`:kbd:`K`, :kbd:`O`", "Insert an ``@object`` keyword."
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
self.mainForm.addRow(
|
self.mainForm.addRow(
|
||||||
self.tr("Main GUI language"),
|
self.tr("Main GUI language"),
|
||||||
self.guiLang,
|
self.guiLang,
|
||||||
self.tr("Requires restart.")
|
self.tr("Requires restart to take effect.")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Select Theme
|
# Select Theme
|
||||||
@@ -199,7 +199,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
self.mainForm.addRow(
|
self.mainForm.addRow(
|
||||||
self.tr("Main GUI theme"),
|
self.tr("Main GUI theme"),
|
||||||
self.guiTheme,
|
self.guiTheme,
|
||||||
self.tr("Requires restart.")
|
self.tr("General colour theme and icons.")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Editor Theme
|
# Editor Theme
|
||||||
@@ -229,7 +229,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
self.mainForm.addRow(
|
self.mainForm.addRow(
|
||||||
self.tr("Font family"),
|
self.tr("Font family"),
|
||||||
self.guiFont,
|
self.guiFont,
|
||||||
self.tr("Requires restart."),
|
self.tr("Requires restart to take effect."),
|
||||||
theButton=self.fontButton
|
theButton=self.fontButton
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ class GuiPreferencesGeneral(QWidget):
|
|||||||
self.mainForm.addRow(
|
self.mainForm.addRow(
|
||||||
self.tr("Font size"),
|
self.tr("Font size"),
|
||||||
self.guiFontSize,
|
self.guiFontSize,
|
||||||
self.tr("Requires restart."),
|
self.tr("Requires restart to take effect."),
|
||||||
theUnit=self.tr("pt")
|
theUnit=self.tr("pt")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -112,9 +112,10 @@ class nwDocInsert(Enum):
|
|||||||
QUOTE_RS = 2
|
QUOTE_RS = 2
|
||||||
QUOTE_LD = 3
|
QUOTE_LD = 3
|
||||||
QUOTE_RD = 4
|
QUOTE_RD = 4
|
||||||
NEW_PAGE = 5
|
SYNOPSIS = 5
|
||||||
VSPACE_S = 6
|
NEW_PAGE = 6
|
||||||
VSPACE_M = 7
|
VSPACE_S = 7
|
||||||
|
VSPACE_M = 8
|
||||||
|
|
||||||
# END Enum nwDocInsert
|
# END Enum nwDocInsert
|
||||||
|
|
||||||
|
|||||||
@@ -877,6 +877,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
newBlock = False
|
newBlock = False
|
||||||
|
goAfter = False
|
||||||
|
|
||||||
if isinstance(theInsert, str):
|
if isinstance(theInsert, str):
|
||||||
theText = theInsert
|
theText = theInsert
|
||||||
@@ -889,22 +890,29 @@ class GuiDocEditor(QTextEdit):
|
|||||||
theText = self._typDQOpen
|
theText = self._typDQOpen
|
||||||
elif theInsert == nwDocInsert.QUOTE_RD:
|
elif theInsert == nwDocInsert.QUOTE_RD:
|
||||||
theText = self._typDQClose
|
theText = self._typDQClose
|
||||||
|
elif theInsert == nwDocInsert.SYNOPSIS:
|
||||||
|
theText = "% Synopsis: "
|
||||||
|
newBlock = True
|
||||||
|
goAfter = True
|
||||||
elif theInsert == nwDocInsert.NEW_PAGE:
|
elif theInsert == nwDocInsert.NEW_PAGE:
|
||||||
theText = "[NEW PAGE]"
|
theText = "[NEW PAGE]"
|
||||||
newBlock = True
|
newBlock = True
|
||||||
|
goAfter = False
|
||||||
elif theInsert == nwDocInsert.VSPACE_S:
|
elif theInsert == nwDocInsert.VSPACE_S:
|
||||||
theText = "[VSPACE]"
|
theText = "[VSPACE]"
|
||||||
newBlock = True
|
newBlock = True
|
||||||
|
goAfter = False
|
||||||
elif theInsert == nwDocInsert.VSPACE_M:
|
elif theInsert == nwDocInsert.VSPACE_M:
|
||||||
theText = "[VSPACE:2]"
|
theText = "[VSPACE:2]"
|
||||||
newBlock = True
|
newBlock = True
|
||||||
|
goAfter = False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if newBlock:
|
if newBlock:
|
||||||
self.insertNewBlock(theText, defaultAfter=False)
|
self.insertNewBlock(theText, defaultAfter=goAfter)
|
||||||
else:
|
else:
|
||||||
theCursor = self.textCursor()
|
theCursor = self.textCursor()
|
||||||
theCursor.beginEditBlock()
|
theCursor.beginEditBlock()
|
||||||
@@ -1709,12 +1717,8 @@ class GuiDocEditor(QTextEdit):
|
|||||||
logger.debug("Invalid block selected for action '%s'", str(docAction))
|
logger.debug("Invalid block selected for action '%s'", str(docAction))
|
||||||
return False
|
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
|
# Remove existing format first, if any
|
||||||
|
theText = theBlock.text()
|
||||||
if theText.startswith("@"):
|
if theText.startswith("@"):
|
||||||
logger.error("Cannot apply block format to keyword/value line")
|
logger.error("Cannot apply block format to keyword/value line")
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -554,6 +554,15 @@ class GuiMainMenu(QMenuBar):
|
|||||||
)
|
)
|
||||||
self.mInsKeywords.addAction(self.mInsKWItems[keyWord][0])
|
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
|
# Insert > Symbols
|
||||||
self.mInsBreaks = self.insertMenu.addMenu(self.tr("Page Break and Space"))
|
self.mInsBreaks = self.insertMenu.addMenu(self.tr("Page Break and Space"))
|
||||||
|
|
||||||
|
|||||||
@@ -783,10 +783,6 @@ def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumTex
|
|||||||
mp.setattr(QTextBlock, "isValid", lambda *a, **k: False)
|
mp.setattr(QTextBlock, "isValid", lambda *a, **k: False)
|
||||||
assert nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT) is 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
|
# Keyword
|
||||||
assert nwGUI.docEditor.replaceText("@pov: Jane\n\n") is True
|
assert nwGUI.docEditor.replaceText("@pov: Jane\n\n") is True
|
||||||
assert nwGUI.docEditor.setCursorPosition(5) is True
|
assert nwGUI.docEditor.setCursorPosition(5) is True
|
||||||
|
|||||||
@@ -116,6 +116,16 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, nwLipsum):
|
|||||||
fmtStr = "#### Pellentesque nec erat ut nulla posuere commodo."
|
fmtStr = "#### Pellentesque nec erat ut nulla posuere commodo."
|
||||||
assert nwGUI.docEditor.getText()[39:91] == fmtStr
|
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
|
# Clear Format
|
||||||
nwGUI.mainMenu.aFmtNoFormat.activate(QAction.Trigger)
|
nwGUI.mainMenu.aFmtNoFormat.activate(QAction.Trigger)
|
||||||
assert nwGUI.docEditor.getText()[39:86] == cleanText
|
assert nwGUI.docEditor.getText()[39:86] == cleanText
|
||||||
@@ -314,10 +324,6 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, nwLipsum):
|
|||||||
assert nwGUI.docEditor.setCursorPosition(17)
|
assert nwGUI.docEditor.setCursorPosition(17)
|
||||||
assert not nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT)
|
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
|
# Invalid Action
|
||||||
assert nwGUI.docEditor.setCursorPosition(30)
|
assert nwGUI.docEditor.setCursorPosition(30)
|
||||||
assert not nwGUI.docEditor._formatBlock(nwDocAction.NO_ACTION)
|
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
|
assert nwGUI.docEditor.getText() == nwUnicode.U_THNBSP
|
||||||
nwGUI.docEditor.clear()
|
nwGUI.docEditor.clear()
|
||||||
|
|
||||||
##
|
# Insert Keywords
|
||||||
# Insert Keywords
|
# ===============
|
||||||
##
|
|
||||||
|
|
||||||
nwGUI.docEditor.setText("Stuff")
|
nwGUI.docEditor.setText("Stuff")
|
||||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.TAG_KEY][0].activate(QAction.Trigger)
|
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()
|
nwGUI.docEditor.clear()
|
||||||
|
|
||||||
##
|
# Insert Special Comments
|
||||||
# Insert Break or Space
|
# =======================
|
||||||
##
|
|
||||||
|
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.docEditor.setText("### Stuff\n")
|
||||||
nwGUI.mainMenu.aInsNewPage.activate(QAction.Trigger)
|
nwGUI.mainMenu.aInsNewPage.activate(QAction.Trigger)
|
||||||
@@ -601,9 +612,8 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
|
|||||||
|
|
||||||
nwGUI.docEditor.clear()
|
nwGUI.docEditor.clear()
|
||||||
|
|
||||||
##
|
# Insert Text from File
|
||||||
# Insert text from file
|
# =====================
|
||||||
##
|
|
||||||
|
|
||||||
nwGUI.closeDocument()
|
nwGUI.closeDocument()
|
||||||
|
|
||||||
@@ -639,9 +649,8 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
|
|||||||
nwGUI.mainMenu.aImportFile.activate(QAction.Trigger)
|
nwGUI.mainMenu.aImportFile.activate(QAction.Trigger)
|
||||||
assert nwGUI.docEditor.getText() == "Foo"
|
assert nwGUI.docEditor.getText() == "Foo"
|
||||||
|
|
||||||
##
|
# Reveal File Location
|
||||||
# Reveal file location
|
# ====================
|
||||||
##
|
|
||||||
|
|
||||||
theMessage = ""
|
theMessage = ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user