Clean up item notification and item main icon
This commit is contained in:
@@ -296,6 +296,7 @@ class NWIndex:
|
||||
self._indexChange = nowTime
|
||||
self._rootChange[tItem.itemRoot] = nowTime
|
||||
if not blockSignal:
|
||||
tItem.notifyToRefresh()
|
||||
SHARED.indexSignalProxy({
|
||||
"event": "scanText",
|
||||
"handle": tHandle,
|
||||
|
||||
@@ -321,6 +321,10 @@ class NWItem:
|
||||
|
||||
return trConst(nwLabels.ITEM_DESCRIPTION.get(descKey, ""))
|
||||
|
||||
def getMainIcon(self) -> QIcon:
|
||||
"""Get the main item icon."""
|
||||
return SHARED.theme.getItemIcon(self._type, self._class, self._layout, self._heading)
|
||||
|
||||
def getImportStatus(self) -> tuple[str, QIcon]:
|
||||
"""Return the relevant importance or status label and icon for
|
||||
the current item based on its class.
|
||||
|
||||
@@ -31,7 +31,6 @@ from typing import TYPE_CHECKING
|
||||
from PyQt5.QtCore import QAbstractItemModel, QMimeData, QModelIndex, Qt
|
||||
from PyQt5.QtGui import QIcon
|
||||
|
||||
from novelwriter import SHARED
|
||||
from novelwriter.common import decodeMimeHandles, minmax
|
||||
from novelwriter.constants import nwConst
|
||||
from novelwriter.core.item import NWItem
|
||||
@@ -116,10 +115,7 @@ class ProjectNode:
|
||||
def refresh(self) -> None:
|
||||
"""Refresh data values."""
|
||||
# Label
|
||||
self._cache[C_LABEL_ICON] = SHARED.theme.getItemIcon(
|
||||
self._item.itemType, self._item.itemClass,
|
||||
self._item.itemLayout, self._item.mainHeading
|
||||
)
|
||||
self._cache[C_LABEL_ICON] = self._item.getMainIcon()
|
||||
self._cache[C_LABEL_TEXT] = self._item.itemName
|
||||
|
||||
# Count
|
||||
|
||||
@@ -130,8 +130,9 @@ class NWStatus:
|
||||
if self._default not in self._store:
|
||||
self._default = next(iter(self._store)) if self._store else None
|
||||
|
||||
# Emit the change signal
|
||||
# Emit the change signal and refresh tree
|
||||
SHARED.projectSignalProxy({"event": "statusLabels", "kind": self._prefix})
|
||||
SHARED.project.tree.refreshAllItems()
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -248,6 +248,14 @@ class NWTree:
|
||||
self._project.setProjectChanged(True)
|
||||
return
|
||||
|
||||
def refreshAllItems(self) -> None:
|
||||
"""Refresh all items in the tree."""
|
||||
for node in reversed(self._model.root.allChildren()):
|
||||
node.refresh()
|
||||
node.updateCount(propagate=False)
|
||||
self._model.layoutChanged.emit()
|
||||
return
|
||||
|
||||
def checkConsistency(self, prefix: str) -> tuple[int, int]:
|
||||
"""Check the project tree consistency. Also check the content
|
||||
folder and add back files that were discovered but were not
|
||||
|
||||
Reference in New Issue
Block a user