Re-enable item rename

This commit is contained in:
Veronica Berglyd Olsen
2024-11-18 00:01:40 +01:00
parent 4f8e898440
commit 337f05f60e
6 changed files with 53 additions and 45 deletions
+16 -1
View File
@@ -55,7 +55,7 @@ class NWItem:
"_project", "_name", "_handle", "_parent", "_root", "_order",
"_type", "_class", "_layout", "_status", "_import", "_active",
"_expanded", "_heading", "_charCount", "_wordCount",
"_paraCount", "_cursorPos", "_initCount",
"_paraCount", "_cursorPos", "_initCount", "_blocked",
)
def __init__(self, project: NWProject, handle: str) -> None:
@@ -82,6 +82,8 @@ class NWItem:
self._cursorPos = 0 # Last cursor position
self._initCount = 0 # Initial word count
self._blocked = True
return
def __repr__(self) -> str:
@@ -257,6 +259,7 @@ class NWItem:
self._cursorPos = 0
self._initCount = self._wordCount
self._blocked = False
return True
@@ -281,6 +284,7 @@ class NWItem:
cls._paraCount = source._paraCount
cls._cursorPos = source._cursorPos
cls._initCount = source._initCount
cls._blocked = source._blocked
return cls
##
@@ -415,6 +419,7 @@ class NWItem:
self._name = simplified(name)
else:
self._name = ""
self._notifyChange()
return
def setParent(self, handle: Any) -> None:
@@ -560,3 +565,13 @@ class NWItem:
"""Save the initial word count."""
self._initCount = self._wordCount
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
+1 -1
View File
@@ -131,7 +131,7 @@ class NWStatus:
self._default = next(iter(self._store)) if self._store else None
# Emit the change signal
SHARED.projectSingalProxy({"event": "statusLabels", "kind": self._prefix})
SHARED.projectSignalProxy({"event": "statusLabels", "kind": self._prefix})
return
+14 -17
View File
@@ -30,6 +30,7 @@ from collections.abc import Iterable, Iterator
from pathlib import Path
from typing import TYPE_CHECKING, Literal, overload
from novelwriter import SHARED
from novelwriter.constants import nwFiles
from novelwriter.core.item import NWItem
from novelwriter.core.itemmodel import ProjectModel, ProjectNode
@@ -68,20 +69,12 @@ class NWTree:
)
def __init__(self, project: NWProject) -> None:
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._items: dict[str, NWItem] = {}
self._nodes: dict[str, ProjectNode] = {}
self._trash = None # The handle of the trash root folder
self._changed = False # True if tree structure has changed
return
##
@@ -107,15 +100,10 @@ class NWTree:
def clear(self) -> None:
"""Clear the item tree entirely."""
# self._tree = {}
# self._order = []
# self._roots = {}
self._model = ProjectModel(self)
self._items = {}
self._nodes = {}
self._trash = None
self._model = ProjectModel(self)
self._items = {}
self._nodes = {}
self._trash = None
self._changed = False
return
@@ -237,6 +225,15 @@ class NWTree:
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]:
""""""
remains: dict[str, NWItem] = {}