| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // 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 <Atomic/Container/ArrayPtr.h>
- #include <Atomic/UI/UI.h>
- #include <Atomic/IO/Log.h>
- #include <Atomic/IO/File.h>
- #include <Atomic/IO/FileSystem.h>
- #include <Atomic/Resource/ResourceCache.h>
- #include <Atomic/Core/CoreEvents.h>
- #include <AtomicJS/Javascript/JSVM.h>
- #include <AtomicWebView/WebViewEvents.h>
- #include <AtomicWebView/UIWebView.h>
- #include <AtomicWebView/WebClient.h>
- #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://";
- webView_ = new UIWebView(context_, "file:///Users/josh/Dev/atomic/AtomicGameEngine/Data/AtomicEditor/CodeEditor/Editor.html");
- webClient_ = webView_->GetWebClient();
- SubscribeToEvent(webClient_, E_WEBVIEWLOADEND, HANDLER(JSResourceEditor, HandleWebViewLoadEnd));
- 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("sayHi();");
- }
- 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;
- }
- }
|