// // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved // LICENSE: Atomic Game Engine Editor and Tools EULA // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for // license information: https://github.com/AtomicGameEngine/AtomicGameEngine // #include #include #include #include #include #include #include #include #include #include #include #include #include "JSResourceEditor.h" using namespace tb; namespace AtomicEditor { JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, UITabContainer *container) : ResourceEditor(context, fullpath, container) { TBLayout* layout = new TBLayout(); layout->SetLayoutSize(LAYOUT_SIZE_GRAVITY); layout->SetGravity(WIDGET_GRAVITY_ALL); layout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY); rootContentWidget_->GetInternalWidget()->AddChild(layout); TBContainer* c = new TBContainer(); c->SetGravity(WIDGET_GRAVITY_ALL); layout->AddChild(c); String url = "file:///Users/josh/Dev/atomic/AtomicGameEngine/Data/AtomicEditor/CodeEditor/Editor.html"; webView_ = new UIWebView(context_, url); webClient_ = webView_->GetWebClient(); messageHandler_ = new WebMessageHandler(context_); webClient_->AddMessageHandler(messageHandler_); SubscribeToEvent(webClient_, E_WEBVIEWLOADEND, HANDLER(JSResourceEditor, HandleWebViewLoadEnd)); SubscribeToEvent(messageHandler_, E_WEBMESSAGE, HANDLER(JSResourceEditor, HandleWebMessage)); c->AddChild(webView_->GetInternalWidget()); // FIXME: Set the size at the end of setup, so all children are updated accordingly // future size changes will be handled automatically IntRect rect = container_->GetContentRoot()->GetRect(); rootContentWidget_->SetSize(rect.Width(), rect.Height()); } JSResourceEditor::~JSResourceEditor() { } void JSResourceEditor::HandleWebViewLoadEnd(StringHash eventType, VariantMap& eventData) { webClient_->ExecuteJavaScript(ToString("loadCode(\"atomic://resources/%s\");", fullpath_.CString())); } void JSResourceEditor::HandleWebMessage(StringHash eventType, VariantMap& eventData) { using namespace WebMessage; const String& request = eventData[P_REQUEST].GetString(); WebMessageHandler* handler = static_cast(eventData[P_HANDLER].GetPtr()); if (request == "change") { SetModified(true); } handler->Success(); } void JSResourceEditor::FormatCode() { } bool JSResourceEditor::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_SHORTCUT) { if (ev.ref_id == TBIDC("close")) { RequestClose(); } } return false; } void JSResourceEditor::FindTextClose() { } bool JSResourceEditor::FindText(const String& findText, unsigned flags) { return true; } void JSResourceEditor::SetFocus() { //editField_->SetFocus(WIDGET_FOCUS_REASON_UNKNOWN); } void JSResourceEditor::GotoTokenPos(int tokenPos) { } void JSResourceEditor::GotoLineNumber(int lineNumber) { } bool JSResourceEditor::Save() { if (!modified_) return true; SetModified(false); return true; } }