|
|
@@ -33,6 +33,8 @@
|
|
|
#include <AtomicJS/Javascript/JSVM.h>
|
|
|
|
|
|
#include <ToolCore/ToolEnvironment.h>
|
|
|
+#include <ToolCore/ToolSystem.h>
|
|
|
+#include <ToolCore/Project/Project.h>
|
|
|
|
|
|
#include <AtomicWebView/WebViewEvents.h>
|
|
|
#include <AtomicWebView/UIWebView.h>
|
|
|
@@ -92,12 +94,12 @@ JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, UI
|
|
|
c->AddChild(webView_->GetInternalWidget());
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
JSResourceEditor::~JSResourceEditor()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
String getNormalizedPath(const String& path)
|
|
|
{
|
|
|
// Full path is the fully qualified path from the root of the filesystem. In order
|
|
|
@@ -107,34 +109,34 @@ String getNormalizedPath(const String& path)
|
|
|
const String& RESOURCES_MARKER = "resources/";
|
|
|
return path.SubstringUTF8(path.ToLower().Find(RESOURCES_MARKER));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
void JSResourceEditor::HandleRenameResourceNotification(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
using namespace RenameResourceNotification;
|
|
|
const String& newPath = eventData[P_NEWRESOURCEPATH].GetString();
|
|
|
const String& path = eventData[P_RESOURCEPATH].GetString();
|
|
|
-
|
|
|
+
|
|
|
webClient_->ExecuteJavaScript(ToString("HOST_resourceRenamed(\"%s\",\"%s\");", getNormalizedPath(path).CString(), getNormalizedPath(newPath).CString()));
|
|
|
-
|
|
|
+
|
|
|
if (fullpath_.Compare(path) == 0) {
|
|
|
fullpath_ = newPath;
|
|
|
SetModified(modified_);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
void JSResourceEditor::HandleDeleteResourceNotification(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
using namespace DeleteResourceNotification;
|
|
|
const String& path = eventData[P_RESOURCEPATH].GetString();
|
|
|
-
|
|
|
+
|
|
|
webClient_->ExecuteJavaScript(ToString("HOST_resourceDeleted(\"%s\");", getNormalizedPath(path).CString()));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
void JSResourceEditor::HandleProjectUnloadedNotification(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
webClient_->ExecuteJavaScript("HOST_projectUnloaded();");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
void JSResourceEditor::HandleWebViewLoadEnd(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
// need to wait until we get an editor load complete message since we could
|
|
|
@@ -150,9 +152,10 @@ void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventD
|
|
|
const String& EDITOR_SAVE_CODE = "editorSaveCode";
|
|
|
const String& EDITOR_SAVE_FILE = "editorSaveFile";
|
|
|
const String& EDITOR_LOAD_COMPLETE = "editorLoadComplete";
|
|
|
-
|
|
|
+ const String& EDITOR_GET_USER_PREFS = "editorGetUserPrefs";
|
|
|
+
|
|
|
String normalizedPath = getNormalizedPath(fullpath_);
|
|
|
-
|
|
|
+
|
|
|
WebMessageHandler* handler = static_cast<WebMessageHandler*>(eventData[P_HANDLER].GetPtr());
|
|
|
|
|
|
if (request == EDITOR_CHANGE)
|
|
|
@@ -188,6 +191,16 @@ void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventD
|
|
|
file.Write((void*) code.CString(), code.Length());
|
|
|
file.Close();
|
|
|
}
|
|
|
+ else if (message == EDITOR_GET_USER_PREFS)
|
|
|
+ {
|
|
|
+ ToolSystem* tsys = GetSubsystem<ToolSystem>();
|
|
|
+ Project* proj = tsys->GetProject();
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
+ if (fileSystem->FileExists(proj->GetUserPrefsFullPath()))
|
|
|
+ {
|
|
|
+ webClient_->ExecuteJavaScript(ToString("HOST_loadPreferences(\"atomic://%s\");", proj->GetUserPrefsFullPath().CString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|