Browse Source

Merge pull request #674 from AtomicGameEngine/JME-ATOMIC-CODEEDITORSAVEFIX

Fixing code editor saves
JoshEngebretson 9 years ago
parent
commit
c5712ba7a0

+ 43 - 42
Script/AtomicWebViewEditor/interop.ts

@@ -4,56 +4,57 @@ import * as editorConfig from "./editor/editorConfig";
 
 export function saveCode() {
 
-    const data = {
-        message: "saveCode",
-        payload: editor.session.getValue()
-    };
-
-    window.atomicQuery({
-        request: JSON.stringify(data),
-        persistent: false,
-        onSuccess: function(response) {/**/ },
-        onFailure: function(error_code, error_message) {
-            console.log("Error getting code");
-        }
-    });
+  const data = {
+    message: "saveCode",
+    payload: editor.session.getValue()
+  };
+
+  window.atomicQuery({
+    request: JSON.stringify(data),
+    persistent: false,
+    onSuccess: function(response) {/**/ },
+    onFailure: function(error_code, error_message) {
+      console.log("Error getting code");
+    }
+  });
 }
 
 export function codeLoaded(value: string, fileExt: string) {
-    editor.session.setValue(value);
-    editor.gotoLine(0);
-
-    editor.getSession().on("change", function(e) {
-        window.atomicQuery({
-            request: "change",
-            persistent: false,
-            onSuccess: (response) => {/**/ },
-            onFailure: (error_code, error_message) => {
-                console.log("Error on change");
-            }
-        });
+  editor.session.setValue(value);
+  editor.gotoLine(0);
+
+  editor.getSession().on("change", function(e) {
+    window.atomicQuery({
+      request: "change",
+      persistent: false,
+      onSuccess: (response) => {/**/ },
+      onFailure: (error_code, error_message) => {
+        console.log("Error on change");
+      }
     });
+  });
 }
 
 export function loadCode(codeUrl: string) {
-    const fileExt = codeUrl.split(".").pop();
-
-    // go ahead and set the theme prior to pulling the file across
-    editorConfig.configure(fileExt);
-
-    const p = new Promise(function(resolve, reject) {
-        const xmlHttp = new XMLHttpRequest();
-        xmlHttp.onreadystatechange = () => {
-            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
-                resolve(xmlHttp.responseText);
-            }
-        };
-        xmlHttp.open("GET", codeUrl, true); // true for asynchronous
-        xmlHttp.send(null);
-    }).then(function(src: string) {
-        codeLoaded(src, fileExt);
-    });
+  const fileExt = codeUrl.split(".").pop();
+
+  // go ahead and set the theme prior to pulling the file across
+  editorConfig.configure(fileExt);
+
+  const p = new Promise(function(resolve, reject) {
+    const xmlHttp = new XMLHttpRequest();
+    xmlHttp.onreadystatechange = () => {
+      if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
+        resolve(xmlHttp.responseText);
+      }
+    };
+    xmlHttp.open("GET", codeUrl, true); // true for asynchronous
+    xmlHttp.send(null);
+  }).then(function(src: string) {
+    codeLoaded(src, fileExt);
+  });
 }
 
 // Set up the window object so the host can call into it
 window.loadCode = loadCode;
+window.saveCode = saveCode;

+ 1 - 0
Script/AtomicWebViewEditor/typings/AtomicQuery.d.ts

@@ -1,4 +1,5 @@
 interface Window {
     atomicQuery: any;
     loadCode: (codeUrl) => void;
+    saveCode: () => void;
 }