Merge branch 'master' into project_outline
This commit is contained in:
+3
-3
@@ -400,7 +400,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def saveProject(self):
|
def saveProject(self, autoSave=False):
|
||||||
"""Save the current project.
|
"""Save the current project.
|
||||||
"""
|
"""
|
||||||
if not self.hasProject:
|
if not self.hasProject:
|
||||||
@@ -414,7 +414,7 @@ class GuiMain(QMainWindow):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
self.treeView.saveTreeOrder()
|
self.treeView.saveTreeOrder()
|
||||||
self.theProject.saveProject()
|
self.theProject.saveProject(autoSave)
|
||||||
self.theIndex.saveIndex()
|
self.theIndex.saveIndex()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -916,7 +916,7 @@ class GuiMain(QMainWindow):
|
|||||||
if (self.hasProject and self.theProject.projChanged and
|
if (self.hasProject and self.theProject.projChanged and
|
||||||
self.theProject.projPath is not None):
|
self.theProject.projPath is not None):
|
||||||
logger.debug("Autosaving project")
|
logger.debug("Autosaving project")
|
||||||
self.saveProject()
|
self.saveProject(autoSave=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _autoSaveDocument(self):
|
def _autoSaveDocument(self):
|
||||||
|
|||||||
+28
-3
@@ -41,6 +41,8 @@ class NWProject():
|
|||||||
self.projChanged = None # The project has unsaved changes
|
self.projChanged = None # The project has unsaved changes
|
||||||
self.projAltered = None # The project has been altered this session
|
self.projAltered = None # The project has been altered this session
|
||||||
self.lockedBy = None # Data on which computer has the project open
|
self.lockedBy = None # Data on which computer has the project open
|
||||||
|
self.saveCount = None # Meta data: number of saves
|
||||||
|
self.autoCount = None # Meta data: number of automatic saves
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
self.handleSeed = None
|
self.handleSeed = None
|
||||||
@@ -143,10 +145,15 @@ class NWProject():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def clearProject(self):
|
def clearProject(self):
|
||||||
|
"""Clear the data for the current project, and set them to
|
||||||
|
default values.
|
||||||
|
"""
|
||||||
|
|
||||||
self.projOpened = None
|
self.projOpened = None
|
||||||
self.projChanged = None
|
self.projChanged = None
|
||||||
self.projAltered = False
|
self.projAltered = False
|
||||||
|
self.saveCount = 0
|
||||||
|
self.autoCount = 0
|
||||||
|
|
||||||
# Project Settings
|
# Project Settings
|
||||||
self.projTree = {}
|
self.projTree = {}
|
||||||
@@ -244,8 +251,19 @@ class NWProject():
|
|||||||
xRoot = nwXML.getroot()
|
xRoot = nwXML.getroot()
|
||||||
nwxRoot = xRoot.tag
|
nwxRoot = xRoot.tag
|
||||||
|
|
||||||
appVersion = xRoot.attrib["appVersion"]
|
appVersion = "Unknown"
|
||||||
fileVersion = xRoot.attrib["fileVersion"]
|
fileVersion = "Unknown"
|
||||||
|
self.saveCount = 0
|
||||||
|
self.autoCount = 0
|
||||||
|
|
||||||
|
if "appVersion" in xRoot.attrib:
|
||||||
|
appVersion = xRoot.attrib["appVersion"]
|
||||||
|
if "fileVersion" in xRoot.attrib:
|
||||||
|
fileVersion = xRoot.attrib["fileVersion"]
|
||||||
|
if "saveCount" in xRoot.attrib:
|
||||||
|
self.saveCount = checkInt(xRoot.attrib["saveCount"], 0, False)
|
||||||
|
if "autoCount" in xRoot.attrib:
|
||||||
|
self.autoCount = checkInt(xRoot.attrib["autoCount"], 0, False)
|
||||||
|
|
||||||
logger.verbose("XML root is %s" % nwxRoot)
|
logger.verbose("XML root is %s" % nwxRoot)
|
||||||
logger.verbose("File version is %s" % fileVersion)
|
logger.verbose("File version is %s" % fileVersion)
|
||||||
@@ -328,7 +346,7 @@ class NWProject():
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def saveProject(self):
|
def saveProject(self, autoSave=False):
|
||||||
"""Save the project main XML file. The saving command itself
|
"""Save the project main XML file. The saving command itself
|
||||||
uses a temporary filename, and the file is renamed afterwards to
|
uses a temporary filename, and the file is renamed afterwards to
|
||||||
make sure if the save fails, we're not left with a truncated
|
make sure if the save fails, we're not left with a truncated
|
||||||
@@ -347,11 +365,18 @@ class NWProject():
|
|||||||
|
|
||||||
logger.debug("Saving project: %s" % self.projPath)
|
logger.debug("Saving project: %s" % self.projPath)
|
||||||
|
|
||||||
|
if autoSave:
|
||||||
|
self.autoCount += 1
|
||||||
|
else:
|
||||||
|
self.saveCount += 1
|
||||||
|
|
||||||
# Root element and project details
|
# Root element and project details
|
||||||
logger.debug("Writing project meta")
|
logger.debug("Writing project meta")
|
||||||
nwXML = etree.Element("novelWriterXML",attrib={
|
nwXML = etree.Element("novelWriterXML",attrib={
|
||||||
"appVersion" : str(nw.__version__),
|
"appVersion" : str(nw.__version__),
|
||||||
"fileVersion" : "1.0",
|
"fileVersion" : "1.0",
|
||||||
|
"saveCount" : str(self.saveCount),
|
||||||
|
"autoCount" : str(self.autoCount),
|
||||||
"timeStamp" : datetime.fromtimestamp(saveTime).strftime("%Y-%m-%d %H:%M:%S"),
|
"timeStamp" : datetime.fromtimestamp(saveTime).strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user