Added merge documents dialog and related code

This commit is contained in:
Veronica K. B. Olsen
2020-01-23 15:52:27 +01:00
parent a111247a3c
commit 6cac679458
7 changed files with 134 additions and 1 deletions
+1
View File
@@ -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
+2
View File
@@ -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",
+2
View File
@@ -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",
+108
View File
@@ -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
+2
View File
@@ -46,7 +46,9 @@ class GuiIcons:
DECO_MAP = {
"export" : "export.svg",
"merge" : "merge.svg",
"settings" : "gear.svg",
"split" : "split.svg",
}
def __init__(self, theParent):
+7
View File
@@ -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):
+12 -1
View File
@@ -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.