Merge pull request #796 from vkbo/split_tool
Fix split tool dropping last line (#795)
This commit is contained in:
+9
-13
@@ -53,6 +53,7 @@ class GuiDocSplit(QDialog):
|
|||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.optState = self.theProject.optState
|
self.optState = self.theProject.optState
|
||||||
self.sourceItem = None
|
self.sourceItem = None
|
||||||
|
self.sourceText = []
|
||||||
|
|
||||||
self.outerBox = QVBoxLayout()
|
self.outerBox = QVBoxLayout()
|
||||||
self.setWindowTitle(self.tr("Split Document"))
|
self.setWindowTitle(self.tr("Split Document"))
|
||||||
@@ -127,11 +128,7 @@ class GuiDocSplit(QDialog):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
theDoc = NWDoc(self.theProject, self.theParent)
|
nLines = len(self.sourceText)
|
||||||
theText = theDoc.openDocument(self.sourceItem, False)
|
|
||||||
theLines = theText.splitlines()
|
|
||||||
nLines = len(theLines)
|
|
||||||
theLines.insert(0, "%Split Doc")
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Splitting document %s with %d lines" % (self.sourceItem, nLines)
|
"Splitting document %s with %d lines" % (self.sourceItem, nLines)
|
||||||
)
|
)
|
||||||
@@ -186,6 +183,7 @@ class GuiDocSplit(QDialog):
|
|||||||
logger.verbose("Creating folder %s" % fHandle)
|
logger.verbose("Creating folder %s" % fHandle)
|
||||||
|
|
||||||
# Loop through, and create the files
|
# Loop through, and create the files
|
||||||
|
theDoc = NWDoc(self.theProject, self.theParent)
|
||||||
for wTitle, iStart, iEnd in finalOrder:
|
for wTitle, iStart, iEnd in finalOrder:
|
||||||
|
|
||||||
itemLayout = nwItemLayout.NOTE
|
itemLayout = nwItemLayout.NOTE
|
||||||
@@ -208,11 +206,11 @@ class GuiDocSplit(QDialog):
|
|||||||
newItem.setStatus(srcItem.itemStatus)
|
newItem.setStatus(srcItem.itemStatus)
|
||||||
logger.verbose(
|
logger.verbose(
|
||||||
"Creating new document %s with text from line %d to %d" % (
|
"Creating new document %s with text from line %d to %d" % (
|
||||||
nHandle, iStart, iEnd-1
|
nHandle, iStart+1, iEnd
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
theText = "\n".join(theLines[iStart:iEnd])
|
theText = "\n".join(self.sourceText[iStart:iEnd])
|
||||||
theText = theText.rstrip("\n") + "\n\n"
|
theText = theText.rstrip("\n") + "\n\n"
|
||||||
theDoc.openDocument(nHandle, False)
|
theDoc.openDocument(nHandle, False)
|
||||||
theDoc.saveDocument(theText)
|
theDoc.saveDocument(theText)
|
||||||
@@ -265,12 +263,10 @@ class GuiDocSplit(QDialog):
|
|||||||
"Scanning document %s for headings level <= %d" % (self.sourceItem, spLevel)
|
"Scanning document %s for headings level <= %d" % (self.sourceItem, spLevel)
|
||||||
)
|
)
|
||||||
|
|
||||||
lineNo = 0
|
self.sourceText = theText.splitlines()
|
||||||
for aLine in theText.splitlines():
|
for lineNo, aLine in enumerate(self.sourceText):
|
||||||
|
|
||||||
lineNo += 1
|
|
||||||
onLine = 0
|
|
||||||
|
|
||||||
|
onLine = -1
|
||||||
if aLine.startswith("# ") and spLevel >= 1:
|
if aLine.startswith("# ") and spLevel >= 1:
|
||||||
onLine = lineNo
|
onLine = lineNo
|
||||||
elif aLine.startswith("## ") and spLevel >= 2:
|
elif aLine.startswith("## ") and spLevel >= 2:
|
||||||
@@ -280,7 +276,7 @@ class GuiDocSplit(QDialog):
|
|||||||
elif aLine.startswith("#### ") and spLevel >= 4:
|
elif aLine.startswith("#### ") and spLevel >= 4:
|
||||||
onLine = lineNo
|
onLine = lineNo
|
||||||
|
|
||||||
if onLine > 0:
|
if onLine >= 0:
|
||||||
newItem = QListWidgetItem()
|
newItem = QListWidgetItem()
|
||||||
newItem.setText(aLine.strip())
|
newItem.setText(aLine.strip())
|
||||||
newItem.setData(Qt.UserRole, onLine)
|
newItem.setData(Qt.UserRole, onLine)
|
||||||
|
|||||||
Reference in New Issue
Block a user