Re-enable item rename
This commit is contained in:
@@ -55,7 +55,7 @@ class NWItem:
|
|||||||
"_project", "_name", "_handle", "_parent", "_root", "_order",
|
"_project", "_name", "_handle", "_parent", "_root", "_order",
|
||||||
"_type", "_class", "_layout", "_status", "_import", "_active",
|
"_type", "_class", "_layout", "_status", "_import", "_active",
|
||||||
"_expanded", "_heading", "_charCount", "_wordCount",
|
"_expanded", "_heading", "_charCount", "_wordCount",
|
||||||
"_paraCount", "_cursorPos", "_initCount",
|
"_paraCount", "_cursorPos", "_initCount", "_blocked",
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, project: NWProject, handle: str) -> None:
|
def __init__(self, project: NWProject, handle: str) -> None:
|
||||||
@@ -82,6 +82,8 @@ class NWItem:
|
|||||||
self._cursorPos = 0 # Last cursor position
|
self._cursorPos = 0 # Last cursor position
|
||||||
self._initCount = 0 # Initial word count
|
self._initCount = 0 # Initial word count
|
||||||
|
|
||||||
|
self._blocked = True
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@@ -257,6 +259,7 @@ class NWItem:
|
|||||||
self._cursorPos = 0
|
self._cursorPos = 0
|
||||||
|
|
||||||
self._initCount = self._wordCount
|
self._initCount = self._wordCount
|
||||||
|
self._blocked = False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -281,6 +284,7 @@ class NWItem:
|
|||||||
cls._paraCount = source._paraCount
|
cls._paraCount = source._paraCount
|
||||||
cls._cursorPos = source._cursorPos
|
cls._cursorPos = source._cursorPos
|
||||||
cls._initCount = source._initCount
|
cls._initCount = source._initCount
|
||||||
|
cls._blocked = source._blocked
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -415,6 +419,7 @@ class NWItem:
|
|||||||
self._name = simplified(name)
|
self._name = simplified(name)
|
||||||
else:
|
else:
|
||||||
self._name = ""
|
self._name = ""
|
||||||
|
self._notifyChange()
|
||||||
return
|
return
|
||||||
|
|
||||||
def setParent(self, handle: Any) -> None:
|
def setParent(self, handle: Any) -> None:
|
||||||
@@ -560,3 +565,13 @@ class NWItem:
|
|||||||
"""Save the initial word count."""
|
"""Save the initial word count."""
|
||||||
self._initCount = self._wordCount
|
self._initCount = self._wordCount
|
||||||
return
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Internal Functions
|
||||||
|
##
|
||||||
|
|
||||||
|
def _notifyChange(self) -> None:
|
||||||
|
"""Notify project tree on user changes to the item."""
|
||||||
|
if not self._blocked:
|
||||||
|
self._project.tree.refreshNode(self._handle)
|
||||||
|
return
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class NWStatus:
|
|||||||
self._default = next(iter(self._store)) if self._store else None
|
self._default = next(iter(self._store)) if self._store else None
|
||||||
|
|
||||||
# Emit the change signal
|
# Emit the change signal
|
||||||
SHARED.projectSingalProxy({"event": "statusLabels", "kind": self._prefix})
|
SHARED.projectSignalProxy({"event": "statusLabels", "kind": self._prefix})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
+14
-17
@@ -30,6 +30,7 @@ from collections.abc import Iterable, Iterator
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Literal, overload
|
from typing import TYPE_CHECKING, Literal, overload
|
||||||
|
|
||||||
|
from novelwriter import SHARED
|
||||||
from novelwriter.constants import nwFiles
|
from novelwriter.constants import nwFiles
|
||||||
from novelwriter.core.item import NWItem
|
from novelwriter.core.item import NWItem
|
||||||
from novelwriter.core.itemmodel import ProjectModel, ProjectNode
|
from novelwriter.core.itemmodel import ProjectModel, ProjectNode
|
||||||
@@ -68,20 +69,12 @@ class NWTree:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, project: NWProject) -> None:
|
def __init__(self, project: NWProject) -> None:
|
||||||
|
|
||||||
self._project = project
|
self._project = project
|
||||||
|
|
||||||
# self._tree: dict[str, NWItem] = {} # Holds all the items of the project
|
|
||||||
# self._order: list[str] = [] # The order of the tree items in the tree view
|
|
||||||
# self._roots: dict[str, NWItem] = {} # The root items of the tree
|
|
||||||
|
|
||||||
self._model = ProjectModel(self)
|
self._model = ProjectModel(self)
|
||||||
self._items: dict[str, NWItem] = {}
|
self._items: dict[str, NWItem] = {}
|
||||||
self._nodes: dict[str, ProjectNode] = {}
|
self._nodes: dict[str, ProjectNode] = {}
|
||||||
|
|
||||||
self._trash = None # The handle of the trash root folder
|
self._trash = None # The handle of the trash root folder
|
||||||
self._changed = False # True if tree structure has changed
|
self._changed = False # True if tree structure has changed
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -107,15 +100,10 @@ class NWTree:
|
|||||||
|
|
||||||
def clear(self) -> None:
|
def clear(self) -> None:
|
||||||
"""Clear the item tree entirely."""
|
"""Clear the item tree entirely."""
|
||||||
# self._tree = {}
|
self._model = ProjectModel(self)
|
||||||
# self._order = []
|
self._items = {}
|
||||||
# self._roots = {}
|
self._nodes = {}
|
||||||
|
self._trash = None
|
||||||
self._model = ProjectModel(self)
|
|
||||||
self._items = {}
|
|
||||||
self._nodes = {}
|
|
||||||
|
|
||||||
self._trash = None
|
|
||||||
self._changed = False
|
self._changed = False
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -237,6 +225,15 @@ class NWTree:
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def refreshNode(self, tHandle: str) -> None:
|
||||||
|
"""Refresh node data on item change."""
|
||||||
|
if node := self._nodes.get(tHandle):
|
||||||
|
node.refresh()
|
||||||
|
index = self._model.indexFromNode(node)
|
||||||
|
SHARED.projectSignalProxy({"event": "projectItem", "handle": tHandle})
|
||||||
|
self._model.dataChanged.emit(index, index)
|
||||||
|
return
|
||||||
|
|
||||||
def _buildTree(self, items: dict[str, NWItem]) -> dict[str, NWItem]:
|
def _buildTree(self, items: dict[str, NWItem]) -> dict[str, NWItem]:
|
||||||
""""""
|
""""""
|
||||||
remains: dict[str, NWItem] = {}
|
remains: dict[str, NWItem] = {}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ from novelwriter.common import qtLambda
|
|||||||
from novelwriter.constants import nwLabels, nwUnicode, trConst
|
from novelwriter.constants import nwLabels, nwUnicode, trConst
|
||||||
from novelwriter.core.item import NWItem
|
from novelwriter.core.item import NWItem
|
||||||
from novelwriter.core.itemmodel import ProjectModel, ProjectNode
|
from novelwriter.core.itemmodel import ProjectModel, ProjectNode
|
||||||
|
from novelwriter.dialogs.editlabel import GuiEditLabel
|
||||||
from novelwriter.dialogs.projectsettings import GuiProjectSettings
|
from novelwriter.dialogs.projectsettings import GuiProjectSettings
|
||||||
from novelwriter.enum import nwDocMode, nwItemClass, nwItemLayout, nwItemType
|
from novelwriter.enum import nwDocMode, nwItemClass, nwItemLayout, nwItemType
|
||||||
from novelwriter.extensions.modified import NIconToolButton
|
from novelwriter.extensions.modified import NIconToolButton
|
||||||
@@ -58,7 +59,7 @@ class GuiProjectView(QWidget):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Signals triggered when the meta data values of items change
|
# Signals triggered when the meta data values of items change
|
||||||
treeItemChanged = pyqtSignal(str)
|
# treeItemChanged = pyqtSignal(str)
|
||||||
rootFolderChanged = pyqtSignal(str)
|
rootFolderChanged = pyqtSignal(str)
|
||||||
wordCountsChanged = pyqtSignal()
|
wordCountsChanged = pyqtSignal()
|
||||||
|
|
||||||
@@ -193,8 +194,10 @@ class GuiProjectView(QWidget):
|
|||||||
"""
|
"""
|
||||||
if tHandle is None:
|
if tHandle is None:
|
||||||
tHandle = self.projTree.getSelectedHandle()
|
tHandle = self.projTree.getSelectedHandle()
|
||||||
if tHandle:
|
if nwItem := SHARED.project.tree[tHandle]:
|
||||||
self.projTree.renameTreeItem(tHandle, name=name)
|
newLabel, dlgOk = GuiEditLabel.getLabel(self, text=name or nwItem.itemName)
|
||||||
|
if dlgOk:
|
||||||
|
nwItem.setName(newLabel)
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(str, bool)
|
@pyqtSlot(str, bool)
|
||||||
@@ -893,16 +896,6 @@ class GuiProjectTree(QTreeView):
|
|||||||
# self.setCurrentItem(tItem.child(0))
|
# self.setCurrentItem(tItem.child(0))
|
||||||
return
|
return
|
||||||
|
|
||||||
def renameTreeItem(self, tHandle: str, name: str = "") -> None:
|
|
||||||
"""Open a dialog to edit the label of an item."""
|
|
||||||
# if nwItem := SHARED.project.tree[tHandle]:
|
|
||||||
# newLabel, dlgOk = GuiEditLabel.getLabel(self, text=name or nwItem.itemName)
|
|
||||||
# if dlgOk:
|
|
||||||
# nwItem.setName(newLabel)
|
|
||||||
# self.setTreeItemValues(nwItem)
|
|
||||||
# self._alertTreeChange(tHandle, flush=False)
|
|
||||||
return
|
|
||||||
|
|
||||||
# def saveTreeOrder(self) -> None:
|
# def saveTreeOrder(self) -> None:
|
||||||
# """Build a list of the items in the project tree and send them
|
# """Build a list of the items in the project tree and send them
|
||||||
# to the project class. This syncs up the two versions of the
|
# to the project class. This syncs up the two versions of the
|
||||||
@@ -1848,7 +1841,7 @@ class _TreeContextMenu(QMenu):
|
|||||||
|
|
||||||
# Edit Item Settings
|
# Edit Item Settings
|
||||||
action = self.addAction(self.tr("Rename"))
|
action = self.addAction(self.tr("Rename"))
|
||||||
action.triggered.connect(qtLambda(self.projTree.renameTreeItem, self._handle))
|
action.triggered.connect(qtLambda(self.projView.renameTreeItem, self._handle))
|
||||||
if isFile:
|
if isFile:
|
||||||
self._itemHeader()
|
self._itemHeader()
|
||||||
self._itemActive(False)
|
self._itemActive(False)
|
||||||
@@ -1911,7 +1904,7 @@ class _TreeContextMenu(QMenu):
|
|||||||
if hItem := SHARED.project.index.getItemHeading(self._handle, "T0001"):
|
if hItem := SHARED.project.index.getItemHeading(self._handle, "T0001"):
|
||||||
action = self.addAction(self.tr("Rename to Heading"))
|
action = self.addAction(self.tr("Rename to Heading"))
|
||||||
action.triggered.connect(
|
action.triggered.connect(
|
||||||
qtLambda(self.projTree.renameTreeItem, self._handle, hItem.title)
|
qtLambda(self.projView.renameTreeItem, self._handle, hItem.title)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -216,6 +216,10 @@ class GuiMain(QMainWindow):
|
|||||||
SHARED.indexScannedText.connect(self.itemDetails.updateViewBox)
|
SHARED.indexScannedText.connect(self.itemDetails.updateViewBox)
|
||||||
SHARED.indexScannedText.connect(self.projView.updateItemValues)
|
SHARED.indexScannedText.connect(self.projView.updateItemValues)
|
||||||
SHARED.mainClockTick.connect(self._timeTick)
|
SHARED.mainClockTick.connect(self._timeTick)
|
||||||
|
SHARED.projectItemChanged.connect(self.docEditor.updateDocInfo)
|
||||||
|
SHARED.projectItemChanged.connect(self.docViewer.updateDocInfo)
|
||||||
|
SHARED.projectItemChanged.connect(self.docViewerPanel.projectItemChanged)
|
||||||
|
SHARED.projectItemChanged.connect(self.itemDetails.updateViewBox)
|
||||||
SHARED.projectStatusChanged.connect(self.mainStatus.updateProjectStatus)
|
SHARED.projectStatusChanged.connect(self.mainStatus.updateProjectStatus)
|
||||||
SHARED.projectStatusMessage.connect(self.mainStatus.setStatusMessage)
|
SHARED.projectStatusMessage.connect(self.mainStatus.setStatusMessage)
|
||||||
SHARED.spellLanguageChanged.connect(self.mainStatus.setLanguage)
|
SHARED.spellLanguageChanged.connect(self.mainStatus.setLanguage)
|
||||||
@@ -237,10 +241,6 @@ class GuiMain(QMainWindow):
|
|||||||
self.projView.rootFolderChanged.connect(self.outlineView.updateRootItem)
|
self.projView.rootFolderChanged.connect(self.outlineView.updateRootItem)
|
||||||
self.projView.rootFolderChanged.connect(self.projView.updateRootItem)
|
self.projView.rootFolderChanged.connect(self.projView.updateRootItem)
|
||||||
self.projView.selectedItemChanged.connect(self.itemDetails.updateViewBox)
|
self.projView.selectedItemChanged.connect(self.itemDetails.updateViewBox)
|
||||||
self.projView.treeItemChanged.connect(self.docEditor.updateDocInfo)
|
|
||||||
self.projView.treeItemChanged.connect(self.docViewer.updateDocInfo)
|
|
||||||
self.projView.treeItemChanged.connect(self.docViewerPanel.projectItemChanged)
|
|
||||||
self.projView.treeItemChanged.connect(self.itemDetails.updateViewBox)
|
|
||||||
self.projView.wordCountsChanged.connect(self._updateStatusWordCount)
|
self.projView.wordCountsChanged.connect(self._updateStatusWordCount)
|
||||||
|
|
||||||
self.novelView.openDocumentRequest.connect(self._openDocument)
|
self.novelView.openDocumentRequest.connect(self._openDocument)
|
||||||
|
|||||||
+10
-7
@@ -55,15 +55,16 @@ class SharedData(QObject):
|
|||||||
"_idleTime", "_idleRefTime",
|
"_idleTime", "_idleRefTime",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
focusModeChanged = pyqtSignal(bool)
|
||||||
|
indexAvailable = pyqtSignal()
|
||||||
|
indexChangedTags = pyqtSignal(list, list)
|
||||||
|
indexCleared = pyqtSignal()
|
||||||
|
indexScannedText = pyqtSignal(str)
|
||||||
|
mainClockTick = pyqtSignal()
|
||||||
|
projectItemChanged = pyqtSignal(str)
|
||||||
projectStatusChanged = pyqtSignal(bool)
|
projectStatusChanged = pyqtSignal(bool)
|
||||||
projectStatusMessage = pyqtSignal(str)
|
projectStatusMessage = pyqtSignal(str)
|
||||||
spellLanguageChanged = pyqtSignal(str, str)
|
spellLanguageChanged = pyqtSignal(str, str)
|
||||||
focusModeChanged = pyqtSignal(bool)
|
|
||||||
indexScannedText = pyqtSignal(str)
|
|
||||||
indexChangedTags = pyqtSignal(list, list)
|
|
||||||
indexCleared = pyqtSignal()
|
|
||||||
indexAvailable = pyqtSignal()
|
|
||||||
mainClockTick = pyqtSignal()
|
|
||||||
statusLabelsChanged = pyqtSignal(str)
|
statusLabelsChanged = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@@ -320,12 +321,14 @@ class SharedData(QObject):
|
|||||||
self.indexAvailable.emit()
|
self.indexAvailable.emit()
|
||||||
return
|
return
|
||||||
|
|
||||||
def projectSingalProxy(self, data: dict) -> None:
|
def projectSignalProxy(self, data: dict) -> None:
|
||||||
"""Emit signals on project data change."""
|
"""Emit signals on project data change."""
|
||||||
event = data.get("event")
|
event = data.get("event")
|
||||||
logger.debug("Received '%s' event from project data", event)
|
logger.debug("Received '%s' event from project data", event)
|
||||||
if event == "statusLabels":
|
if event == "statusLabels":
|
||||||
self.statusLabelsChanged.emit(data.get("kind", ""))
|
self.statusLabelsChanged.emit(data.get("kind", ""))
|
||||||
|
elif event == "projectItem":
|
||||||
|
self.projectItemChanged.emit(data.get("handle", ""))
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user