Browse Source

Restructured web view client so that it can be controlled from the host typescript after getting an OnWebviewEnd message. This is the first step to removing some of the native events and being able to handle them from the TS side of things.

Shaddock Heath 9 years ago
parent
commit
3554ad5a7e

+ 39 - 1
Data/AtomicEditor/CodeEditor/Editor.html

@@ -39,7 +39,45 @@
       }
       }
     });
     });
 
 
-    System.import('./source/editorCore/interop');
+    // Functions exposed to the host editor.  These
+    // are hooked in here so that they are available immediately from the host
+    // and when called will bring in the interop as a promise and call it once
+    // it has been loaded
+    function HOST_loadCode(url) {
+        System.import('./source/editorCore/interop').then((module) => {
+            module.default.getInstance().loadCode(url);
+        });
+    }
+
+    function HOST_saveCode() {
+        System.import('./source/editorCore/interop').then((module) => {
+            module.default.getInstance().saveCode();
+        });
+    }
+
+    function HOST_projectUnloaded() {
+        System.import('./source/editorCore/interop').then((module) => {
+            module.default.getInstance().projectUnloaded();
+        });
+    }
+
+    function HOST_resourceRenamed(path, newPath) {
+        System.import('./source/editorCore/interop').then((module) => {
+            module.default.getInstance().resourceRenamed(path, newPath);
+        });
+    }
+
+    function HOST_resourceDeleted(path) {
+        System.import('./source/editorCore/interop').then((module) => {
+            module.default.getInstance().resourceDeleted(path);
+        });
+    }
+
+    function HOST_loadPreferences(prefUrl) {
+        System.import('./source/editorCore/interop').then((module) => {
+            module.default.getInstance().loadPreferences(prefUrl);
+        });
+    }
   </script>
   </script>
 
 
 </body>
 </body>

+ 8 - 2
Script/AtomicEditor/ui/frames/ResourceFrame.ts

@@ -100,7 +100,14 @@ class ResourceFrame extends ScriptWidget {
 
 
         if (ext == ".js" || ext == ".txt" || ext == ".json" || ext == ".ts") {
         if (ext == ".js" || ext == ".txt" || ext == ".json" || ext == ".ts") {
 
 
-             editor = new Editor.JSResourceEditor(path, this.tabcontainer);
+            editor = new Editor.JSResourceEditor(path, this.tabcontainer);
+
+            // one time subscriptions waiting for the web view to finish loading
+            this.subscribeToEvent("WebViewLoadEnd", (data) => {
+                this.unsubscribeFromEvent("WebViewLoadEnd");
+                let webClient = <WebView.WebClient> data.client;
+                webClient.executeJavaScript(`HOST_loadCode("atomic://${path}");`);
+            });
 
 
         } else if (ext == ".scene") {
         } else if (ext == ".scene") {
 
 
@@ -319,7 +326,6 @@ class ResourceFrame extends ScriptWidget {
 
 
         this.subscribeToEvent(UIEvents.ResourceEditorChanged, (data) => this.handleResourceEditorChanged(data));
         this.subscribeToEvent(UIEvents.ResourceEditorChanged, (data) => this.handleResourceEditorChanged(data));
 
 
-
         this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
         this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
 
 
     }
     }

+ 0 - 13
Script/AtomicWebViewEditor/interop.ts

@@ -78,17 +78,6 @@ export default class HostInteropType {
     static EDITOR_CHANGE = "editorChange";
     static EDITOR_CHANGE = "editorChange";
     static EDITOR_GET_USER_PREFS = "editorGetUserPrefs";
     static EDITOR_GET_USER_PREFS = "editorGetUserPrefs";
 
 
-    constructor() {
-        // Set up the window object so the host can call into it
-        window.HOST_loadCode = this.loadCode.bind(this);
-        window.HOST_saveCode = this.saveCode.bind(this);
-
-        window.HOST_projectUnloaded = this.projectUnloaded.bind(this);
-        window.HOST_resourceRenamed = this.resourceRenamed.bind(this);
-        window.HOST_resourceDeleted = this.resourceDeleted.bind(this);
-        window.HOST_loadPreferences = this.loadPreferences.bind(this);
-    }
-
     /**
     /**
      * Called from the host to notify the client what file to load
      * Called from the host to notify the client what file to load
      * @param  {string} codeUrl
      * @param  {string} codeUrl
@@ -235,5 +224,3 @@ export default class HostInteropType {
         });
         });
     }
     }
 }
 }
-
-HostInteropType.getInstance().editorLoaded();