X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.editor%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Feditor%2FSaveLoadManager.java;h=3d22b9cf2451de6d23f31594967d85d459d76ea2;hb=a25f554756e1bc9a1f842293aefe60a220d8b950;hp=f4a2eca47480c07806dc30d82a2d6bd7b86964b4;hpb=089e41f47d9347c7772dde8fd12774142970b328;p=Mograsim.git diff --git a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/SaveLoadManager.java b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/SaveLoadManager.java index f4a2eca4..3d22b9cf 100644 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/SaveLoadManager.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/SaveLoadManager.java @@ -2,11 +2,14 @@ package net.mograsim.logic.model.editor; import java.io.IOException; -import net.mograsim.logic.model.editor.ui.DialogManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; + import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.serializing.DeserializedSubmodelComponent; -import net.mograsim.logic.model.serializing.SubmodelComponentDeserializer; -import net.mograsim.logic.model.util.JsonHandler; +import net.mograsim.logic.model.serializing.IdentifierGetter; +import net.mograsim.logic.model.serializing.SubmodelComponentSerializer; public class SaveLoadManager { @@ -28,10 +31,15 @@ public class SaveLoadManager public void openSaveAsDialog() { - String result[] = DialogManager.openMultiTextDialog("Save as...", "Save", "Cancel", "Path"); - if(result != null) + Shell fdShell = new Shell(); + FileDialog fd = new FileDialog(fdShell, SWT.SAVE); + fd.setText("Save as..."); + fd.setFilterExtensions(new String[] { "*.json" }); + String result = fd.open(); + fdShell.dispose(); + if (result != null) { - savePath = result[0]; + savePath = result; innerSave(); } } @@ -40,13 +48,16 @@ public class SaveLoadManager { try { - JsonHandler.writeJson(editor.toBeEdited.calculateParams(c -> + IdentifierGetter idGetter = new IdentifierGetter(); + idGetter.componentIDs = c -> { if (Editor.identifierPerComponent.containsKey(c)) return Editor.identifierPerComponent.get(c); return "class:" + c.getClass().getCanonicalName(); - }), savePath); - } catch (IOException e) + }; + SubmodelComponentSerializer.serialize(editor.toBeEdited, idGetter, savePath); + } + catch (IOException e) { savePath = null; System.err.println("Failed to save component!"); @@ -54,13 +65,17 @@ public class SaveLoadManager } } - public static void openLoadDialog() + public static void openLoadDialog() throws IOException { - String[] result = DialogManager.openMultiTextDialog("Load Component...", "Load", "Cancel", "Path"); - if(result != null) + Shell fdShell = new Shell(); + FileDialog fd = new FileDialog(fdShell, SWT.OPEN); + fd.setText("Load component..."); + fd.setFilterExtensions(new String[] { "*.json" }); + String result = fd.open(); + fdShell.dispose(); + if (result != null) { - new Editor((DeserializedSubmodelComponent) SubmodelComponentDeserializer - .create(new ViewModelModifiable(), result[0])); + new Editor((DeserializedSubmodelComponent) SubmodelComponentSerializer.deserialize(new ViewModelModifiable(), result)); } } }