Add a 'Create New' menu for documents in project tree context menu (#1679)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
@@ -1769,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
|
||||
|
||||
@@ -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,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 == [
|
||||
"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]:
|
||||
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,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",
|
||||
|
||||
Reference in New Issue
Block a user