TSExample.plugin.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. var ExamplePluginUILabel = "TS Example Plugin";
  3. var ExamplePluginTBPath = "EditorData/Example.tb.txt";
  4. var TSExamplePluginService = (function () {
  5. function TSExamplePluginService() {
  6. var _this = this;
  7. this.name = "TSExampleService";
  8. this.description = "This service demonstrates plugin functionality written in TypeScript.";
  9. this.serviceLocator = null;
  10. this.extensionWindow = null;
  11. this.handleWidgetEvent = function (ev) {
  12. if (!_this.extensionWindow) {
  13. return;
  14. }
  15. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  16. if (ev.target.id == "example_cancel") {
  17. _this.extensionWindow.hide();
  18. _this.extensionWindow = null;
  19. return true;
  20. }
  21. if (ev.target.id == "example_speak") {
  22. _this.helloLabel.text = "Hello " + _this.nameField.text;
  23. return true;
  24. }
  25. }
  26. return false;
  27. };
  28. }
  29. TSExamplePluginService.prototype.initialize = function (serviceLoader) {
  30. Atomic.print("ExamplePluginService.initialize");
  31. this.serviceLocator = (serviceLoader);
  32. if (this.serviceLocator) {
  33. this.serviceLocator.projectServices.register(this);
  34. this.serviceLocator.uiServices.register(this);
  35. }
  36. };
  37. TSExamplePluginService.prototype.projectUnloaded = function () {
  38. this.serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
  39. Atomic.print("ExamplePluginService.projectUnloaded");
  40. if (this.serviceLocator) {
  41. this.serviceLocator.projectServices.unregister(this);
  42. this.serviceLocator.uiServices.unregister(this);
  43. }
  44. };
  45. TSExamplePluginService.prototype.projectLoaded = function (ev) {
  46. Atomic.print("ExamplePluginService.projectLoaded");
  47. var menu = this.serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, { "Open": ["tsexampleplugin open"] });
  48. };
  49. TSExamplePluginService.prototype.playerStarted = function () {
  50. Atomic.print("ExamplePluginService.playerStarted");
  51. };
  52. TSExamplePluginService.prototype.menuItemClicked = function (refId) {
  53. Atomic.print("ExamplePluginService.menuItemClicked: " + refId);
  54. if (refId == "tsexampleplugin open") {
  55. this.extensionWindow = this.serviceLocator.uiServices.showModalWindow(ExamplePluginUILabel, ExamplePluginTBPath, this.handleWidgetEvent);
  56. this.getWidgets();
  57. return true;
  58. }
  59. return false;
  60. };
  61. TSExamplePluginService.prototype.getWidgets = function () {
  62. if (!this.extensionWindow) {
  63. return;
  64. }
  65. this.helloLabel = this.extensionWindow.getWidget("example_hello");
  66. this.nameField = this.extensionWindow.getWidget("example_name");
  67. };
  68. return TSExamplePluginService;
  69. }());
  70. var examplePluginService = new TSExamplePluginService();
  71. Object.defineProperty(exports, "__esModule", { value: true });
  72. exports.default = examplePluginService;