Allow root folders to be created next to selected root
This commit is contained in:
+20
-22
@@ -457,7 +457,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
D_HANDLE = Qt.ItemDataRole.UserRole
|
D_HANDLE = Qt.ItemDataRole.UserRole
|
||||||
D_WORDS = Qt.ItemDataRole.UserRole + 1
|
D_WORDS = Qt.ItemDataRole.UserRole + 1
|
||||||
|
|
||||||
def __init__(self, projView: GuiProjectView):
|
def __init__(self, projView: GuiProjectView) -> None:
|
||||||
super().__init__(parent=projView)
|
super().__init__(parent=projView)
|
||||||
|
|
||||||
logger.debug("Create: GuiProjectTree")
|
logger.debug("Create: GuiProjectTree")
|
||||||
@@ -531,36 +531,33 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def initSettings(self):
|
def initSettings(self) -> None:
|
||||||
"""Set or update tree widget settings.
|
"""Set or update tree widget settings."""
|
||||||
"""
|
|
||||||
# Scroll bars
|
# Scroll bars
|
||||||
if CONFIG.hideVScroll:
|
if CONFIG.hideVScroll:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||||
|
|
||||||
if CONFIG.hideHScroll:
|
if CONFIG.hideHScroll:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
else:
|
else:
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Class Methods
|
# Class Methods
|
||||||
##
|
##
|
||||||
|
|
||||||
def clearTree(self):
|
def clearTree(self) -> None:
|
||||||
"""Clear the GUI content and the related map.
|
"""Clear the GUI content and the related map."""
|
||||||
"""
|
|
||||||
self.clear()
|
self.clear()
|
||||||
self._treeMap = {}
|
self._treeMap = {}
|
||||||
self._lastMove = {}
|
self._lastMove = {}
|
||||||
self._timeChanged = 0
|
self._timeChanged = 0
|
||||||
return
|
return
|
||||||
|
|
||||||
def newTreeItem(self, itemType, itemClass=None, hLevel=1, isNote=False):
|
def newTreeItem(self, itemType: nwItemType, itemClass: nwItemClass | None = None,
|
||||||
|
hLevel: int = 1, isNote: bool = False) -> bool:
|
||||||
"""Add new item to the tree, with a given itemType (and
|
"""Add new item to the tree, with a given itemType (and
|
||||||
itemClass if Root), and attach it to the selected handle. Also
|
itemClass if Root), and attach it to the selected handle. Also
|
||||||
make sure the item is added in a place it can be added, and that
|
make sure the item is added in a place it can be added, and that
|
||||||
@@ -576,18 +573,21 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass):
|
if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass):
|
||||||
|
|
||||||
tHandle = self.theProject.newRoot(itemClass)
|
tHandle = self.theProject.newRoot(itemClass)
|
||||||
|
sHandle = self.getSelectedHandle()
|
||||||
|
pItem = self.theProject.tree[sHandle] if sHandle else None
|
||||||
|
nHandle = pItem.itemRoot if pItem else None
|
||||||
|
|
||||||
elif itemType in (nwItemType.FILE, nwItemType.FOLDER):
|
elif itemType in (nwItemType.FILE, nwItemType.FOLDER):
|
||||||
|
|
||||||
sHandle = self.getSelectedHandle()
|
sHandle = self.getSelectedHandle()
|
||||||
if sHandle is None or sHandle not in self.theProject.tree:
|
pItem = self.theProject.tree[sHandle] if sHandle else None
|
||||||
|
if sHandle is None or pItem is None:
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"Did not find anywhere to add the file or folder!"
|
"Did not find anywhere to add the file or folder!"
|
||||||
), nwAlert.ERROR)
|
), nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Collect some information about the selected item that
|
# Collect some information about the selected item
|
||||||
pItem = self.theProject.tree[sHandle]
|
|
||||||
qItem = self._getTreeItem(sHandle)
|
qItem = self._getTreeItem(sHandle)
|
||||||
sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0)
|
sLevel = nwHeaders.H_LEVEL.get(pItem.mainHeading, 0)
|
||||||
sIsParent = False if qItem is None else qItem.childCount() > 0
|
sIsParent = False if qItem is None else qItem.childCount() > 0
|
||||||
@@ -658,9 +658,8 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def revealNewTreeItem(
|
def revealNewTreeItem(self, tHandle: str, nHandle: str | None = None,
|
||||||
self, tHandle: str, nHandle: str | None = None, wordCount: bool = False
|
wordCount: bool = False) -> bool:
|
||||||
) -> bool:
|
|
||||||
"""Reveal a newly added project item in the project tree."""
|
"""Reveal a newly added project item in the project tree."""
|
||||||
nwItem = self.theProject.tree[tHandle]
|
nwItem = self.theProject.tree[tHandle]
|
||||||
if not nwItem:
|
if not nwItem:
|
||||||
@@ -971,7 +970,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
if trItem is None or nwItem is None:
|
if trItem is None or nwItem is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
itemStatus, statusIcon = nwItem.getImportStatus()
|
itemStatus, statusIcon = nwItem.getImportStatus(incIcon=True)
|
||||||
hLevel = nwItem.mainHeading
|
hLevel = nwItem.mainHeading
|
||||||
itemIcon = self.mainTheme.getItemIcon(
|
itemIcon = self.mainTheme.getItemIcon(
|
||||||
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel
|
||||||
@@ -1452,10 +1451,9 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
return 0
|
return 0
|
||||||
return int(tItem.data(self.C_DATA, self.D_WORDS))
|
return int(tItem.data(self.C_DATA, self.D_WORDS))
|
||||||
|
|
||||||
def _getTreeItem(self, tHandle):
|
def _getTreeItem(self, tHandle: str | None) -> QTreeWidgetItem | None:
|
||||||
"""Return the QTreeWidgetItem of a given item handle.
|
"""Return the QTreeWidgetItem of a given item handle."""
|
||||||
"""
|
return self._treeMap.get(tHandle, None) if tHandle else None
|
||||||
return self._treeMap.get(tHandle, None)
|
|
||||||
|
|
||||||
def _toggleItemActive(self, tHandle):
|
def _toggleItemActive(self, tHandle):
|
||||||
"""Toggle the active status of an item.
|
"""Toggle the active status of an item.
|
||||||
@@ -1698,7 +1696,7 @@ class GuiProjectTree(QTreeWidget):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _scanChildren(self, itemList: list, tItem: QTreeWidgetItem, tIndex: int):
|
def _scanChildren(self, itemList: list, tItem: QTreeWidgetItem, tIndex: int) -> list[str]:
|
||||||
"""This is a recursive function returning all items in a tree
|
"""This is a recursive function returning all items in a tree
|
||||||
starting at a given QTreeWidgetItem.
|
starting at a given QTreeWidgetItem.
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user