Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply new item rules in project tree #1406

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions novelwriter/gui/projtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
QMenu, QShortcut, QSizePolicy, QToolButton, QTreeWidget, QTreeWidgetItem,
QVBoxLayout, QWidget
)
from novelwriter.core.item import NWItem

from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout, nwAlert, nwWidget
from novelwriter.constants import nwHeaders, nwUnicode, trConst, nwLabels
Expand Down Expand Up @@ -108,6 +109,9 @@ def __init__(self, mainGui):
self.keyContext.setContext(Qt.WidgetShortcut)
self.keyContext.activated.connect(lambda: self.projTree.openContextOnSelected())

# Signals
self.selectedItemChanged.connect(self.projBar._treeSelectionChanged)

# Function Mappings
self.emptyTrash = self.projTree.emptyTrash
self.requestDeleteItem = self.projTree.requestDeleteItem
Expand Down Expand Up @@ -418,6 +422,23 @@ def addClass(itemClass):

return

##
# Slots
##

@pyqtSlot(str)
def _treeSelectionChanged(self, tHandle):
"""Toggle the visibility of the new item enties for novel
documents. They should only be visible if novel documents can
actually be added.
"""
nwItem = self.theProject.tree[tHandle]
allowDoc = isinstance(nwItem, NWItem) and nwItem.documentAllowed()
self.aAddEmpty.setVisible(allowDoc)
self.aAddChap.setVisible(allowDoc)
self.aAddScene.setVisible(allowDoc)
return

# END Class GuiProjectToolBar


Expand Down