Skip to content

Commit db892f6

Browse files
authored
New root folder location (#1487)
2 parents 925ead7 + 08648e0 commit db892f6

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

novelwriter/core/item.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import logging
2727

28-
from typing import TYPE_CHECKING, Any
28+
from typing import TYPE_CHECKING, Any, Literal, overload
2929

3030
from PyQt5.QtGui import QIcon
3131

@@ -308,7 +308,15 @@ def describeMe(self) -> str:
308308

309309
return trConst(nwLabels.ITEM_DESCRIPTION.get(descKey, ""))
310310

311-
def getImportStatus(self, incIcon: bool = True) -> tuple[str, QIcon | None]:
311+
@overload # pragma: no cover
312+
def getImportStatus(self, incIcon: Literal[True] = True) -> tuple[str, QIcon]:
313+
pass
314+
315+
@overload # pragma: no cover
316+
def getImportStatus(self, incIcon: Literal[False]) -> tuple[str, None]:
317+
pass
318+
319+
def getImportStatus(self, incIcon=True):
312320
"""Return the relevant importance or status label and icon for
313321
the current item based on its class.
314322
"""

novelwriter/core/tree.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ def handles(self) -> list[str]:
9393
"""Returns a copy of the list of all the active handles."""
9494
return self._treeOrder.copy()
9595

96-
@overload
96+
@overload # pragma: no cover
9797
def create(self, label: str, parent: None, itemType: Literal[nwItemType.ROOT],
98-
itemClass: nwItemClass) -> str: # pragma: no cover
98+
itemClass: nwItemClass) -> str:
9999
pass
100100

101-
@overload
101+
@overload # pragma: no cover
102102
def create(self, label: str, parent: str | None, itemType: nwItemType,
103-
itemClass: nwItemClass = nwItemClass.NO_CLASS) -> str | None: # pragma: no cover
103+
itemClass: nwItemClass = nwItemClass.NO_CLASS) -> str | None:
104104
pass
105105

106106
def create(self, label, parent, itemType, itemClass=nwItemClass.NO_CLASS):

novelwriter/gui/doceditor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ def updateInfo(self):
30343034
sIcon = QPixmap()
30353035
sText = ""
30363036
else:
3037-
theStatus, theIcon = self._theItem.getImportStatus()
3037+
theStatus, theIcon = self._theItem.getImportStatus(incIcon=True)
30383038
sIcon = theIcon.pixmap(self.sPx, self.sPx)
30393039
sText = f"{theStatus} / {self._theItem.describeMe()}"
30403040

novelwriter/gui/itemdetails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def updateViewBox(self, tHandle):
263263
# Status
264264
# ======
265265

266-
theStatus, theIcon = nwItem.getImportStatus()
266+
theStatus, theIcon = nwItem.getImportStatus(incIcon=True)
267267
self.statusIcon.setPixmap(theIcon.pixmap(iPx, iPx))
268268
self.statusData.setText(theStatus)
269269

novelwriter/gui/projtree.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class GuiProjectTree(QTreeWidget):
457457
D_HANDLE = Qt.ItemDataRole.UserRole
458458
D_WORDS = Qt.ItemDataRole.UserRole + 1
459459

460-
def __init__(self, projView: GuiProjectView):
460+
def __init__(self, projView: GuiProjectView) -> None:
461461
super().__init__(parent=projView)
462462

463463
logger.debug("Create: GuiProjectTree")
@@ -531,36 +531,33 @@ def __init__(self, projView: GuiProjectView):
531531

532532
return
533533

534-
def initSettings(self):
535-
"""Set or update tree widget settings.
536-
"""
534+
def initSettings(self) -> None:
535+
"""Set or update tree widget settings."""
537536
# Scroll bars
538537
if CONFIG.hideVScroll:
539538
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
540539
else:
541540
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
542-
543541
if CONFIG.hideHScroll:
544542
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
545543
else:
546544
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
547-
548545
return
549546

550547
##
551548
# Class Methods
552549
##
553550

