From 9aa0e259fe64f663d4a861a8adfa3c46353ceab0 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 1 Sep 2020 23:24:29 +0200 Subject: [PATCH 1/3] Added a message box before the document split process is completed --- nw/gui/docsplit.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/nw/gui/docsplit.py b/nw/gui/docsplit.py index edd92b6e..2a292b9f 100644 --- a/nw/gui/docsplit.py +++ b/nw/gui/docsplit.py @@ -31,7 +31,7 @@ import nw from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( QDialog, QVBoxLayout, QComboBox, QListWidget, QAbstractItemView, - QListWidgetItem, QDialogButtonBox, QLabel + QListWidgetItem, QDialogButtonBox, QLabel, QMessageBox ) from nw.constants import nwAlert, nwItemType, nwItemClass, nwItemLayout, nwConst @@ -107,7 +107,7 @@ class GuiDocSplit(QDialog): def _doSplit(self): """Perform the split of the file, create a new folder in the same parent folder, and multiple files depending on split level - settings. The old file is not removed in the merge process, and + settings. The old file is not removed in the split process, and must be deleted manually. """ logger.verbose("GuiDocSplit split button clicked") @@ -143,7 +143,8 @@ class GuiDocSplit(QDialog): if i > 0: finalOrder[i-1][2] = lineNo - if len(finalOrder) == 0: + nFiles = len(finalOrder) + if nFiles == 0: self.theParent.makeAlert(( "No headers found. Nothing to do." ), nwAlert.ERROR) @@ -159,6 +160,18 @@ class GuiDocSplit(QDialog): ), nwAlert.ERROR) return + if self.mainConf.showGUI: + msgBox = QMessageBox() + msgRes = msgBox.question( + self, "Split Document", ( + "The document will be split into %d file(s) in a new folder. " + "The original document will remain intact.

" + "Continue with the splitting process?" + ) % nFiles + ) + if msgRes != QMessageBox.Yes: + return + # Create the folder fHandle = self.theProject.newFolder( srcItem.itemName, srcItem.itemClass, srcItem.parHandle From 123b986a07aa7ad9fe4df9ed3a63ef931b8c1289 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 1 Sep 2020 23:27:48 +0200 Subject: [PATCH 2/3] Split document now preserves item status of the source item --- nw/gui/docsplit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nw/gui/docsplit.py b/nw/gui/docsplit.py index 2a292b9f..376eaf3a 100644 --- a/nw/gui/docsplit.py +++ b/nw/gui/docsplit.py @@ -199,6 +199,7 @@ class GuiDocSplit(QDialog): nHandle = self.theProject.newFile(wTitle, srcItem.itemClass, fHandle) newItem = self.theProject.projTree[nHandle] newItem.setLayout(itemLayout) + newItem.setStatus(srcItem.itemStatus) logger.verbose( "Creating new document %s with text from line %d to %d" % ( nHandle, iStart, iEnd-1 From af0d578555298258942f2e1c9e5c17f36320fea0 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 1 Sep 2020 23:33:13 +0200 Subject: [PATCH 3/3] Also have the merge tool preserve item status of the source item --- nw/gui/docmerge.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nw/gui/docmerge.py b/nw/gui/docmerge.py index 547cbd44..06eb226a 100644 --- a/nw/gui/docmerge.py +++ b/nw/gui/docmerge.py @@ -109,15 +109,24 @@ class GuiDocMerge(QDialog): if self.sourceItem is None: self.theParent.makeAlert(( - "Cannot parse source item." + "No source document selected. Nothing to do." ), nwAlert.ERROR) return srcItem = self.theProject.projTree[self.sourceItem] + if srcItem is None: + self.theParent.makeAlert(( + "Could not parse source document." + ), nwAlert.ERROR) + return + nHandle = self.theProject.newFile(srcItem.itemName, srcItem.itemClass, srcItem.parHandle) - self.theParent.treeView.revealTreeItem(nHandle) + newItem = self.theProject.projTree[nHandle] + newItem.setStatus(srcItem.itemStatus) + theDoc.openDocument(nHandle, False) theDoc.saveDocument(theText) + self.theParent.treeView.revealTreeItem(nHandle) self.theParent.openDocument(nHandle, doScroll=True) self.close()