From 1bd82954c2de62fcd7f534098a49f0dfea0ec065 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:12:47 +0100 Subject: [PATCH] Add menu entry and update tests --- novelwriter/enum.py | 31 ++++++++++---------- novelwriter/gui/doceditor.py | 5 ++++ novelwriter/gui/mainmenu.py | 6 ++++ tests/test_core/test_core_index.py | 13 ++++++++ tests/test_gui/test_gui_doceditor.py | 16 +++++++++- tests/test_gui/test_gui_mainmenu.py | 5 ++++ tests/test_tools/test_tools_manussettings.py | 16 ++++++++++ 7 files changed, 76 insertions(+), 16 deletions(-) diff --git a/novelwriter/enum.py b/novelwriter/enum.py index 85724c95..b7e38e40 100644 --- a/novelwriter/enum.py +++ b/novelwriter/enum.py @@ -112,21 +112,22 @@ class nwDocAction(Enum): BLOCK_TXT = 19 BLOCK_TTL = 20 BLOCK_UNN = 21 - REPL_SNG = 22 - REPL_DBL = 23 - RM_BREAKS = 24 - ALIGN_L = 25 - ALIGN_C = 26 - ALIGN_R = 27 - INDENT_L = 28 - INDENT_R = 29 - SC_ITALIC = 30 - SC_BOLD = 31 - SC_STRIKE = 32 - SC_ULINE = 33 - SC_MARK = 34 - SC_SUP = 35 - SC_SUB = 36 + BLOCK_HSC = 22 + REPL_SNG = 23 + REPL_DBL = 24 + RM_BREAKS = 25 + ALIGN_L = 26 + ALIGN_C = 27 + ALIGN_R = 28 + INDENT_L = 29 + INDENT_R = 30 + SC_ITALIC = 31 + SC_BOLD = 32 + SC_STRIKE = 33 + SC_ULINE = 34 + SC_MARK = 35 + SC_SUP = 36 + SC_SUB = 37 # END Enum nwDocAction diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index f041141b..0d3bf0cc 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -744,6 +744,8 @@ class GuiDocEditor(QPlainTextEdit): self._formatBlock(nwDocAction.BLOCK_TTL) elif action == nwDocAction.BLOCK_UNN: self._formatBlock(nwDocAction.BLOCK_UNN) + elif action == nwDocAction.BLOCK_HSC: + self._formatBlock(nwDocAction.BLOCK_HSC) elif action == nwDocAction.REPL_SNG: self._replaceQuotes("'", self._typSQuoteO, self._typSQuoteC) elif action == nwDocAction.REPL_DBL: @@ -1705,6 +1707,9 @@ class GuiDocEditor(QPlainTextEdit): elif action == nwDocAction.BLOCK_UNN: text = f"##! {temp}" offset -= 4 + elif action == nwDocAction.BLOCK_HSC: + text = f"###! {temp}" + offset -= 5 elif action == nwDocAction.ALIGN_L: text = f"{temp} <<" elif action == nwDocAction.ALIGN_C: diff --git a/novelwriter/gui/mainmenu.py b/novelwriter/gui/mainmenu.py index 3e4c3850..86cbd3d8 100644 --- a/novelwriter/gui/mainmenu.py +++ b/novelwriter/gui/mainmenu.py @@ -735,6 +735,12 @@ class GuiMainMenu(QMenuBar): lambda: self.requestDocAction.emit(nwDocAction.BLOCK_UNN) ) + # Format > Hard Scene + self.aFmtHardSc = self.fmtMenu.addAction(self.tr("Hard Scene")) + self.aFmtHardSc.triggered.connect( + lambda: self.requestDocAction.emit(nwDocAction.BLOCK_HSC) + ) + # Format > Separator self.fmtMenu.addSeparator() diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index 2555b411..3ae976d4 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -502,6 +502,19 @@ def testCoreIndex_ScanText(mockGUI, fncPath, mockRnd): assert index._itemIndex[tHandle]["T0001"].paraCount == 1 # type: ignore assert index._itemIndex[tHandle]["T0001"].synopsis == "" # type: ignore + assert index.scanText(tHandle, ( + "###! Hard Scene\n\n" + "We're no longer following Jane, but John!\n\n" + )) + assert index._itemIndex[cHandle]["T0001"].references == {} # type: ignore + assert index._itemIndex[tHandle]["T0001"].level == "H3" # type: ignore + assert index._itemIndex[tHandle]["T0001"].line == 1 # type: ignore + assert index._itemIndex[tHandle]["T0001"].title == "Hard Scene" # type: ignore + assert index._itemIndex[tHandle]["T0001"].charCount == 51 # type: ignore + assert index._itemIndex[tHandle]["T0001"].wordCount == 9 # type: ignore + assert index._itemIndex[tHandle]["T0001"].paraCount == 1 # type: ignore + assert index._itemIndex[tHandle]["T0001"].synopsis == "" # type: ignore + # Page wo/Title # ============= diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index c8b1d581..d7475952 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -1134,13 +1134,20 @@ def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, projPath, ipsumText assert nwGUI.docEditor.getText() == "Title\n\n" assert nwGUI.docEditor.getCursorPosition() == 2 - # Strip Unnumbered CHapter + # Strip Unnumbered Chapter nwGUI.docEditor.replaceText("##! Title\n\n") nwGUI.docEditor.setCursorPosition(5) assert nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT) is True assert nwGUI.docEditor.getText() == "Title\n\n" assert nwGUI.docEditor.getCursorPosition() == 1 + # Strip Hard Scene + nwGUI.docEditor.replaceText("###! Title\n\n") + nwGUI.docEditor.setCursorPosition(6) + assert nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_TXT) is True + assert nwGUI.docEditor.getText() == "Title\n\n" + assert nwGUI.docEditor.getCursorPosition() == 1 + # Strip Text nwGUI.docEditor.replaceText("Generic text\n\n") nwGUI.docEditor.setCursorPosition(5) @@ -1302,6 +1309,13 @@ def testGuiEditor_BlockFormatting(qtbot, monkeypatch, nwGUI, projPath, ipsumText assert nwGUI.docEditor.getText() == "##! Some text\n\n" assert nwGUI.docEditor.getCursorPosition() == 9 + # Hard Scene + nwGUI.docEditor.replaceText("Some text\n\n") + nwGUI.docEditor.setCursorPosition(5) + assert nwGUI.docEditor._formatBlock(nwDocAction.BLOCK_HSC) is True + assert nwGUI.docEditor.getText() == "###! Some text\n\n" + assert nwGUI.docEditor.getCursorPosition() == 10 + # Left Indent nwGUI.docEditor.replaceText("Some text\n\n") nwGUI.docEditor.setCursorPosition(5) diff --git a/tests/test_gui/test_gui_mainmenu.py b/tests/test_gui/test_gui_mainmenu.py index 5d11b0d2..b0a0351f 100644 --- a/tests/test_gui/test_gui_mainmenu.py +++ b/tests/test_gui/test_gui_mainmenu.py @@ -126,6 +126,11 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum): fmtStr = "##! Pellentesque nec erat ut nulla posuere commodo." assert nwGUI.docEditor.getText()[54:105] == fmtStr + # Hard Scene + nwGUI.mainMenu.aFmtHardSc.activate(QAction.Trigger) + fmtStr = "###! Pellentesque nec erat ut nulla posuere commodo." + assert nwGUI.docEditor.getText()[54:106] == fmtStr + # Clear Format nwGUI.mainMenu.aFmtNoFormat.activate(QAction.Trigger) assert nwGUI.docEditor.getText()[54:101] == cleanText diff --git a/tests/test_tools/test_tools_manussettings.py b/tests/test_tools/test_tools_manussettings.py index 45f97358..75d7d83f 100644 --- a/tests/test_tools/test_tools_manussettings.py +++ b/tests/test_tools/test_tools_manussettings.py @@ -327,12 +327,14 @@ def testBuildSettings_Headings(qtbot: QtBot, nwGUI: GuiMain): chTitle = f"Chapter: {nwHeadFmt.TITLE}" unTitle = f"Interlude: {nwHeadFmt.TITLE}" scTitle = f"Scene: {nwHeadFmt.TITLE}" + shTitle = f"Hard Scene: {nwHeadFmt.TITLE}" sxTitle = f"Section: {nwHeadFmt.TITLE}" build.setValue("headings.fmtTitle", ttTitle) build.setValue("headings.fmtChapter", chTitle) build.setValue("headings.fmtUnnumbered", unTitle) build.setValue("headings.fmtScene", scTitle) + build.setValue("headings.fmtHardScene", shTitle) build.setValue("headings.fmtSection", sxTitle) build.setValue("headings.hideScene", False) build.setValue("headings.hideSection", False) @@ -351,6 +353,7 @@ def testBuildSettings_Headings(qtbot: QtBot, nwGUI: GuiMain): assert headTab.fmtChapter.text() == chTitle assert headTab.fmtUnnumbered.text() == unTitle assert headTab.fmtScene.text() == scTitle + assert headTab.fmtHScene.text() == shTitle assert headTab.fmtSection.text() == sxTitle assert headTab.swtScene.isChecked() is False assert headTab.swtSection.isChecked() is False @@ -396,6 +399,14 @@ def testBuildSettings_Headings(qtbot: QtBot, nwGUI: GuiMain): headTab.btnApply.click() assert headTab.editTextBox.isEnabled() is False + # Hard Scene + headTab.btnHScene.click() + assert headTab._editing == headTab.EDIT_HSCENE + assert headTab.editTextBox.isEnabled() is True + assert headTab.editTextBox.toPlainText() == shTitle + headTab.btnApply.click() + assert headTab.editTextBox.isEnabled() is False + # Section headTab.btnSection.click() assert headTab._editing == headTab.EDIT_SECTION @@ -455,6 +466,11 @@ def testBuildSettings_Headings(qtbot: QtBot, nwGUI: GuiMain): headTab.btnApply.click() assert build.getStr("headings.fmtScene") == nwHeadFmt.TITLE + headTab.btnHScene.click() + headTab.editTextBox.setPlainText(nwHeadFmt.TITLE) + headTab.btnApply.click() + assert build.getStr("headings.fmtHardScene") == nwHeadFmt.TITLE + headTab.btnSection.click() headTab.editTextBox.setPlainText(nwHeadFmt.TITLE) headTab.btnApply.click()