| import { store } from "@/Store"; |
| import * as api from "@/Api"; |
| import { FileInfo } from "@/FileSystem/FileInfo"; |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import { molmodaStateKeysToRetain } from "../ParseMolModels/_ParseUsingMolModa"; |
| import { setStoreIsDirty } from "@/Core/SaveOnClose/DirtyStore"; |
| import { toRaw } from "vue"; |
| import { customSelsAndStyles } from "@/Core/Styling/StyleManager"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function saveMolModa(filename: string): Promise<undefined> { |
| |
| if (!filename.endsWith(".molmoda")) { |
| filename += ".molmoda"; |
| } |
|
|
| return saveState(filename, store.state).then(() => { |
| setStoreIsDirty(false); |
| return undefined; |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export function stateToJsonStr(state: any): string { |
| const newMolData = (state.molecules as TreeNodeList).serialize(); |
|
|
| const newState: { [key: string]: any } = {}; |
| for (const key in state) { |
| if (molmodaStateKeysToRetain.indexOf(key) === -1) { |
| continue; |
| } |
|
|
| |
| |
| newState[key] = key === "molecules" ? newMolData : state[key]; |
| } |
|
|
| const rawCustomStyles = toRaw(customSelsAndStyles); |
| if (Object.keys(rawCustomStyles).length > 0) { |
| newState["customSelsAndStyles"] = rawCustomStyles; |
| } |
|
|
| |
| const seen = new WeakSet(); |
| return JSON.stringify(newState, (key, value) => { |
| if (typeof value === "object" && value !== null) { |
| if (seen.has(value)) { |
| |
| |
| return; |
| } |
| seen.add(value); |
| } |
| return value; |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function saveState(filename: string, state: any): Promise<any> { |
| const jsonStr = stateToJsonStr(state); |
|
|
| |
| return api.fs.saveTxt( |
| new FileInfo({ |
| name: "molmoda_file.json", |
| contents: jsonStr, |
| compressedName: filename, |
| }) |
| ); |
| } |
|
|