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=e690200e93d98443d532373acb2ab790d4ecdf4f;hb=148a58630b38b30d4d24a21e3f55c357f5b4d0bc;hp=848227bc0b1b9af9393391528888e910958fc2d0;hpb=47ea68ed5c444dd14864412639f6a6fd60ab8a0f;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 848227bc..e690200e 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.DialogManager.InteractiveDialog; +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.IndirectGUIComponentCreator; +import net.mograsim.logic.model.serializing.SubmodelComponentSerializer; public class SaveLoadManager { @@ -28,12 +31,15 @@ public class SaveLoadManager public void openSaveAsDialog() { - InteractiveDialog d = new InteractiveDialog("Save as...", "Save", "Cancel", "Path"); - d.open(); - - if(InteractiveDialog.InteractiveDialogState.ACCEPTED.equals(d.getState())) + 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 = d.getText(); + savePath = result; innerSave(); } } @@ -42,13 +48,9 @@ public class SaveLoadManager { try { - JsonHandler.writeJson(editor.toBeEdited.calculateParams(c -> - { - if (Editor.identifierPerComponent.containsKey(c)) - return Editor.identifierPerComponent.get(c); - return "class:" + c.getClass().getCanonicalName(); - }), savePath); - } catch (IOException e) + SubmodelComponentSerializer.serialize(editor.toBeEdited, savePath); + } + catch (IOException e) { savePath = null; System.err.println("Failed to save component!"); @@ -56,14 +58,18 @@ public class SaveLoadManager } } - public static void openLoadDialog() + public static void openLoadDialog() throws IOException { - InteractiveDialog load = new InteractiveDialog("Load Component...", "Load", "Cancel", "Path"); - load.open(); - if(InteractiveDialog.InteractiveDialogState.ACCEPTED.equals(load.getState())) + 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(), load.getText())); + new Editor((DeserializedSubmodelComponent) IndirectGUIComponentCreator.createComponent(new ViewModelModifiable(), + "file:" + result)); } } }