Use novel selector for project details

This commit is contained in:
Veronica Berglyd Olsen
2022-11-22 12:45:10 +01:00
parent 55f7a91eaf
commit f26a745d0e
3 changed files with 33 additions and 28 deletions
+14 -28
View File
@@ -30,15 +30,14 @@ import novelwriter
from PyQt5.QtCore import Qt, QSize, pyqtSlot from PyQt5.QtCore import Qt, QSize, pyqtSlot
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractItemView, QComboBox, QDialogButtonBox, QGridLayout, QHBoxLayout, QAbstractItemView, QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel,
QLabel, QLineEdit, QSpinBox, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QLineEdit, QSpinBox, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
QWidget
) )
from novelwriter.enum import nwItemClass
from novelwriter.common import numberToRoman from novelwriter.common import numberToRoman
from novelwriter.custom import PagedDialog, QSwitch from novelwriter.custom import PagedDialog, QSwitch
from novelwriter.constants import nwLabels, nwUnicode from novelwriter.constants import nwUnicode
from novelwriter.gui.components import NovelSelector
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -297,9 +296,9 @@ class GuiProjectDetailsContents(QWidget):
self.tocLabel = QLabel("<b>%s</b>" % self.tr("Table of Contents")) self.tocLabel = QLabel("<b>%s</b>" % self.tr("Table of Contents"))
self.novelValue = QComboBox(self) self.novelValue = NovelSelector(self, self.theProject, self.mainGui)
self.novelValue.setMinimumWidth(self.mainConf.pxInt(200)) self.novelValue.setMinimumWidth(self.mainConf.pxInt(200))
self.novelValue.currentIndexChanged.connect(self._novelValueChanged) self.novelValue.novelSelectionChanged.connect(self._novelValueChanged)
self.headBox = QHBoxLayout() self.headBox = QHBoxLayout()
self.headBox.addWidget(self.tocLabel) self.headBox.addWidget(self.tocLabel)
@@ -431,10 +430,9 @@ class GuiProjectDetailsContents(QWidget):
"""Populate the tree. """Populate the tree.
""" """
self._currentRoot = None self._currentRoot = None
self._populateNovelList() self.novelValue.updateList()
self.novelValue.setHandle(self.novelValue.firstHandle)
rootHandle = self.novelValue.currentData() self._prepareData(self.novelValue.firstHandle)
self._prepareData(rootHandle)
self._populateTree() self._populateTree()
return return
@@ -443,17 +441,6 @@ class GuiProjectDetailsContents(QWidget):
# Internal Functions # Internal Functions
## ##
def _populateNovelList(self):
"""Fill the novel combo box with a list of all novel folders.
"""
self.novelValue.clear()
tIcon = self.mainTheme.getIcon(nwLabels.CLASS_ICON[nwItemClass.NOVEL])
for tHandle, nwItem in self.theProject.tree.iterRoots(nwItemClass.NOVEL):
self.novelValue.addItem(tIcon, nwItem.itemName, tHandle)
return
def _prepareData(self, rootHandle): def _prepareData(self, rootHandle):
"""Extract the information from the project index. """Extract the information from the project index.
""" """
@@ -466,15 +453,14 @@ class GuiProjectDetailsContents(QWidget):
# Slots # Slots
## ##
@pyqtSlot() @pyqtSlot(str)
def _novelValueChanged(self): def _novelValueChanged(self, tHandle):
"""Refresh the tree with another root item. """Refresh the tree with another root item.
""" """
rootHandle = self.novelValue.currentData() if tHandle != self._currentRoot:
if rootHandle != self._currentRoot: self._prepareData(tHandle)
self._prepareData(rootHandle)
self._populateTree() self._populateTree()
self._currentRoot = rootHandle self._currentRoot = tHandle
return return
@pyqtSlot() @pyqtSlot()
+17
View File
@@ -47,14 +47,28 @@ class NovelSelector(QComboBox):
self._project = project self._project = project
self._theme = mainGui.mainTheme self._theme = mainGui.mainTheme
self._blockSignal = False self._blockSignal = False
self._firstHandle = None
self.currentIndexChanged.connect(self._indexChanged) self.currentIndexChanged.connect(self._indexChanged)
return return
##
# Properties
##
@property @property
def handle(self): def handle(self):
return self.currentData() return self.currentData()
@property
def firstHandle(self):
return self._firstHandle
##
# Methods
##
def setHandle(self, tHandle, blockSignal=True): def setHandle(self, tHandle, blockSignal=True):
"""Set the currently selected handle. """Set the currently selected handle.
""" """
@@ -72,6 +86,7 @@ class NovelSelector(QComboBox):
"""Rebuild the list of novel items. """Rebuild the list of novel items.
""" """
self._blockSignal = True self._blockSignal = True
self._firstHandle = None
self.clear() self.clear()
icon = self._theme.getIcon(nwLabels.CLASS_ICON[nwItemClass.NOVEL]) icon = self._theme.getIcon(nwLabels.CLASS_ICON[nwItemClass.NOVEL])
@@ -83,6 +98,8 @@ class NovelSelector(QComboBox):
else: else:
name = nwItem.itemName name = nwItem.itemName
self.addItem(icon, nwItem.itemName, tHandle) self.addItem(icon, nwItem.itemName, tHandle)
if self._firstHandle is None:
self._firstHandle = tHandle
if includeAll: if includeAll:
self.insertSeparator(self.count()) self.insertSeparator(self.count())
+2
View File
@@ -326,6 +326,8 @@ class GuiNovelToolBar(QWidget):
@pyqtSlot() @pyqtSlot()
def _openNovelSelector(self): def _openNovelSelector(self):
"""Trigger the dropdown list of the novel selector.
"""
self.novelValue.showPopup() self.novelValue.showPopup()
return return