Added merge documents dialog and related code
This commit is contained in:
@@ -29,6 +29,7 @@ class nwFiles():
|
|||||||
EXPORT_OPT = "exportOptions.json"
|
EXPORT_OPT = "exportOptions.json"
|
||||||
TLINE_OPT = "timelineOptions.json"
|
TLINE_OPT = "timelineOptions.json"
|
||||||
SLOG_OPT = "sessionLogOptions.json"
|
SLOG_OPT = "sessionLogOptions.json"
|
||||||
|
MERGE_OPT = "docMergeOptions.json"
|
||||||
|
|
||||||
# END Class nwFiles
|
# END Class nwFiles
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from nw.gui.theme import GuiTheme
|
|||||||
|
|
||||||
# Dialogs
|
# Dialogs
|
||||||
from nw.gui.dialogs.configeditor import GuiConfigEditor
|
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.export import GuiExport
|
||||||
from nw.gui.dialogs.itemeditor import GuiItemEditor
|
from nw.gui.dialogs.itemeditor import GuiItemEditor
|
||||||
from nw.gui.dialogs.projecteditor import GuiProjectEditor
|
from nw.gui.dialogs.projecteditor import GuiProjectEditor
|
||||||
@@ -33,6 +34,7 @@ __all__ = [
|
|||||||
"GuiMainStatus",
|
"GuiMainStatus",
|
||||||
"GuiTheme",
|
"GuiTheme",
|
||||||
"GuiConfigEditor",
|
"GuiConfigEditor",
|
||||||
|
"GuiDocMerge",
|
||||||
"GuiExport",
|
"GuiExport",
|
||||||
"GuiItemEditor",
|
"GuiItemEditor",
|
||||||
"GuiProjectEditor",
|
"GuiProjectEditor",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from nw.gui.dialogs.configeditor import GuiConfigEditor
|
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.export import GuiExport
|
||||||
from nw.gui.dialogs.itemeditor import GuiItemEditor
|
from nw.gui.dialogs.itemeditor import GuiItemEditor
|
||||||
from nw.gui.dialogs.projecteditor import GuiProjectEditor
|
from nw.gui.dialogs.projecteditor import GuiProjectEditor
|
||||||
@@ -9,6 +10,7 @@ from nw.gui.dialogs.timelineview import GuiTimeLineView
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"GuiConfigEditor",
|
"GuiConfigEditor",
|
||||||
|
"GuiDocMerge",
|
||||||
"GuiExport",
|
"GuiExport",
|
||||||
"GuiItemEditor",
|
"GuiItemEditor",
|
||||||
"GuiProjectEditor",
|
"GuiProjectEditor",
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -46,7 +46,9 @@ class GuiIcons:
|
|||||||
|
|
||||||
DECO_MAP = {
|
DECO_MAP = {
|
||||||
"export" : "export.svg",
|
"export" : "export.svg",
|
||||||
|
"merge" : "merge.svg",
|
||||||
"settings" : "gear.svg",
|
"settings" : "gear.svg",
|
||||||
|
"split" : "split.svg",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, theParent):
|
def __init__(self, theParent):
|
||||||
|
|||||||
@@ -369,6 +369,13 @@ class GuiMainMenu(QMenuBar):
|
|||||||
self.aImportFile.triggered.connect(self.theParent.importDocument)
|
self.aImportFile.triggered.connect(self.theParent.importDocument)
|
||||||
self.docuMenu.addAction(self.aImportFile)
|
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
|
return
|
||||||
|
|
||||||
def _buildViewMenu(self):
|
def _buildViewMenu(self):
|
||||||
|
|||||||
+12
-1
@@ -27,7 +27,7 @@ from nw.gui import (
|
|||||||
GuiMainMenu, GuiMainStatus, GuiTheme, GuiDocTree, GuiDocEditor,
|
GuiMainMenu, GuiMainStatus, GuiTheme, GuiDocTree, GuiDocEditor,
|
||||||
GuiDocViewer, GuiDocDetails, GuiSearchBar, GuiNoticeBar,
|
GuiDocViewer, GuiDocDetails, GuiSearchBar, GuiNoticeBar,
|
||||||
GuiDocViewDetails, GuiConfigEditor, GuiProjectEditor, GuiExport,
|
GuiDocViewDetails, GuiConfigEditor, GuiProjectEditor, GuiExport,
|
||||||
GuiItemEditor, GuiTimeLineView, GuiSessionLogView
|
GuiItemEditor, GuiTimeLineView, GuiSessionLogView, GuiDocMerge
|
||||||
)
|
)
|
||||||
from nw.project import NWProject, NWDoc, NWItem, NWIndex, NWBackup
|
from nw.project import NWProject, NWDoc, NWItem, NWIndex, NWBackup
|
||||||
from nw.tools import countWords
|
from nw.tools import countWords
|
||||||
@@ -458,6 +458,17 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
return True
|
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):
|
def passDocumentAction(self, theAction):
|
||||||
"""Pass on document action theAction to whatever document has
|
"""Pass on document action theAction to whatever document has
|
||||||
the focus. If no document has focus, the action is discarded.
|
the focus. If no document has focus, the action is discarded.
|
||||||
|
|||||||
Reference in New Issue
Block a user