554-
def clearTree(self):
555-
"""Clear the GUI content and the related map.
556-
"""
551+
def clearTree(self) -> None:
552+
"""Clear the GUI content and the related map."""
557553
self.clear()
558554
self._treeMap = {}
559555
self._lastMove = {}
560556
self._timeChanged = 0
561557
return
562558

563-
def newTreeItem(self, itemType, itemClass=None, hLevel=1, isNote=False):
559+
def newTreeItem(self, itemType: nwItemType, itemClass: nwItemClass | None = None,
560+
hLevel: int = 1, isNote: bool = False) -> bool:
564561
"""Add new item to the tree, with a given itemType (and
565562
itemClass if Root), and attach it to the selected handle. Also
566563
make sure the item is added in a place it can be added, and that
@@ -576,18 +573,21 @@ def newTreeItem(self, itemType, itemClass=None, hLevel=1, isNote=False):
576573
if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass):
577574

578575
tHandle = self.theProject.newRoot(itemClass)
576+
sHandle = self.getSelectedHandle()
577+
pItem = self.theProject.tree[sHandle] if sHandle else None
578+
nHandle = pItem.itemRoot if pItem else None
579579

580580
elif itemType in (nwItemType.FILE, nwItemType.FOLDER):
581581

582582
sHandle = self.getSelectedHandle()
583-
if sHandle is None or sHandle not in self.theProject.tree:
583+
pItem = self.theProject.tree[sHandle] if sHandle else None
584+
if sHandle is None or pItem is None:
584585
self.mainGui.makeAlert(self.tr(
585586
"Did not find anywhere to add the file or folder!"
586587
), nwAlert.ERROR)
587588
return False
588589

589-
# Collect some information about the selected item that
590-
pItem = self.theProject.tree[sHandle]
590+
# Collect some information about the selected item
591591
qItem = self._getTreeItem(sHandle)
592592
sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0)
593593
sIsParent = False if qItem is None else qItem.childCount() > 0
@@ -658,9 +658,8 @@ def newTreeItem(self, itemType, itemClass=None, hLevel=1, isNote=False):
658658

659659
return True
660660

661-
def revealNewTreeItem(
662-
self, tHandle: str, nHandle: str | None = None, wordCount: bool = False
663-
) -> bool:
661+
def revealNewTreeItem(self, tHandle: str, nHandle: str | None = None,
662+
wordCount: bool = False) -> bool:
664663
"""Reveal a newly added project item in the project tree."""
665664
nwItem = self.theProject.tree[tHandle]
666665
if not nwItem:
@@ -971,7 +970,7 @@ def setTreeItemValues(self, tHandle):
971970
if trItem is None or nwItem is None:
972971
return
973972

974-
itemStatus, statusIcon = nwItem.getImportStatus()
973+
itemStatus, statusIcon = nwItem.getImportStatus(incIcon=True)
975974
hLevel = nwItem.mainHeading
976975
itemIcon = self.mainTheme.getItemIcon(
977976
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
@@ -1452,10 +1451,9 @@ def _getItemWordCount(self, tHandle):
14521451
return 0
14531452
return int(tItem.data(self.C_DATA, self.D_WORDS))
14541453

1455-
def _getTreeItem(self, tHandle):
1456-
"""Return the QTreeWidgetItem of a given item handle.
1457-
"""
1458-
return self._treeMap.get(tHandle, None)
1454+
def _getTreeItem(self, tHandle: str | None) -> QTreeWidgetItem | None:
1455+
"""Return the QTreeWidgetItem of a given item handle."""
1456+
return self._treeMap.get(tHandle, None) if tHandle else None
14591457

14601458
def _toggleItemActive(self, tHandle):
14611459
"""Toggle the active status of an item.
@@ -1698,7 +1696,7 @@ def _duplicateFromHandle(self, tHandle: str) -> bool:
16981696

16991697
return True
17001698

1701-
def _scanChildren(self, itemList: list, tItem: QTreeWidgetItem, tIndex: int):
1699+
def _scanChildren(self, itemList: list, tItem: QTreeWidgetItem, tIndex: int) -> list[str]:
17021700
"""This is a recursive function returning all items in a tree
17031701
starting at a given QTreeWidgetItem.
17041702
"""

0 commit comments

Comments
 (0)