Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'Create New' menu for documents in project tree context menu #1679

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion novelwriter/dialogs/projectsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(self, parent: QWidget, gotoPage: int = PAGE_SETTINGS) -> None:
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
Expand Down Expand Up @@ -122,6 +121,10 @@ def __init__(self, parent: QWidget, gotoPage: int = PAGE_SETTINGS) -> None:
self.setLayout(self.outerBox)
self.setSizeGripEnabled(True)

# Jump to Specified Page
self.sidebar.setSelected(gotoPage)
self._sidebarClicked(gotoPage)

logger.debug("Ready: GuiProjectSettings")

return
Expand Down
20 changes: 17 additions & 3 deletions novelwriter/gui/projtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,9 +1674,13 @@ def buildSingleSelectMenu(self, hasChild: bool) -> None:
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)
Expand Down Expand Up @@ -1716,6 +1720,16 @@ def _docActions(self) -> None:
)
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:
Expand Down Expand Up @@ -1769,7 +1783,7 @@ def _itemStatusImport(self, multi: bool) -> None:

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
Expand Down
23 changes: 12 additions & 11 deletions tests/test_gui/test_gui_projtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,8 @@ def itemPos(tHandle):
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
Expand All @@ -1193,13 +1193,13 @@ def itemPos(tHandle):
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 []

Expand All @@ -1210,8 +1210,9 @@ def getTransformSubMenu(menu: QMenu) -> list[str]:
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",
Expand All @@ -1225,8 +1226,8 @@ def getTransformSubMenu(menu: QMenu) -> list[str]:
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",
Expand All @@ -1239,8 +1240,8 @@ def getTransformSubMenu(menu: QMenu) -> list[str]:
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",
Expand Down
Loading