Added insert menu entries for keywords

This commit is contained in:
Veronica K. B. Olsen
2020-11-21 14:46:01 +01:00
parent 6d630d3a1b
commit 67063e089c
3 changed files with 55 additions and 7 deletions
+26 -1
View File
@@ -54,7 +54,8 @@ from nw.core import NWDoc, NWSpellSimple, countWords
from nw.gui.dochighlight import GuiDocHighlighter
from nw.common import transferCase
from nw.constants import (
nwConst, nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwItemClass
nwConst, nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwItemClass,
nwKeyWords
)
logger = logging.getLogger(__name__)
@@ -755,6 +756,30 @@ class GuiDocEditor(QTextEdit):
return True
def insertKeyWord(self, keyWord):
"""Insert a keyword in the text editor, at the cursor position.
If the insert line is not blank, a new line is started.
"""
if keyWord not in nwKeyWords.VALID_KEYS:
logger.error("Invalid keyword '%s'" % keyWord)
return False
logger.verbose("Inserting keyword '%s'" % keyWord)
theCursor = self.textCursor()
theBlock = theCursor.block()
if not theBlock.isValid():
logger.error("Filed to insert keyword '%s'" % keyWord)
return False
theCursor.beginEditBlock()
if theBlock.length() > 1:
theCursor.insertText("\n")
theCursor.insertText("%s: " % keyWord)
theCursor.endEditBlock()
return True
def closeSearch(self):
"""Close the search box.
"""