Browse Source

- delay loading of the code into the editor instance until the editor instance notifies the host that it is fully loaded and all bits are required in
- switched over to using the full system.js to require in individual files instead of creating a single bundle of all the typescript. This allows the ability to only require in the bits that are needed

Shaddock Heath 9 years ago
parent
commit
a0aaeda280

+ 14 - 3
Data/AtomicEditor/CodeEditor/Editor.html

@@ -25,10 +25,21 @@
 
   <script src="./source/ace/ace.js" type="text/javascript" charset="utf-8"></script>
   <script src="./source/ace/ext-language_tools.js"></script>
-  <script src="./source/systemjs/system-register-only.js" type="text/javascript" charset="utf-8"></script>
-  <script src="./editor.bundle.js" type="text/javascript" charset="utf-8"></script>
+  <script src="./source/systemjs/system.js" type="text/javascript" charset="utf-8"></script>
   <script>
-    System.import('./interop');
+    System.config({
+        "baseURL": "/",
+        "defaultJSExtensions": true,
+        // TODO: figure out how to make this be loaded in by the extension instead of being hard-coded in the html page
+        meta: {
+        './source/editorCore/modules/typescript.js': {
+          format: 'global',
+          exports: 'ts',
+        }
+      }
+    });
+
+    System.import('./source/editorCore/interop');
   </script>
 
 </body>

File diff suppressed because it is too large
+ 3 - 0
Data/AtomicEditor/CodeEditor/source/systemjs/system.js


+ 23 - 4
Source/AtomicEditor/Editors/JSResourceEditor.cpp

@@ -96,7 +96,8 @@ JSResourceEditor::~JSResourceEditor()
 
 void JSResourceEditor::HandleWebViewLoadEnd(StringHash eventType, VariantMap& eventData)
 {
-    webClient_->ExecuteJavaScript(ToString("loadCode(\"atomic://resources/%s\");", fullpath_.CString()));
+    // need to wait until we get an editor load complete message since we could
+    // still be streaming things in.
 }
 
 void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventData)
@@ -104,19 +105,37 @@ void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventD
     using namespace WebMessage;
 
     const String& request = eventData[P_REQUEST].GetString();
+    const String& EDITOR_CHANGE = "change";
+    const String& EDITOR_SAVE_CODE = "saveCode";
+    const String& EDITOR_LOAD_COMPLETE = "editorLoadComplete";
+    
+    const String& RESOURCES_MARKER = "resources/";
+    
+    // Full path is the fully qualified path from the root of the filesystem.  In order
+    // to take advantage of the resource caching system, let's trim it down to just the
+    // path inside the resources directory
+    String normalizedPath = fullpath_.SubstringUTF8(fullpath_.ToLower().Find(RESOURCES_MARKER) + RESOURCES_MARKER.Length());
+    
     WebMessageHandler* handler = static_cast<WebMessageHandler*>(eventData[P_HANDLER].GetPtr());
 
-    if (request == "change")
+    if (request == EDITOR_CHANGE)
     {
         SetModified(true);
     }
+    else if (request == EDITOR_LOAD_COMPLETE)
+    {
+        // We need to wait until the editor javascript is all required in to call the
+        // method to load the code.  The HandleWebViewLoadEnd event is getting called
+        // too soon.
+        webClient_->ExecuteJavaScript(ToString("HOST_loadCode(\"atomic://resources/%s\");", normalizedPath.CString()));
+    }
     else
     {
         JSONValue jvalue;
         if (JSONFile::ParseJSON(request, jvalue, false))
         {
             String message = jvalue["message"].GetString();
-            if (message == "saveCode")
+            if (message == EDITOR_SAVE_CODE)
             {
                 String code = jvalue["payload"].GetString();
                 File file(context_, fullpath_, FILE_WRITE);
@@ -178,7 +197,7 @@ bool JSResourceEditor::Save()
     if (!modified_)
         return true;
 
-    webClient_->ExecuteJavaScript("saveCode();");
+    webClient_->ExecuteJavaScript("HOST_saveCode();");
 
     SetModified(false);
 

Some files were not shown because too many files changed in this diff