JSResourceEditor.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/Container/ArrayPtr.h>
  8. #include <Atomic/UI/UI.h>
  9. #include <Atomic/IO/Log.h>
  10. #include <Atomic/IO/File.h>
  11. #include <Atomic/IO/FileSystem.h>
  12. #include <Atomic/Resource/ResourceCache.h>
  13. #include <Atomic/Core/CoreEvents.h>
  14. #include <AtomicJS/Javascript/JSVM.h>
  15. #include <AtomicWebView/WebViewEvents.h>
  16. #include <AtomicWebView/UIWebView.h>
  17. #include <AtomicWebView/WebClient.h>
  18. #include "JSResourceEditor.h"
  19. using namespace tb;
  20. namespace AtomicEditor
  21. {
  22. JSResourceEditor ::JSResourceEditor(Context* context, const String &fullpath, UITabContainer *container) :
  23. ResourceEditor(context, fullpath, container)
  24. {
  25. TBLayout* layout = new TBLayout();
  26. layout->SetLayoutSize(LAYOUT_SIZE_GRAVITY);
  27. layout->SetGravity(WIDGET_GRAVITY_ALL);
  28. layout->SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
  29. rootContentWidget_->GetInternalWidget()->AddChild(layout);
  30. TBContainer* c = new TBContainer();
  31. c->SetGravity(WIDGET_GRAVITY_ALL);
  32. layout->AddChild(c);
  33. String url = "file://";
  34. webView_ = new UIWebView(context_, "file:///Users/josh/Dev/atomic/AtomicGameEngine/Data/AtomicEditor/CodeEditor/Editor.html");
  35. webClient_ = webView_->GetWebClient();
  36. SubscribeToEvent(webClient_, E_WEBVIEWLOADEND, HANDLER(JSResourceEditor, HandleWebViewLoadEnd));
  37. c->AddChild(webView_->GetInternalWidget());
  38. // FIXME: Set the size at the end of setup, so all children are updated accordingly
  39. // future size changes will be handled automatically
  40. IntRect rect = container_->GetContentRoot()->GetRect();
  41. rootContentWidget_->SetSize(rect.Width(), rect.Height());
  42. }
  43. JSResourceEditor::~JSResourceEditor()
  44. {
  45. }
  46. void JSResourceEditor::HandleWebViewLoadEnd(StringHash eventType, VariantMap& eventData)
  47. {
  48. webClient_->ExecuteJavaScript("sayHi();");
  49. }
  50. void JSResourceEditor::FormatCode()
  51. {
  52. }
  53. bool JSResourceEditor::OnEvent(const TBWidgetEvent &ev)
  54. {
  55. if (ev.type == EVENT_TYPE_SHORTCUT)
  56. {
  57. if (ev.ref_id == TBIDC("close"))
  58. {
  59. RequestClose();
  60. }
  61. }
  62. return false;
  63. }
  64. void JSResourceEditor::FindTextClose()
  65. {
  66. }
  67. bool JSResourceEditor::FindText(const String& findText, unsigned flags)
  68. {
  69. return true;
  70. }
  71. void JSResourceEditor::SetFocus()
  72. {
  73. //editField_->SetFocus(WIDGET_FOCUS_REASON_UNKNOWN);
  74. }
  75. void JSResourceEditor::GotoTokenPos(int tokenPos)
  76. {
  77. }
  78. void JSResourceEditor::GotoLineNumber(int lineNumber)
  79. {
  80. }
  81. bool JSResourceEditor::Save()
  82. {
  83. if (!modified_)
  84. return true;
  85. SetModified(false);
  86. return true;
  87. }
  88. }