Allow showing all novel files in Outline

This commit is contained in:
Veronica Berglyd Olsen
2022-06-05 18:43:09 +02:00
parent 92924b3288
commit 85f63721e0
3 changed files with 26 additions and 26 deletions
+5 -6
View File
@@ -273,14 +273,13 @@ class NWTree():
rootClasses.add(nwItem.itemClass) rootClasses.add(nwItem.itemClass)
return rootClasses return rootClasses
def novelRoots(self): def iterRoots(self, itemClass):
"""Return a doctionary of all novel-like root items. """Iterate over all items of a given class.
""" """
novelItems = {}
for tHandle, nwItem in self._treeRoots.items(): for tHandle, nwItem in self._treeRoots.items():
if nwItem.isNovelLike(): if nwItem.itemClass == itemClass:
novelItems[tHandle] = nwItem yield tHandle, nwItem
return novelItems return
def isRoot(self, tHandle): def isRoot(self, tHandle):
"""Check if a handle is a root item. """Check if a handle is a root item.
+20 -19
View File
@@ -83,11 +83,8 @@ class GuiOutline(QWidget):
self.outlineView.hiddenStateChanged.connect(self._updateMenuColumns) self.outlineView.hiddenStateChanged.connect(self._updateMenuColumns)
self.outlineView.activeItemChanged.connect(self.outlineData.showItem) self.outlineView.activeItemChanged.connect(self.outlineData.showItem)
self.outlineData.itemTagClicked.connect(self._tagClicked) self.outlineData.itemTagClicked.connect(self._tagClicked)
self.outlineBar.novelRootChanged.connect(self._rootItemChanged) self.outlineBar.loadNovelRootRequest.connect(self._rootItemChanged)
self.outlineBar.viewColumnToggled.connect(self.outlineView.menuColumnToggled) self.outlineBar.viewColumnToggled.connect(self.outlineView.menuColumnToggled)
self.outlineBar.viewRefreshRequested.connect(
lambda: self.outlineView.refreshTree(overRide=True)
)
# Function Mappings # Function Mappings
self.getSelectedHandle = self.outlineView.getSelectedHandle self.getSelectedHandle = self.outlineView.getSelectedHandle
@@ -160,9 +157,9 @@ class GuiOutline(QWidget):
@pyqtSlot(str) @pyqtSlot(str)
def _rootItemChanged(self, handle): def _rootItemChanged(self, handle):
"""The root novel handle has been changed. """The root novel handle has changed or needs to be refreshed.
""" """
self.outlineView.refreshTree(rootHandle=handle, overRide=True) self.outlineView.refreshTree(rootHandle=(handle or None), overRide=True)
return return
# END Class GuiOutline # END Class GuiOutline
@@ -170,8 +167,7 @@ class GuiOutline(QWidget):
class GuiOutlineToolBar(QToolBar): class GuiOutlineToolBar(QToolBar):
novelRootChanged = pyqtSignal(str) loadNovelRootRequest = pyqtSignal(str)
viewRefreshRequested = pyqtSignal()
viewColumnToggled = pyqtSignal(bool, Enum) viewColumnToggled = pyqtSignal(bool, Enum)
def __init__(self, theOutline): def __init__(self, theOutline):
@@ -206,9 +202,7 @@ class GuiOutlineToolBar(QToolBar):
# Actions # Actions
self.aRefresh = QAction(self.tr("Refresh"), self) self.aRefresh = QAction(self.tr("Refresh"), self)
self.aRefresh.setIcon(self.theTheme.getIcon("refresh")) self.aRefresh.setIcon(self.theTheme.getIcon("refresh"))
self.aRefresh.triggered.connect( self.aRefresh.triggered.connect(self._refreshRequested)
lambda: self.viewRefreshRequested.emit()
)
# Column Menu # Column Menu
self.mColumns = GuiOutlineHeaderMenu(self) self.mColumns = GuiOutlineHeaderMenu(self)
@@ -236,14 +230,14 @@ class GuiOutlineToolBar(QToolBar):
## ##
def populateNovelList(self): def populateNovelList(self):
"""Fill the novel combo box. """Fill the novel combo box with a list of all novel folders.
""" """
self.novelValue.clear() self.novelValue.clear()
for tHandle, nwItem in self.theProject.tree.novelRoots().items(): tIcon = self.theTheme.getIcon(nwLabels.CLASS_ICON[nwItemClass.NOVEL])
self.novelValue.addItem( for tHandle, nwItem in self.theProject.tree.iterRoots(nwItemClass.NOVEL):
self.theTheme.getIcon(nwLabels.CLASS_ICON[nwItem.itemClass]), self.novelValue.addItem(tIcon, nwItem.itemName, tHandle)
nwItem.itemName, tHandle self.novelValue.insertSeparator(self.novelValue.count())
) self.novelValue.addItem(tIcon, self.tr("All Novel Folders"), "")
return return
def setColumnHiddenState(self, hiddenState): def setColumnHiddenState(self, hiddenState):
@@ -253,7 +247,7 @@ class GuiOutlineToolBar(QToolBar):
return return
## ##
# Slots # Private Slots
## ##
@pyqtSlot(int) @pyqtSlot(int)
@@ -261,7 +255,14 @@ class GuiOutlineToolBar(QToolBar):
"""Emit a signal containing the handle of the selected item. """Emit a signal containing the handle of the selected item.
""" """
if index >= 0: if index >= 0:
self.novelRootChanged.emit(self.novelValue.currentData()) self.loadNovelRootRequest.emit(self.novelValue.currentData())
return
@pyqtSlot()
def _refreshRequested(self):
"""Emit a signal containing the handle of the selected item.
"""
self.loadNovelRootRequest.emit(self.novelValue.currentData())
return return
# END Class GuiOutlineToolBar # END Class GuiOutlineToolBar
+1 -1
View File
@@ -939,7 +939,7 @@ class GuiProjectTree(QTreeWidget):
except Exception: except Exception:
logger.error("Failed to get index of item with handle '%s'", nHandle) logger.error("Failed to get index of item with handle '%s'", nHandle)
if byIndex >= 0: if byIndex >= 0:
self._treeMap[pHandle].insertChild(byIndex+1, newItem) self._treeMap[pHandle].insertChild(byIndex + 1, newItem)
else: else:
self._treeMap[pHandle].addChild(newItem) self._treeMap[pHandle].addChild(newItem)
self.propagateCount(tHandle, nwItem.wordCount, countChildren=True) self.propagateCount(tHandle, nwItem.wordCount, countChildren=True)