From 5ee0b640bdf1c01c5bbe862fe8449500d430938c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 18 Aug 2020 21:47:50 +0200 Subject: [PATCH] Make sure the doc split doesn't go past the maximum folder depth --- nw/gui/docsplit.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nw/gui/docsplit.py b/nw/gui/docsplit.py index 218b4855..edd92b6e 100644 --- a/nw/gui/docsplit.py +++ b/nw/gui/docsplit.py @@ -34,7 +34,7 @@ from PyQt5.QtWidgets import ( QListWidgetItem, QDialogButtonBox, QLabel ) -from nw.constants import nwAlert, nwItemType, nwItemClass, nwItemLayout +from nw.constants import nwAlert, nwItemType, nwItemClass, nwItemLayout, nwConst from nw.gui.custom import QHelpLabel from nw.core import NWDoc @@ -149,12 +149,24 @@ class GuiDocSplit(QDialog): ), nwAlert.ERROR) return + # Check that another folder can be created + parTree = self.theProject.projTree.getItemPath(srcItem.parHandle) + if len(parTree) >= nwConst.maxDepth - 1: + self.theParent.makeAlert(( + "Cannot add new folder for the document split. " + "Maximum folder depth has been reached. " + "Please move the file to another level in the project tree." + ), nwAlert.ERROR) + return + + # Create the folder fHandle = self.theProject.newFolder( srcItem.itemName, srcItem.itemClass, srcItem.parHandle ) self.theParent.treeView.revealTreeItem(fHandle) logger.verbose("Creating folder %s" % fHandle) + # Loop through, and create the files for wTitle, iStart, iEnd in finalOrder: itemLayout = nwItemLayout.NOTE