Add context menu option to rename item to first heading (#1692)
This commit is contained in:
@@ -1785,6 +1785,7 @@ class _TreeContextMenu(QMenu):
|
|||||||
action = self.addAction(self.tr("Rename"))
|
action = self.addAction(self.tr("Rename"))
|
||||||
action.triggered.connect(lambda: self.projTree.renameTreeItem(self._handle))
|
action.triggered.connect(lambda: self.projTree.renameTreeItem(self._handle))
|
||||||
if isFile:
|
if isFile:
|
||||||
|
self._itemHeader()
|
||||||
self._itemActive(False)
|
self._itemActive(False)
|
||||||
self._itemStatusImport(False)
|
self._itemStatusImport(False)
|
||||||
|
|
||||||
@@ -1833,6 +1834,15 @@ class _TreeContextMenu(QMenu):
|
|||||||
menu.addAction(self.projView.projBar.aAddFolder)
|
menu.addAction(self.projView.projBar.aAddFolder)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _itemHeader(self) -> None:
|
||||||
|
"""Check if there is a header that can be used for rename."""
|
||||||
|
if hItem := SHARED.project.index.getItemHeader(self._handle, "T0001"):
|
||||||
|
action = self.addAction(self.tr("Rename to Heading"))
|
||||||
|
action.triggered.connect(
|
||||||
|
lambda: self.projTree.renameTreeItem(self._handle, hItem.title)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
def _itemActive(self, multi: bool) -> None:
|
def _itemActive(self, multi: bool) -> None:
|
||||||
"""Add Active/Inactive actions."""
|
"""Add Active/Inactive actions."""
|
||||||
if multi:
|
if multi:
|
||||||
|
|||||||
@@ -1223,8 +1223,8 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
|||||||
ctxMenu.buildSingleSelectMenu(True)
|
ctxMenu.buildSingleSelectMenu(True)
|
||||||
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
||||||
assert actions == [
|
assert actions == [
|
||||||
"Open Document", "View Document", "Create New ...", "Rename", "Toggle Active",
|
"Open Document", "View Document", "Create New ...", "Rename", "Rename to Heading",
|
||||||
"Set Status to ...", "Transform ...", "Expand All", "Collapse All",
|
"Toggle Active", "Set Status to ...", "Transform ...", "Expand All", "Collapse All",
|
||||||
"Duplicate from Here", "Move to Trash",
|
"Duplicate from Here", "Move to Trash",
|
||||||
]
|
]
|
||||||
assert getTransformSubMenu(ctxMenu) == [
|
assert getTransformSubMenu(ctxMenu) == [
|
||||||
@@ -1239,8 +1239,9 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
|||||||
ctxMenu.buildSingleSelectMenu(False)
|
ctxMenu.buildSingleSelectMenu(False)
|
||||||
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
||||||
assert actions == [
|
assert actions == [
|
||||||
"Open Document", "View Document", "Create New ...", "Rename", "Toggle Active",
|
"Open Document", "View Document", "Create New ...", "Rename", "Rename to Heading",
|
||||||
"Set Importance to ...", "Transform ...", "Duplicate Document", "Move to Trash",
|
"Toggle Active", "Set Importance to ...", "Transform ...", "Duplicate Document",
|
||||||
|
"Move to Trash",
|
||||||
]
|
]
|
||||||
assert getTransformSubMenu(ctxMenu) == [
|
assert getTransformSubMenu(ctxMenu) == [
|
||||||
"Split Document by Headers",
|
"Split Document by Headers",
|
||||||
@@ -1253,8 +1254,9 @@ def testGuiProjTree_ContextMenu(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
|||||||
ctxMenu.buildSingleSelectMenu(False)
|
ctxMenu.buildSingleSelectMenu(False)
|
||||||
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
actions = [x.text() for x in ctxMenu.actions() if x.text()]
|
||||||
assert actions == [
|
assert actions == [
|
||||||
"Open Document", "View Document", "Create New ...", "Rename", "Toggle Active",
|
"Open Document", "View Document", "Create New ...", "Rename", "Rename to Heading",
|
||||||
"Set Status to ...", "Transform ...", "Duplicate Document", "Move to Trash",
|
"Toggle Active", "Set Status to ...", "Transform ...", "Duplicate Document",
|
||||||
|
"Move to Trash",
|
||||||
]
|
]
|
||||||
assert getTransformSubMenu(ctxMenu) == [
|
assert getTransformSubMenu(ctxMenu) == [
|
||||||
"Convert to Novel Document", "Split Document by Headers",
|
"Convert to Novel Document", "Split Document by Headers",
|
||||||
|
|||||||
Reference in New Issue
Block a user