Add a shortcut to open project tree context menu
This commit is contained in:
@@ -25,7 +25,7 @@ The main shorcuts are as follows:
|
|||||||
":kbd:`Alt`:kbd:`4`", "Switch focus to outline view. On Windows, use :kbd:`Ctrl`:kbd:`Alt`:kbd:`4`."
|
":kbd:`Alt`:kbd:`4`", "Switch focus to outline view. On Windows, use :kbd:`Ctrl`:kbd:`Alt`:kbd:`4`."
|
||||||
":kbd:`Alt`:kbd:`Left`", "Move backward in the view history of the document viewer."
|
":kbd:`Alt`:kbd:`Left`", "Move backward in the view history of the document viewer."
|
||||||
":kbd:`Alt`:kbd:`Right`", "Move forward in the view history of the document viewer."
|
":kbd:`Alt`:kbd:`Right`", "Move forward in the view history of the document viewer."
|
||||||
":kbd:`Ctrl`:kbd:`.`", "Open menu to correct word under cursor."
|
":kbd:`Ctrl`:kbd:`.`", "Open the context menu in the project tree or the document editor."
|
||||||
":kbd:`Ctrl`:kbd:`,`", "Open the :guilabel:`Preferences` dialog."
|
":kbd:`Ctrl`:kbd:`,`", "Open the :guilabel:`Preferences` dialog."
|
||||||
":kbd:`Ctrl`:kbd:`/`", "Toggle block format as comment."
|
":kbd:`Ctrl`:kbd:`/`", "Toggle block format as comment."
|
||||||
":kbd:`Ctrl`:kbd:`0`", "Remove block formatting for block under cursor."
|
":kbd:`Ctrl`:kbd:`0`", "Remove block formatting for block under cursor."
|
||||||
@@ -42,7 +42,6 @@ The main shorcuts are as follows:
|
|||||||
":kbd:`Ctrl`:kbd:`B`", "Format selected text, or word under cursor, with strong emphasis (bold)."
|
":kbd:`Ctrl`:kbd:`B`", "Format selected text, or word under cursor, with strong emphasis (bold)."
|
||||||
":kbd:`Ctrl`:kbd:`C`", "Copy selected text to clipboard."
|
":kbd:`Ctrl`:kbd:`C`", "Copy selected text to clipboard."
|
||||||
":kbd:`Ctrl`:kbd:`D`", "Strikethrough selected text, or word under cursor."
|
":kbd:`Ctrl`:kbd:`D`", "Strikethrough selected text, or word under cursor."
|
||||||
":kbd:`Ctrl`:kbd:`E`", "If in the project tree, edit a document or folder settings."
|
|
||||||
":kbd:`Ctrl`:kbd:`F`", "Open the search bar and search for the selected word, if any is selected."
|
":kbd:`Ctrl`:kbd:`F`", "Open the search bar and search for the selected word, if any is selected."
|
||||||
":kbd:`Ctrl`:kbd:`G`", "Find next occurrence of search word in current document."
|
":kbd:`Ctrl`:kbd:`G`", "Find next occurrence of search word in current document."
|
||||||
":kbd:`Ctrl`:kbd:`H`", "Open the search and replace bar and search for the selected word, if any is selected. (On Mac, this is :kbd:`Cmd`:kbd:`=`.)"
|
":kbd:`Ctrl`:kbd:`H`", "Open the search and replace bar and search for the selected word, if any is selected. (On Mac, this is :kbd:`Cmd`:kbd:`=`.)"
|
||||||
|
|||||||
@@ -97,6 +97,11 @@ class GuiProjectView(QWidget):
|
|||||||
self.keyUndoMv.setContext(Qt.WidgetShortcut)
|
self.keyUndoMv.setContext(Qt.WidgetShortcut)
|
||||||
self.keyUndoMv.activated.connect(lambda: self.projTree.undoLastMove())
|
self.keyUndoMv.activated.connect(lambda: self.projTree.undoLastMove())
|
||||||
|
|
||||||
|
self.keyContext = QShortcut(self.projTree)
|
||||||
|
self.keyContext.setKey("Ctrl+.")
|
||||||
|
self.keyContext.setContext(Qt.WidgetShortcut)
|
||||||
|
self.keyContext.activated.connect(lambda: self.projTree.openContextOnSelected())
|
||||||
|
|
||||||
# Function Mappings
|
# Function Mappings
|
||||||
self.revealNewTreeItem = self.projTree.revealNewTreeItem
|
self.revealNewTreeItem = self.projTree.revealNewTreeItem
|
||||||
self.renameTreeItem = self.projTree.renameTreeItem
|
self.renameTreeItem = self.projTree.renameTreeItem
|
||||||
@@ -913,9 +918,6 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
def setSelectedHandle(self, tHandle, doScroll=False):
|
def setSelectedHandle(self, tHandle, doScroll=False):
|
||||||
"""Set a specific handle as the selected item.
|
"""Set a specific handle as the selected item.
|
||||||
"""
|
"""
|
||||||
if tHandle not in self._treeMap:
|
|
||||||
return False
|
|
||||||
|
|
||||||
tItem = self._getTreeItem(tHandle)
|
tItem = self._getTreeItem(tHandle)
|
||||||
if tItem is None:
|
if tItem is None:
|
||||||
return False
|
return False
|
||||||
@@ -929,6 +931,15 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def openContextOnSelected(self):
|
||||||
|
"""Open the context menu on the current selected item.
|
||||||
|
"""
|
||||||
|
selItem = self.selectedItems()
|
||||||
|
if selItem:
|
||||||
|
pos = self.visualItemRect(selItem[0]).center()
|
||||||
|
return self._openContextMenu(pos)
|
||||||
|
return False
|
||||||
|
|
||||||
def changedSince(self, checkTime):
|
def changedSince(self, checkTime):
|
||||||
"""Check if the tree has changed since a given time.
|
"""Check if the tree has changed since a given time.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -511,6 +511,12 @@ def testGuiProjTree_ContextMenu(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockR
|
|||||||
assert projTree._openContextMenu(itemPos(hCharRoot)) is True
|
assert projTree._openContextMenu(itemPos(hCharRoot)) is True
|
||||||
assert projTree._openContextMenu(itemPos(hCharNote)) is True
|
assert projTree._openContextMenu(itemPos(hCharNote)) is True
|
||||||
|
|
||||||
|
# Check the keyboard shortcut handler as well
|
||||||
|
projTree.setSelectedHandle(hNovelRoot)
|
||||||
|
assert projTree.openContextOnSelected() is True
|
||||||
|
projTree.clearSelection()
|
||||||
|
assert projTree.openContextOnSelected() is False
|
||||||
|
|
||||||
# Direct Edit Functions
|
# Direct Edit Functions
|
||||||
# =====================
|
# =====================
|
||||||
# Trigger the dedicated functions the menu entries connect to
|
# Trigger the dedicated functions the menu entries connect to
|
||||||
|
|||||||
Reference in New Issue
Block a user