diff --git a/docs/source/interface.rst b/docs/source/interface.rst index 2cf0cc15..ff694efd 100644 --- a/docs/source/interface.rst +++ b/docs/source/interface.rst @@ -183,6 +183,7 @@ These are as following: On macOS, replace :kbd:`Ctrl` with :kbd:`Cmd`. A set of insert features are also available through shortcuts, but they require a double combination of shortcuts. +The insert feature is activated with :kbd:`Ctrl-K`, followed by a key for the inserted character or punctuation. .. csv-table:: Keyboard Shortcuts :header: "Shortcut", "Description" @@ -191,6 +192,10 @@ A set of insert features are also available through shortcuts, but they require ":kbd:`Ctrl-K, -`", "Insert a short dash (en dash)." ":kbd:`Ctrl-K, _`", "Insert a long dash (em dash)." ":kbd:`Ctrl-K, .`", "Insert ellipsis." + ":kbd:`Ctrl-K, 1`", "Insert left single quote." + ":kbd:`Ctrl-K, 2`", "Insert right single quote." + ":kbd:`Ctrl-K, 3`", "Insert left double quote." + ":kbd:`Ctrl-K, 4`", "Insert right double quote." ":kbd:`Ctrl-K, Return`", "Insert a hard line break." ":kbd:`Ctrl-K, Space`", "Insert a non-breaking space." ":kbd:`Ctrl-K, Shift-Space`", "Insert a thin space." diff --git a/nw/constants/__init__.py b/nw/constants/__init__.py index 0e90354a..7c43df61 100644 --- a/nw/constants/__init__.py +++ b/nw/constants/__init__.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- from nw.constants.iso import isoLanguage, isoCountry from nw.constants.constants import ( - nwConst, nwRegEx, nwFiles, nwKeyWords, nwLabels, nwQuotes, nwUnicode, - nwInsertSymbols + nwConst, nwRegEx, nwFiles, nwKeyWords, nwLabels, nwQuotes, nwUnicode ) from nw.constants.enum import ( nwAlert, nwDocAction, nwItemClass, nwItemLayout, nwItemType, nwOutline, @@ -19,7 +18,6 @@ __all__ = [ "nwLabels", "nwQuotes", "nwUnicode", - "nwInsertSymbols", "nwAlert", "nwDocAction", "nwItemClass", diff --git a/nw/constants/constants.py b/nw/constants/constants.py index d78cd5c6..c6e17a15 100644 --- a/nw/constants/constants.py +++ b/nw/constants/constants.py @@ -299,18 +299,3 @@ class nwUnicode: H_LTRIS = "◂" # END Class nwUnicode - -class nwInsertSymbols(): - - SYMBOLS = { - nwDocInsert.NO_INSERT : "", - nwDocInsert.HARD_BREAK : " \n", - nwDocInsert.NB_SPACE : nwUnicode.U_NBSP, - nwDocInsert.THIN_SPACE : nwUnicode.U_THNSP, - nwDocInsert.THIN_NB_SPACE : nwUnicode.U_THNBSP, - nwDocInsert.SHORT_DASH : nwUnicode.U_ENDASH, - nwDocInsert.LONG_DASH : nwUnicode.U_EMDASH, - nwDocInsert.ELLIPSIS : nwUnicode.U_HELLIP, - } - -# END Enum nwDocInsert diff --git a/nw/constants/enum.py b/nw/constants/enum.py index 4a377d7b..68b8b173 100644 --- a/nw/constants/enum.py +++ b/nw/constants/enum.py @@ -107,6 +107,10 @@ class nwDocInsert(Enum): SHORT_DASH = 5 LONG_DASH = 6 ELLIPSIS = 7 + QUOTE_LS = 8 + QUOTE_RS = 9 + QUOTE_LD = 10 + QUOTE_RD = 11 # END Enum nwDocInsert diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index cba62c16..28edba4e 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -52,7 +52,7 @@ from nw.core import NWDoc, NWSpellSimple, countWords from nw.gui.dochighlight import GuiDocHighlighter from nw.common import transferCase from nw.constants import ( - nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwInsertSymbols, nwItemClass + nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwItemClass ) logger = logging.getLogger(__name__) @@ -590,8 +590,33 @@ class GuiDocEditor(QTextEdit): """ if isinstance(theInsert, str): theText = theInsert - elif theInsert in nwInsertSymbols.SYMBOLS: - theText = nwInsertSymbols.SYMBOLS[theInsert] + elif theInsert in nwDocInsert: + if theInsert == nwDocInsert.NO_INSERT: + theText = "", + elif theInsert == nwDocInsert.HARD_BREAK: + theText = " \n", + elif theInsert == nwDocInsert.NB_SPACE: + theText = nwUnicode.U_NBSP, + elif theInsert == nwDocInsert.THIN_SPACE: + theText = nwUnicode.U_THNSP, + elif theInsert == nwDocInsert.THIN_NB_SPACE: + theText = nwUnicode.U_THNBSP, + elif theInsert == nwDocInsert.SHORT_DASH: + theText = nwUnicode.U_ENDASH, + elif theInsert == nwDocInsert.LONG_DASH: + theText = nwUnicode.U_EMDASH, + elif theInsert == nwDocInsert.ELLIPSIS: + theText = nwUnicode.U_HELLIP, + elif theInsert == nwDocInsert.QUOTE_LS: + theText = self.typSQOpen + elif theInsert == nwDocInsert.QUOTE_RS: + theText = self.typSQClose + elif theInsert == nwDocInsert.QUOTE_LD: + theText = self.typDQOpen + elif theInsert == nwDocInsert.QUOTE_RD: + theText = self.typDQClose + else: + return False else: return False theCursor = self.textCursor() diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 911e4153..84a336eb 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -485,6 +485,37 @@ class GuiMainMenu(QMenuBar): # Insert > Separator self.insertMenu.addSeparator() + # Insert > Left Single Quote + self.aInsQuoteLS = QAction("Left Single Quote", self) + self.aInsQuoteLS.setStatusTip("Insert left single quote") + self.aInsQuoteLS.setShortcut("Ctrl+K, 1") + self.aInsQuoteLS.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_LS)) + self.insertMenu.addAction(self.aInsQuoteLS) + + # Insert > Right Single Quote + self.aInsQuoteRS = QAction("Right Single Quote", self) + self.aInsQuoteRS.setStatusTip("Insert right single quote") + self.aInsQuoteRS.setShortcut("Ctrl+K, 2") + self.aInsQuoteRS.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_RS)) + self.insertMenu.addAction(self.aInsQuoteRS) + + # Insert > Left Double Quote + self.aInsQuoteLD = QAction("Left Double Quote", self) + self.aInsQuoteLD.setStatusTip("Insert left double quote") + self.aInsQuoteLD.setShortcut("Ctrl+K, 3") + self.aInsQuoteLD.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_LD)) + self.insertMenu.addAction(self.aInsQuoteLD) + + # Insert > Right Double Quote + self.aInsQuoteRD = QAction("Right Double Quote", self) + self.aInsQuoteRD.setStatusTip("Insert right double quote") + self.aInsQuoteRD.setShortcut("Ctrl+K, 4") + self.aInsQuoteRD.triggered.connect(lambda: self._docInsert(nwDocInsert.QUOTE_RD)) + self.insertMenu.addAction(self.aInsQuoteRD) + + # Insert > Separator + self.insertMenu.addSeparator() + # Insert > Hard Line Break self.aInsHardBreak = QAction("Hard Line Break", self) self.aInsHardBreak.setStatusTip("Insert a hard line break") diff --git a/nw/guimain.py b/nw/guimain.py index 668ebf9f..f2a4cb3f 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -1004,6 +1004,10 @@ class GuiMain(QMainWindow): self.addAction(self.mainMenu.aInsENDash) self.addAction(self.mainMenu.aInsEMDash) self.addAction(self.mainMenu.aInsEllipsis) + self.addAction(self.mainMenu.aInsQuoteLS) + self.addAction(self.mainMenu.aInsQuoteRS) + self.addAction(self.mainMenu.aInsQuoteLD) + self.addAction(self.mainMenu.aInsQuoteRD) self.addAction(self.mainMenu.aInsHardBreak) self.addAction(self.mainMenu.aInsNBSpace) self.addAction(self.mainMenu.aInsThinSpace)