Added insert menu entries for keywords
This commit is contained in:
@@ -167,7 +167,7 @@ class nwLabels():
|
|||||||
nwKeyWords.POV_KEY : "Point of View",
|
nwKeyWords.POV_KEY : "Point of View",
|
||||||
nwKeyWords.CHAR_KEY : "Characters",
|
nwKeyWords.CHAR_KEY : "Characters",
|
||||||
nwKeyWords.PLOT_KEY : "Plot",
|
nwKeyWords.PLOT_KEY : "Plot",
|
||||||
nwKeyWords.TIME_KEY : "Time",
|
nwKeyWords.TIME_KEY : "Timeline",
|
||||||
nwKeyWords.WORLD_KEY : "Locations",
|
nwKeyWords.WORLD_KEY : "Locations",
|
||||||
nwKeyWords.OBJECT_KEY : "Objects",
|
nwKeyWords.OBJECT_KEY : "Objects",
|
||||||
nwKeyWords.ENTITY_KEY : "Entities",
|
nwKeyWords.ENTITY_KEY : "Entities",
|
||||||
|
|||||||
+26
-1
@@ -54,7 +54,8 @@ from nw.core import NWDoc, NWSpellSimple, countWords
|
|||||||
from nw.gui.dochighlight import GuiDocHighlighter
|
from nw.gui.dochighlight import GuiDocHighlighter
|
||||||
from nw.common import transferCase
|
from nw.common import transferCase
|
||||||
from nw.constants import (
|
from nw.constants import (
|
||||||
nwConst, nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwItemClass
|
nwConst, nwAlert, nwUnicode, nwDocAction, nwDocInsert, nwItemClass,
|
||||||
|
nwKeyWords
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -755,6 +756,30 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
return True
|
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):
|
def closeSearch(self):
|
||||||
"""Close the search box.
|
"""Close the search box.
|
||||||
"""
|
"""
|
||||||
|
|||||||
+28
-5
@@ -32,7 +32,9 @@ from PyQt5.QtCore import QUrl, QProcess
|
|||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
from PyQt5.QtWidgets import QMenuBar, QAction
|
from PyQt5.QtWidgets import QMenuBar, QAction
|
||||||
|
|
||||||
from nw.constants import nwItemType, nwItemClass, nwDocAction, nwDocInsert
|
from nw.constants import (
|
||||||
|
nwItemType, nwItemClass, nwDocAction, nwDocInsert, nwKeyWords, nwLabels
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -61,10 +63,11 @@ class GuiMainMenu(QMenuBar):
|
|||||||
self._buildHelpMenu()
|
self._buildHelpMenu()
|
||||||
|
|
||||||
# Function Pointers
|
# Function Pointers
|
||||||
self._docAction = self.theParent.passDocumentAction
|
self._docAction = self.theParent.passDocumentAction
|
||||||
self._moveTreeItem = self.theParent.treeView.moveTreeItem
|
self._moveTreeItem = self.theParent.treeView.moveTreeItem
|
||||||
self._newTreeItem = self.theParent.treeView.newTreeItem
|
self._newTreeItem = self.theParent.treeView.newTreeItem
|
||||||
self._docInsert = self.theParent.docEditor.insertText
|
self._docInsert = self.theParent.docEditor.insertText
|
||||||
|
self._insertKeyWord = self.theParent.docEditor.insertKeyWord
|
||||||
|
|
||||||
logger.debug("GuiMainMenu initialisation complete")
|
logger.debug("GuiMainMenu initialisation complete")
|
||||||
|
|
||||||
@@ -499,6 +502,26 @@ class GuiMainMenu(QMenuBar):
|
|||||||
# Insert
|
# Insert
|
||||||
self.insertMenu = self.addMenu("&Insert")
|
self.insertMenu = self.addMenu("&Insert")
|
||||||
|
|
||||||
|
# Insert > Keywords and Tags
|
||||||
|
self.mInsKeywords = self.insertMenu.addMenu("Keywords and Tags")
|
||||||
|
self.mInsKWItems = {}
|
||||||
|
self.mInsKWItems[nwKeyWords.TAG_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, G")
|
||||||
|
self.mInsKWItems[nwKeyWords.POV_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, V")
|
||||||
|
self.mInsKWItems[nwKeyWords.CHAR_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, C")
|
||||||
|
self.mInsKWItems[nwKeyWords.PLOT_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, P")
|
||||||
|
self.mInsKWItems[nwKeyWords.TIME_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, T")
|
||||||
|
self.mInsKWItems[nwKeyWords.WORLD_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, L")
|
||||||
|
self.mInsKWItems[nwKeyWords.OBJECT_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, O")
|
||||||
|
self.mInsKWItems[nwKeyWords.ENTITY_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, E")
|
||||||
|
self.mInsKWItems[nwKeyWords.CUSTOM_KEY] = (QAction(self.mInsKeywords), "Ctrl+K, X")
|
||||||
|
for n, keyWord in enumerate(self.mInsKWItems):
|
||||||
|
self.mInsKWItems[keyWord][0].setText(nwLabels.KEY_NAME[keyWord])
|
||||||
|
self.mInsKWItems[keyWord][0].setShortcut(self.mInsKWItems[keyWord][1])
|
||||||
|
self.mInsKWItems[keyWord][0].triggered.connect(
|
||||||
|
lambda n, keyWord=keyWord: self._insertKeyWord(keyWord)
|
||||||
|
)
|
||||||
|
self.mInsKeywords.addAction(self.mInsKWItems[keyWord][0])
|
||||||
|
|
||||||
# Insert > Short Dash
|
# Insert > Short Dash
|
||||||
self.aInsENDash = QAction("Short Dash", self)
|
self.aInsENDash = QAction("Short Dash", self)
|
||||||
self.aInsENDash.setStatusTip("Insert short dash")
|
self.aInsENDash.setStatusTip("Insert short dash")
|
||||||
|
|||||||
Reference in New Issue
Block a user