Explorar o código

Modifications to JSResourceEditor - pass path to code editor URL from the typescript (custom editor class, allowing for a variety of pure web editor implementations) and fixes issue with the EDITOR_SAVE_FILE AtomicQuery call so that the web view can pass up a code block and path and it will save it.

Shaddock Heath %!s(int64=9) %!d(string=hai) anos
pai
achega
6c96ab225f

+ 9 - 14
Source/AtomicEditor/Editors/JSResourceEditor.cpp

@@ -51,7 +51,7 @@ using namespace ToolCore;
 namespace AtomicEditor
 {
 
-JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, UITabContainer *container) :
+JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, UITabContainer *container, const String &editorUrl) :
     ResourceEditor(context, fullpath, container)
 {
 
@@ -67,17 +67,7 @@ JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, UI
 
     layout->AddChild(c);
 
-    ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
-    String codeEditorDir = tenv->GetToolDataDir();
-    codeEditorDir += "CodeEditor/Editor.html";
-
-#ifdef ATOMIC_PLATFORM_OSX
-    String url = "file://" + codeEditorDir;
-#else
-    String url = "file:///" + codeEditorDir;
-#endif
-
-    webView_ = new UIWebView(context_, url);
+    webView_ = new UIWebView(context_, editorUrl);
     webClient_ = webView_->GetWebClient();
     messageHandler_ = new WebMessageHandler(context_);
     webClient_->AddMessageHandler(messageHandler_);
@@ -158,8 +148,13 @@ void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventD
             {
                 String code = jvalue["payload"].GetString();
                 String fn = jvalue["filename"].GetString();
-                // TODO: determine if we are absolute path or partial path
-                File file(context_, fn, FILE_WRITE);
+
+                // NOTE: We only want to be able save into the resource directory, so parse out the file path and append
+                // it to the resource directory
+                ToolSystem* tsys = GetSubsystem<ToolSystem>();
+                String fullFilePath = tsys->GetProject()->GetProjectPath() + getNormalizedPath(fn);
+
+                File file(context_, fullFilePath, FILE_WRITE);
                 file.Write((void*) code.CString(), code.Length());
                 file.Close();
             }

+ 2 - 2
Source/AtomicEditor/Editors/JSResourceEditor.h

@@ -43,7 +43,7 @@ class JSResourceEditor: public ResourceEditor
 
 public:
 
-    JSResourceEditor(Context* context, const String& fullpath, UITabContainer* container);
+    JSResourceEditor(Context* context, const String& fullpath, UITabContainer* container, const String& editorUrl);
 
     virtual ~JSResourceEditor();
 
@@ -74,7 +74,7 @@ private:
     void HandleRenameResourceNotification(StringHash eventType, VariantMap& eventData);
     void HandleDeleteResourceNotification(StringHash eventType, VariantMap& eventData);
     void HandleProjectUnloadedNotification(StringHash eventType, VariantMap& eventData);
-    
+
     SharedPtr<UIWebView> webView_;
     WeakPtr<WebClient> webClient_;
     WeakPtr<WebMessageHandler> messageHandler_;