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

Split and Merge improvements #436

Merged
merged 3 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions nw/gui/docmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,24 @@ def _doMerge(self):

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()
Expand Down
20 changes: 17 additions & 3 deletions nw/gui/docsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
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
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(self, theParent, theProject):
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")
Expand Down Expand Up @@ -143,7 +143,8 @@ def _doSplit(self):
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)
Expand All @@ -159,6 +160,18 @@ def _doSplit(self):
), 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.<br><br>"
"Continue with the splitting process?"
) % nFiles
)
if msgRes != QMessageBox.Yes:
return

# Create the folder
fHandle = self.theProject.newFolder(
srcItem.itemName, srcItem.itemClass, srcItem.parHandle
Expand Down Expand Up @@ -186,6 +199,7 @@ def _doSplit(self):
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
Expand Down