diff --git a/docs/source/usage_shortcuts.rst b/docs/source/usage_shortcuts.rst index fa761a3e..e9e7bb36 100644 --- a/docs/source/usage_shortcuts.rst +++ b/docs/source/usage_shortcuts.rst @@ -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:`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:`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:`/`", "Toggle block format as comment." ":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:`C`", "Copy selected text to clipboard." ":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:`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:`=`.)" diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index aa1ff9ce..b9bfda0d 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -97,6 +97,11 @@ class GuiProjectView(QWidget): self.keyUndoMv.setContext(Qt.WidgetShortcut) 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 self.revealNewTreeItem = self.projTree.revealNewTreeItem self.renameTreeItem = self.projTree.renameTreeItem @@ -913,9 +918,6 @@ class GuiProjectTree(QTreeWidget): def setSelectedHandle(self, tHandle, doScroll=False): """Set a specific handle as the selected item. """ - if tHandle not in self._treeMap: - return False - tItem = self._getTreeItem(tHandle) if tItem is None: return False @@ -929,6 +931,15 @@ class GuiProjectTree(QTreeWidget): 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): """Check if the tree has changed since a given time. """ diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py index d7ed41d0..feef859d 100644 --- a/tests/test_gui/test_gui_projtree.py +++ b/tests/test_gui/test_gui_projtree.py @@ -511,6 +511,12 @@ def testGuiProjTree_ContextMenu(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockR assert projTree._openContextMenu(itemPos(hCharRoot)) 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 # ===================== # Trigger the dedicated functions the menu entries connect to