From 6cac679458ecdab38873cd379589bdf5f1b77457 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Thu, 23 Jan 2020 15:52:27 +0100 Subject: [PATCH] Added merge documents dialog and related code --- nw/constants/constants.py | 1 + nw/gui/__init__.py | 2 + nw/gui/dialogs/__init__.py | 2 + nw/gui/dialogs/docmerge.py | 108 +++++++++++++++++++++++++++++++++++++ nw/gui/icons.py | 2 + nw/gui/mainmenu.py | 7 +++ nw/guimain.py | 13 ++++- 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 nw/gui/dialogs/docmerge.py diff --git a/nw/constants/constants.py b/nw/constants/constants.py index a0325482..d3ccd1c7 100644 --- a/nw/constants/constants.py +++ b/nw/constants/constants.py @@ -29,6 +29,7 @@ class nwFiles(): EXPORT_OPT = "exportOptions.json" TLINE_OPT = "timelineOptions.json" SLOG_OPT = "sessionLogOptions.json" + MERGE_OPT = "docMergeOptions.json" # END Class nwFiles diff --git a/nw/gui/__init__.py b/nw/gui/__init__.py index b8196cc2..fad7b148 100644 --- a/nw/gui/__init__.py +++ b/nw/gui/__init__.py @@ -8,6 +8,7 @@ from nw.gui.theme import GuiTheme # Dialogs from nw.gui.dialogs.configeditor import GuiConfigEditor +from nw.gui.dialogs.docmerge import GuiDocMerge from nw.gui.dialogs.export import GuiExport from nw.gui.dialogs.itemeditor import GuiItemEditor from nw.gui.dialogs.projecteditor import GuiProjectEditor @@ -33,6 +34,7 @@ __all__ = [ "GuiMainStatus", "GuiTheme", "GuiConfigEditor", + "GuiDocMerge", "GuiExport", "GuiItemEditor", "GuiProjectEditor", diff --git a/nw/gui/dialogs/__init__.py b/nw/gui/dialogs/__init__.py index fac299ba..0c6b842e 100644 --- a/nw/gui/dialogs/__init__.py +++ b/nw/gui/dialogs/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from nw.gui.dialogs.configeditor import GuiConfigEditor +from nw.gui.dialogs.docmerge import GuiDocMerge from nw.gui.dialogs.export import GuiExport from nw.gui.dialogs.itemeditor import GuiItemEditor from nw.gui.dialogs.projecteditor import GuiProjectEditor @@ -9,6 +10,7 @@ from nw.gui.dialogs.timelineview import GuiTimeLineView __all__ = [ "GuiConfigEditor", + "GuiDocMerge", "GuiExport", "GuiItemEditor", "GuiProjectEditor", diff --git a/nw/gui/dialogs/docmerge.py b/nw/gui/dialogs/docmerge.py new file mode 100644 index 00000000..264fc703 --- /dev/null +++ b/nw/gui/dialogs/docmerge.py @@ -0,0 +1,108 @@ +# -*- coding: utf-8 -*- +"""novelWriter GUI Doc Merge + + novelWriter – GUI Doc Merge +============================= + Tool for merging multiple documents to one + + File History: + Created: 2020-01-23 [0.4.3] + +""" + +import logging +import nw + +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import ( + QDialog, QHBoxLayout, QVBoxLayout, QGridLayout, QPushButton, QLabel, + QProgressBar +) + +from nw.tools import OptLastState +from nw.constants import nwFiles + +logger = logging.getLogger(__name__) + +class GuiDocMerge(QDialog): + + def __init__(self, theParent, theProject): + QDialog.__init__(self, theParent) + + logger.debug("Initialising GuiDocMerge ...") + + self.mainConf = nw.CONFIG + self.theParent = theParent + self.theProject = theProject + self.optState = DocMergeLastState(self.theProject,nwFiles.MERGE_OPT) + self.optState.loadSettings() + + self.outerBox = QHBoxLayout() + self.innerBox = QVBoxLayout() + self.setWindowTitle("Merge Documents") + self.setLayout(self.outerBox) + + self.guiDeco = self.theParent.theTheme.loadDecoration("merge",(64,64)) + + self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop) + self.outerBox.addLayout(self.innerBox) + + self.doMergeForm = QGridLayout() + self.doMergeForm.setContentsMargins(10,5,0,10) + + self.mergeButton = QPushButton("Merge") + self.mergeButton.clicked.connect(self._doMerge) + + self.closeButton = QPushButton("Close") + self.closeButton.clicked.connect(self._doClose) + + self.mergeStatus = QLabel("Ready ...") + self.mergeProgress = QProgressBar(self) + + self.doMergeForm.addWidget(self.mergeStatus, 0, 0, 1, 3) + self.doMergeForm.addWidget(self.mergeProgress, 1, 0) + self.doMergeForm.addWidget(self.mergeButton, 1, 1) + self.doMergeForm.addWidget(self.closeButton, 1, 2) + + self.innerBox.addLayout(self.doMergeForm) + + self.rejected.connect(self._doClose) + self.show() + + logger.debug("GuiDocMerge initialisation complete") + + return + + ## + # Buttons + ## + + def _doMerge(self): + + logger.verbose("GuiDocMerge merge button clicked") + + return + + def _doClose(self): + + logger.verbose("GuiDocMerge close button clicked") + + self.optState.saveSettings() + self.close() + + return + +# END Class GuiDocMerge + +class DocMergeLastState(OptLastState): + + def __init__(self, theProject, theFile): + OptLastState.__init__(self, theProject, theFile) + self.theState = { + } + self.stringOpt = () + self.boolOpt = () + self.intOpt = () + return + +# END Class DocMergeLastState diff --git a/nw/gui/icons.py b/nw/gui/icons.py index 88149b6e..facb84d7 100644 --- a/nw/gui/icons.py +++ b/nw/gui/icons.py @@ -46,7 +46,9 @@ class GuiIcons: DECO_MAP = { "export" : "export.svg", + "merge" : "merge.svg", "settings" : "gear.svg", + "split" : "split.svg", } def __init__(self, theParent): diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index ae5df846..061b5e2d 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -369,6 +369,13 @@ class GuiMainMenu(QMenuBar): self.aImportFile.triggered.connect(self.theParent.importDocument) self.docuMenu.addAction(self.aImportFile) + # Document > Merge Documents + self.aMergeDocs = QAction("Merge Documents", self) + self.aMergeDocs.setStatusTip("Merge multiple documents") + # self.aMergeDocs.setShortcut("Ctrl+Shift+I") + self.aMergeDocs.triggered.connect(self.theParent.mergeDocuments) + self.docuMenu.addAction(self.aMergeDocs) + return def _buildViewMenu(self): diff --git a/nw/guimain.py b/nw/guimain.py index 63a31795..4572ee01 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -27,7 +27,7 @@ from nw.gui import ( GuiMainMenu, GuiMainStatus, GuiTheme, GuiDocTree, GuiDocEditor, GuiDocViewer, GuiDocDetails, GuiSearchBar, GuiNoticeBar, GuiDocViewDetails, GuiConfigEditor, GuiProjectEditor, GuiExport, - GuiItemEditor, GuiTimeLineView, GuiSessionLogView + GuiItemEditor, GuiTimeLineView, GuiSessionLogView, GuiDocMerge ) from nw.project import NWProject, NWDoc, NWItem, NWIndex, NWBackup from nw.tools import countWords @@ -458,6 +458,17 @@ class GuiMain(QMainWindow): return True + def mergeDocuments(self): + """Merge multiple documents to one single new document. + """ + + if self.mainConf.showGUI: + dlgMerge = GuiDocMerge(self, self.theProject) + if dlgMerge.exec_(): + pass + + return True + def passDocumentAction(self, theAction): """Pass on document action theAction to whatever document has the focus. If no document has focus, the action is discarded.