Fix bug in options file conversion

This commit is contained in:
Veronica Berglyd Olsen
2023-06-15 23:54:16 +02:00
parent 6193e3191b
commit a3f0d5b865
3 changed files with 15 additions and 13 deletions
+1 -2
View File
@@ -255,14 +255,13 @@ class NWProject(QObject):
build the tree of project items.
"""
self.clearProject()
logger.info("Opening project: %s", projPath)
if not self._storage.openProjectInPlace(projPath):
self.mainGui.makeAlert(self.tr(
"Could not open project with path: {0}"
).format(projPath), nwAlert.ERROR)
return False
logger.info("Opening project: %s", projPath)
# Project Lock
# ============
+13 -10
View File
@@ -507,21 +507,24 @@ class _LegacyStorage:
logger.info("Converting: %s", optsOld)
with open(optsOld, mode="r", encoding="utf-8") as fObj:
data = json.load(fObj)
# Convert Outline Values
state = {}
outline = data.get("GuiOutline", {})
hidden = outline.get("columnHidden", {})
width = outline.get("columnWidth", {})
for key in outline.get("headerOrder", []):
state[key] = [hidden.get(key, False), width.get(key, 100)]
data["columnState"] = state
if "GuiOutline" in data:
# Convert Outline Values
state = {}
outline = data.get("GuiOutline", {})
hidden = outline.get("columnHidden", {})
width = outline.get("columnWidth", {})
for key in outline.get("headerOrder", []):
state[key] = [hidden.get(key, False), width.get(key, 100)]
data["GuiOutline"]["columnState"] = state
with open(optsNew, mode="w", encoding="utf-8") as fObj:
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()
self._project.options.loadSettings()
self._project.options.saveSettings()
except Exception:
logger.error("Failed to convert old options file")
+1 -1
View File
@@ -466,7 +466,7 @@ def testCoreStorage_OldFormatConvert(monkeypatch, mockGUI, fncPath):
assert data["novelWriter.guiOptions"]["GuiProjectSettings"] == {
"winWidth": 570, "winHeight": 375
}
assert data["novelWriter.guiOptions"]["columnState"] == {
assert data["novelWriter.guiOptions"]["GuiOutline"]["columnState"] == {
"TITLE": [False, 325],
"LEVEL": [True, 40],
"LABEL": [False, 267],