void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventData) { using namespace WebMessage; const String& request = eventData[P_REQUEST].GetString(); WebMessageHandler* handler = static_cast<WebMessageHandler*>(eventData[P_HANDLER].GetPtr()); if (request == "change") { SetModified(true); } else { JSONValue jvalue; if (JSONFile::ParseJSON(request, jvalue, false)) { String message = jvalue["message"].GetString(); if (message == "saveCode") { String code = jvalue["payload"].GetString(); File file(context_, fullpath_, FILE_WRITE); file.Write((void*) code.CString(), code.Length()); file.Close(); } } } handler->Success(); }
void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventData) { using namespace WebMessage; const String& request = eventData[P_REQUEST].GetString(); const String& EDITOR_CHANGE = "editorChange"; const String& EDITOR_SAVE_CODE = "editorSaveCode"; const String& EDITOR_SAVE_FILE = "editorSaveFile"; const String& EDITOR_LOAD_COMPLETE = "editorLoadComplete"; String normalizedPath = getNormalizedPath(fullpath_); WebMessageHandler* handler = static_cast<WebMessageHandler*>(eventData[P_HANDLER].GetPtr()); 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://%s\");", normalizedPath.CString())); } else { JSONValue jvalue; if (JSONFile::ParseJSON(request, jvalue, false)) { String message = jvalue["message"].GetString(); if (message == EDITOR_SAVE_CODE) { String code = jvalue["payload"].GetString(); File file(context_, fullpath_, FILE_WRITE); file.Write((void*) code.CString(), code.Length()); file.Close(); } else if (message == EDITOR_SAVE_FILE) { 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); file.Write((void*) code.CString(), code.Length()); file.Close(); } } } handler->Success(); }