From 1263f4d12e9016408ff04efc6cfa06903110bb4a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 31 Oct 2019 11:03:35 +0100 Subject: [PATCH 1/2] Fix issue 99 --- nw/gui/export.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nw/gui/export.py b/nw/gui/export.py index 1032bb08..d9f3b7e9 100644 --- a/nw/gui/export.py +++ b/nw/gui/export.py @@ -213,7 +213,7 @@ class GuiExport(QDialog): # If we've reached this point, we're also running Pandoc - if self._callPandoc(tFormat, pFormat): + if self._callPandoc(saveTo, tFormat, pFormat): self.exportProgress.setValue(nItems) self.exportStatus.setText("Pandoc conversion complete") logger.verbose("Pandoc conversion complete") @@ -225,7 +225,7 @@ class GuiExport(QDialog): return True - def _callPandoc(self, inFmt, outFmt): + def _callPandoc(self, inFile, inFmt, outFmt): pFmt = { GuiExportPandoc.FMT_ODT : "odt", @@ -246,7 +246,6 @@ class GuiExport(QDialog): ), nwAlert.ERROR) return False - inFile = self.tabMain.exportPath.text() outFile = path.splitext(inFile)[0]+GuiExportPandoc.FMT_EXT[outFmt] fileName = path.basename(outFile) From 2dd546b3950334dfbd62dd50f526c323df820a65 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 31 Oct 2019 11:34:36 +0100 Subject: [PATCH 2/2] Improved the export filter to exclude trash and orphan files always --- nw/convert/file/concat.py | 11 +---- nw/convert/file/text.py | 42 +++++++++++++------ .../sampleNovel/data_b/8136a5a774a0_main.nwd | 3 ++ sample/sampleNovel/nwProject.nwx | 20 +++++++-- 4 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 sample/sampleNovel/data_b/8136a5a774a0_main.nwd diff --git a/nw/convert/file/concat.py b/nw/convert/file/concat.py index 5d22b0fa..392e86f9 100644 --- a/nw/convert/file/concat.py +++ b/nw/convert/file/concat.py @@ -35,16 +35,7 @@ class ConcatFile(TextFile): logger.verbose("Parsing content of item '%s'" % tHandle) - theItem = self.theProject.getItem(tHandle) - isNone = theItem.itemLayout == nwItemLayout.NO_LAYOUT - isNote = theItem.itemLayout == nwItemLayout.NOTE - isNovel = not isNone and not isNote - - if isNone: - return False - if isNote and not self.expNotes: - return False - if isNovel and not self.expNovel: + if not self.checkInclude(tHandle): return False self.theConv.setText(tHandle) diff --git a/nw/convert/file/text.py b/nw/convert/file/text.py index 9301a823..4d3cd346 100644 --- a/nw/convert/file/text.py +++ b/nw/convert/file/text.py @@ -17,7 +17,7 @@ from os import path from PyQt5.QtWidgets import QMessageBox from nw.convert.text.totext import ToText -from nw.enum import nwAlert, nwItemLayout +from nw.enum import nwAlert, nwItemType, nwItemLayout, nwItemClass logger = logging.getLogger(__name__) @@ -120,17 +120,8 @@ class TextFile(): def addText(self, tHandle): logger.verbose("Parsing content of item '%s'" % tHandle) - - theItem = self.theProject.getItem(tHandle) - isNone = theItem.itemLayout == nwItemLayout.NO_LAYOUT - isNote = theItem.itemLayout == nwItemLayout.NOTE - isNovel = not isNone and not isNote - - if isNone: - return False - if isNote and not self.expNotes: - return False - if isNovel and not self.expNovel: + + if not self.checkInclude(tHandle): return False self.theConv.setText(tHandle) @@ -145,6 +136,33 @@ class TextFile(): return True + def checkInclude(self, tHandle): + """This function checks whether a file should be included in the export or not. For standard + note and novel files, this is controlled by the options selected by the user. For other + files classified as non-exportable, a few checks must be made, and the following are not: + * Items that are not actual files. + * Items that have been orphaned which are tagged as NO_LAYOUT and NO_CLASS. + * Items that appear in the TRASH folder + """ + + theItem = self.theProject.getItem(tHandle) + isNone = theItem.itemType != nwItemType.FILE + isNone |= theItem.itemLayout == nwItemLayout.NO_LAYOUT + isNone |= theItem.itemClass == nwItemClass.NO_CLASS + isNone |= theItem.itemClass == nwItemClass.TRASH + isNone |= theItem.parHandle == self.theProject.trashRoot + isNote = theItem.itemLayout == nwItemLayout.NOTE + isNovel = not isNone and not isNote + + if isNone: + return False + if isNote and not self.expNotes: + return False + if isNovel and not self.expNovel: + return False + + return True + ## # Internal Functions ## diff --git a/sample/sampleNovel/data_b/8136a5a774a0_main.nwd b/sample/sampleNovel/data_b/8136a5a774a0_main.nwd new file mode 100644 index 00000000..e3724c45 --- /dev/null +++ b/sample/sampleNovel/data_b/8136a5a774a0_main.nwd @@ -0,0 +1,3 @@ +### Delete Me! + +This scene is trash. \ No newline at end of file diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index da5d657f..11629296 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -9,9 +9,9 @@ True - 636b6aa9b697b + b8136a5a774a0 ba8a28a246524 - 873 + 879 B E @@ -33,7 +33,7 @@ Main - + Novel ROOT @@ -232,5 +232,17 @@ 0 1 + + Delete Me! + FILE + NOVEL + New + False + SCENE + 30 + 6 + 1 + 36 +