From ec7f50b5664167596e9effdb3627b977cf0e66cb Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:05:10 +0100 Subject: [PATCH 1/4] Add a 'Create New' submenu to project tree context menu (#1519) --- novelwriter/gui/projtree.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 14cb0e76..b445e426 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -1674,9 +1674,13 @@ class _TreeContextMenu(QMenu): self._docActions() self.addSeparator() + # Create New Items + self._itemCreation() + self.addSeparator() + # Edit Item Settings - aLabel = self.addAction(self.tr("Rename")) - aLabel.triggered.connect(lambda: self.projTree.renameTreeItem(self._handle)) + action = self.addAction(self.tr("Rename")) + action.triggered.connect(lambda: self.projTree.renameTreeItem(self._handle)) if isFile: self._itemActive(False) self._itemStatusImport(False) @@ -1716,6 +1720,16 @@ class _TreeContextMenu(QMenu): ) return + def _itemCreation(self) -> None: + """Add create item actions.""" + menu = self.addMenu(self.tr("Create New ...")) + menu.addAction(self.projView.projBar.aAddEmpty) + menu.addAction(self.projView.projBar.aAddChap) + menu.addAction(self.projView.projBar.aAddScene) + menu.addAction(self.projView.projBar.aAddNote) + menu.addAction(self.projView.projBar.aAddFolder) + return + def _itemActive(self, multi: bool) -> None: """Add Active/Inactive actions.""" if multi: From 7fcc9a392858c54b3e8d772ca86fa4e7e75baa00 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:05:16 +0100 Subject: [PATCH 2/4] Update test --- tests/test_gui/test_gui_projtree.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py index 63e2f760..6afbb200 100644 --- a/tests/test_gui/test_gui_projtree.py +++ b/tests/test_gui/test_gui_projtree.py @@ -1182,8 +1182,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(True) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Rename", "Set Status to ...", "Expand All", "Collapse All", - "Duplicate from Here", "Delete Permanently", + "Create New", "Rename", "Set Status to ...", "Expand All", + "Collapse All", "Duplicate from Here", "Delete Permanently", ] # Context Menu on Folder Item @@ -1193,8 +1193,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(True) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Rename", "Set Status to ...", "Transform", "Expand All", "Collapse All", - "Duplicate from Here", "Move to Trash", + "Create New", "Rename", "Set Status to ...", "Transform", "Expand All", + "Collapse All", "Duplicate from Here", "Move to Trash", ] def getTransformSubMenu(menu: QMenu) -> list[str]: @@ -1210,8 +1210,9 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(True) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Open Document", "View Document", "Rename", "Toggle Active", "Set Status to ...", - "Transform", "Expand All", "Collapse All", "Duplicate from Here", "Move to Trash", + "Open Document", "View Document", "Create New", "Rename", "Toggle Active", + "Set Status to ...", "Transform", "Expand All", "Collapse All", + "Duplicate from Here", "Move to Trash", ] assert getTransformSubMenu(ctxMenu) == [ "Convert to Project Note", "Merge Child Items into Self", @@ -1225,8 +1226,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(False) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Open Document", "View Document", "Rename", "Toggle Active", "Set Importance to ...", - "Transform", "Duplicate Document", "Move to Trash", + "Open Document", "View Document", "Create New", "Rename", "Toggle Active", + "Set Importance to ...", "Transform", "Duplicate Document", "Move to Trash", ] assert getTransformSubMenu(ctxMenu) == [ "Split Document by Headers", @@ -1239,8 +1240,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(False) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Open Document", "View Document", "Rename", "Toggle Active", "Set Status to ...", - "Transform", "Duplicate Document", "Move to Trash", + "Open Document", "View Document", "Create New", "Rename", "Toggle Active", + "Set Status to ...", "Transform", "Duplicate Document", "Move to Trash", ] assert getTransformSubMenu(ctxMenu) == [ "Convert to Novel Document", "Split Document by Headers", From 9803dc16fde97f7c44067d2ba6543316154d917b Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:10:53 +0100 Subject: [PATCH 3/4] Fix a couple of minor issues with project tree context menu --- novelwriter/dialogs/projectsettings.py | 5 ++++- novelwriter/gui/projtree.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/novelwriter/dialogs/projectsettings.py b/novelwriter/dialogs/projectsettings.py index f6ff7730..c76c9f6b 100644 --- a/novelwriter/dialogs/projectsettings.py +++ b/novelwriter/dialogs/projectsettings.py @@ -79,7 +79,6 @@ class GuiProjectSettings(QDialog): self.sidebar.addButton(self.tr("Status"), self.PAGE_STATUS) self.sidebar.addButton(self.tr("Importance"), self.PAGE_IMPORT) self.sidebar.addButton(self.tr("Auto-Replace"), self.PAGE_REPLACE) - self.sidebar.setSelected(gotoPage) self.sidebar.buttonClicked.connect(self._sidebarClicked) # Buttons @@ -122,6 +121,10 @@ class GuiProjectSettings(QDialog): self.setLayout(self.outerBox) self.setSizeGripEnabled(True) + # Jump to Specified Page + self.sidebar.setSelected(gotoPage) + self._sidebarClicked(gotoPage) + logger.debug("Ready: GuiProjectSettings") return diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index b445e426..d3fcbb34 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -1783,7 +1783,7 @@ class _TreeContextMenu(QMenu): def _itemTransform(self, isFile: bool, isFolder: bool, hasChild: bool) -> None: """Add actions for the Transform menu.""" - menu = self.addMenu(self.tr("Transform")) + menu = self.addMenu(self.tr("Transform ...")) tree = self.projTree tHandle = self._handle From d23fdf28adddc21fcd663d263c7e41e145c7845f Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:18:17 +0100 Subject: [PATCH 4/4] Fix test, again ... --- tests/test_gui/test_gui_projtree.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py index 6afbb200..628c42be 100644 --- a/tests/test_gui/test_gui_projtree.py +++ b/tests/test_gui/test_gui_projtree.py @@ -1182,7 +1182,7 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(True) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Create New", "Rename", "Set Status to ...", "Expand All", + "Create New ...", "Rename", "Set Status to ...", "Expand All", "Collapse All", "Duplicate from Here", "Delete Permanently", ] @@ -1193,13 +1193,13 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(True) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Create New", "Rename", "Set Status to ...", "Transform", "Expand All", + "Create New ...", "Rename", "Set Status to ...", "Transform ...", "Expand All", "Collapse All", "Duplicate from Here", "Move to Trash", ] def getTransformSubMenu(menu: QMenu) -> list[str]: for action in menu.actions(): - if action.text() == "Transform": + if action.text() == "Transform ...": return [x.text() for x in action.menu().actions() if x.text()] return [] @@ -1210,8 +1210,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(True) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Open Document", "View Document", "Create New", "Rename", "Toggle Active", - "Set Status to ...", "Transform", "Expand All", "Collapse All", + "Open Document", "View Document", "Create New ...", "Rename", "Toggle Active", + "Set Status to ...", "Transform ...", "Expand All", "Collapse All", "Duplicate from Here", "Move to Trash", ] assert getTransformSubMenu(ctxMenu) == [ @@ -1226,8 +1226,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(False) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Open Document", "View Document", "Create New", "Rename", "Toggle Active", - "Set Importance to ...", "Transform", "Duplicate Document", "Move to Trash", + "Open Document", "View Document", "Create New ...", "Rename", "Toggle Active", + "Set Importance to ...", "Transform ...", "Duplicate Document", "Move to Trash", ] assert getTransformSubMenu(ctxMenu) == [ "Split Document by Headers", @@ -1240,8 +1240,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd): ctxMenu.buildSingleSelectMenu(False) actions = [x.text() for x in ctxMenu.actions() if x.text()] assert actions == [ - "Open Document", "View Document", "Create New", "Rename", "Toggle Active", - "Set Status to ...", "Transform", "Duplicate Document", "Move to Trash", + "Open Document", "View Document", "Create New ...", "Rename", "Toggle Active", + "Set Status to ...", "Transform ...", "Duplicate Document", "Move to Trash", ] assert getTransformSubMenu(ctxMenu) == [ "Convert to Novel Document", "Split Document by Headers",