The build dialog should show the result from last build when opening
This commit is contained in:
@@ -45,6 +45,7 @@ class nwFiles():
|
|||||||
INDEX_FILE = "tagsIndex.json"
|
INDEX_FILE = "tagsIndex.json"
|
||||||
OPTS_FILE = "guiOptions.json"
|
OPTS_FILE = "guiOptions.json"
|
||||||
RECENT_FILE = "recentProjects.json"
|
RECENT_FILE = "recentProjects.json"
|
||||||
|
BUILD_CACHE = "prevBuild.json"
|
||||||
|
|
||||||
# END Class nwFiles
|
# END Class nwFiles
|
||||||
|
|
||||||
|
|||||||
+72
-1
@@ -26,6 +26,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
@@ -45,7 +46,7 @@ from PyQt5.QtWidgets import (
|
|||||||
from nw.gui.additions import QSwitch
|
from nw.gui.additions import QSwitch
|
||||||
from nw.core import ToHtml
|
from nw.core import ToHtml
|
||||||
from nw.constants import (
|
from nw.constants import (
|
||||||
nwAlert, nwItemType, nwItemLayout, nwItemClass
|
nwAlert, nwFiles, nwItemType, nwItemLayout, nwItemClass
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -372,6 +373,15 @@ class GuiBuildNovel(QDialog):
|
|||||||
|
|
||||||
logger.debug("GuiBuildNovel initialisation complete")
|
logger.debug("GuiBuildNovel initialisation complete")
|
||||||
|
|
||||||
|
# Load from Cache
|
||||||
|
if self._loadCache():
|
||||||
|
self.docView.setStyleSheet(self.htmlStyle)
|
||||||
|
self.docView.setContent(self.htmlText)
|
||||||
|
else:
|
||||||
|
self.htmlText = []
|
||||||
|
self.htmlStyle = []
|
||||||
|
self.nwdText = []
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -459,6 +469,8 @@ class GuiBuildNovel(QDialog):
|
|||||||
self.docView.setStyleSheet(self.htmlStyle)
|
self.docView.setStyleSheet(self.htmlStyle)
|
||||||
self.docView.setContent(self.htmlText)
|
self.docView.setContent(self.htmlText)
|
||||||
|
|
||||||
|
self._saveCache()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _checkInclude(self, theItem, noteFiles, novelFiles, ignoreFlag):
|
def _checkInclude(self, theItem, noteFiles, novelFiles, ignoreFlag):
|
||||||
@@ -683,6 +695,60 @@ class GuiBuildNovel(QDialog):
|
|||||||
self.textSize.setValue(theFont.pointSize())
|
self.textSize.setValue(theFont.pointSize())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _loadCache(self):
|
||||||
|
"""Save the current data to cache.
|
||||||
|
"""
|
||||||
|
buildCache = path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||||
|
dataCount = 0
|
||||||
|
if path.isfile(buildCache):
|
||||||
|
|
||||||
|
logger.debug("Loading build cache")
|
||||||
|
try:
|
||||||
|
with open(buildCache, mode="r", encoding="utf8") as inFile:
|
||||||
|
theJson = inFile.read()
|
||||||
|
theData = json.loads(theJson)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Failed to load build cache")
|
||||||
|
logger.error(str(e))
|
||||||
|
return False
|
||||||
|
|
||||||
|
if "htmlText" in theData.keys():
|
||||||
|
self.htmlText = theData["htmlText"]
|
||||||
|
dataCount += 1
|
||||||
|
if "htmlStyle" in theData.keys():
|
||||||
|
self.htmlStyle = theData["htmlStyle"]
|
||||||
|
dataCount += 1
|
||||||
|
if "nwdText" in theData.keys():
|
||||||
|
self.nwdText = theData["nwdText"]
|
||||||
|
dataCount += 1
|
||||||
|
|
||||||
|
return dataCount == 3
|
||||||
|
|
||||||
|
def _saveCache(self):
|
||||||
|
"""Save the current data to cache.
|
||||||
|
"""
|
||||||
|
buildCache = path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||||
|
|
||||||
|
if self.mainConf.debugInfo:
|
||||||
|
nIndent = 2
|
||||||
|
else:
|
||||||
|
nIndent = None
|
||||||
|
|
||||||
|
logger.debug("Saving build cache")
|
||||||
|
try:
|
||||||
|
with open(buildCache, mode="w+", encoding="utf8") as outFile:
|
||||||
|
outFile.write(json.dumps({
|
||||||
|
"htmlText" : self.htmlText,
|
||||||
|
"htmlStyle" : self.htmlStyle,
|
||||||
|
"nwdText" : self.nwdText,
|
||||||
|
}, indent=nIndent))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Failed to save build cache")
|
||||||
|
logger.error(str(e))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def _doClose(self):
|
def _doClose(self):
|
||||||
"""Close button was clicked.
|
"""Close button was clicked.
|
||||||
"""
|
"""
|
||||||
@@ -762,6 +828,11 @@ class GuiBuildNovelDocView(QTextBrowser):
|
|||||||
|
|
||||||
self.qDocument = self.document()
|
self.qDocument = self.document()
|
||||||
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
|
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
|
||||||
|
self.setPlaceholderText(
|
||||||
|
"This area will show the content of the document to be "
|
||||||
|
"exported or printed. Press the \"Build Novel Project\" "
|
||||||
|
"button to generate content."
|
||||||
|
)
|
||||||
|
|
||||||
theFont = QFont()
|
theFont = QFont()
|
||||||
if self.mainConf.textFont is None:
|
if self.mainConf.textFont is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user