Fix bug in options file conversion
This commit is contained in:
@@ -255,14 +255,13 @@ class NWProject(QObject):
|
|||||||
build the tree of project items.
|
build the tree of project items.
|
||||||
"""
|
"""
|
||||||
self.clearProject()
|
self.clearProject()
|
||||||
|
logger.info("Opening project: %s", projPath)
|
||||||
if not self._storage.openProjectInPlace(projPath):
|
if not self._storage.openProjectInPlace(projPath):
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"Could not open project with path: {0}"
|
"Could not open project with path: {0}"
|
||||||
).format(projPath), nwAlert.ERROR)
|
).format(projPath), nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.info("Opening project: %s", projPath)
|
|
||||||
|
|
||||||
# Project Lock
|
# Project Lock
|
||||||
# ============
|
# ============
|
||||||
|
|
||||||
|
|||||||
+13
-10
@@ -507,21 +507,24 @@ class _LegacyStorage:
|
|||||||
logger.info("Converting: %s", optsOld)
|
logger.info("Converting: %s", optsOld)
|
||||||
with open(optsOld, mode="r", encoding="utf-8") as fObj:
|
with open(optsOld, mode="r", encoding="utf-8") as fObj:
|
||||||
data = json.load(fObj)
|
data = json.load(fObj)
|
||||||
|
if "GuiOutline" in data:
|
||||||
# Convert Outline Values
|
# Convert Outline Values
|
||||||
state = {}
|
state = {}
|
||||||
outline = data.get("GuiOutline", {})
|
outline = data.get("GuiOutline", {})
|
||||||
hidden = outline.get("columnHidden", {})
|
hidden = outline.get("columnHidden", {})
|
||||||
width = outline.get("columnWidth", {})
|
width = outline.get("columnWidth", {})
|
||||||
for key in outline.get("headerOrder", []):
|
for key in outline.get("headerOrder", []):
|
||||||
state[key] = [hidden.get(key, False), width.get(key, 100)]
|
state[key] = [hidden.get(key, False), width.get(key, 100)]
|
||||||
data["columnState"] = state
|
data["GuiOutline"]["columnState"] = state
|
||||||
|
|
||||||
with open(optsNew, mode="w", encoding="utf-8") as fObj:
|
with open(optsNew, mode="w", encoding="utf-8") as fObj:
|
||||||
json.dump({"novelWriter.guiOptions": data}, fObj, indent=2)
|
json.dump({"novelWriter.guiOptions": data}, fObj, indent=2)
|
||||||
|
|
||||||
# If we're here, we remove the old file
|
# If we're here, we remove the old file, and then we reload
|
||||||
|
# the converted file and save it again
|
||||||
optsOld.unlink()
|
optsOld.unlink()
|
||||||
|
self._project.options.loadSettings()
|
||||||
|
self._project.options.saveSettings()
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Failed to convert old options file")
|
logger.error("Failed to convert old options file")
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ def testCoreStorage_OldFormatConvert(monkeypatch, mockGUI, fncPath):
|
|||||||
assert data["novelWriter.guiOptions"]["GuiProjectSettings"] == {
|
assert data["novelWriter.guiOptions"]["GuiProjectSettings"] == {
|
||||||
"winWidth": 570, "winHeight": 375
|
"winWidth": 570, "winHeight": 375
|
||||||
}
|
}
|
||||||
assert data["novelWriter.guiOptions"]["columnState"] == {
|
assert data["novelWriter.guiOptions"]["GuiOutline"]["columnState"] == {
|
||||||
"TITLE": [False, 325],
|
"TITLE": [False, 325],
|
||||||
"LEVEL": [True, 40],
|
"LEVEL": [True, 40],
|
||||||
"LABEL": [False, 267],
|
"LABEL": [False, 267],
|
||||||
|
|||||||
Reference in New Issue
Block a user