Browse Source

merge from upstream

Shaddock Heath 9 years ago
parent
commit
60e7d8a56a

+ 43 - 21
EditorPluginExample/Resources/EditorData/TSExample.plugin.js

@@ -1,17 +1,16 @@
-"use strict";
-var ExamplePluginUILabel = "TS Example Plugin";
+var ExamplePluginUILabel = "Example Plugin";
 var ExamplePluginTBPath = "EditorData/Example.tb.txt";
 var ExamplePluginTBPath = "EditorData/Example.tb.txt";
-var TSExamplePluginService = (function () {
-    function TSExamplePluginService() {
+var ExamplePluginService = (function () {
+    function ExamplePluginService() {
         var _this = this;
         var _this = this;
-        this.name = "TSExampleService";
-        this.description = "This service demonstrates plugin functionality written in TypeScript.";
+        this.name = "ExampleService";
+        this.description = "This service demonstrates plugin functionality functionality.";
         this.serviceLocator = null;
         this.serviceLocator = null;
         this.extensionWindow = null;
         this.extensionWindow = null;
+        this.lastObjectName = null;
         this.handleWidgetEvent = function (ev) {
         this.handleWidgetEvent = function (ev) {
-            if (!_this.extensionWindow) {
+            if (!_this.extensionWindow)
                 return;
                 return;
-            }
             if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
             if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
                 if (ev.target.id == "example_cancel") {
                 if (ev.target.id == "example_cancel") {
                     _this.extensionWindow.hide();
                     _this.extensionWindow.hide();
@@ -26,7 +25,7 @@ var TSExamplePluginService = (function () {
             return false;
             return false;
         };
         };
     }
     }
-    TSExamplePluginService.prototype.initialize = function (serviceLoader) {
+    ExamplePluginService.prototype.initialize = function (serviceLoader) {
         Atomic.print("ExamplePluginService.initialize");
         Atomic.print("ExamplePluginService.initialize");
         this.serviceLocator = (serviceLoader);
         this.serviceLocator = (serviceLoader);
         if (this.serviceLocator) {
         if (this.serviceLocator) {
@@ -34,7 +33,9 @@ var TSExamplePluginService = (function () {
             this.serviceLocator.uiServices.register(this);
             this.serviceLocator.uiServices.register(this);
         }
         }
     };
     };
-    TSExamplePluginService.prototype.projectUnloaded = function () {
+    ExamplePluginService.prototype.projectUnloaded = function () {
+        this.serviceLocator.uiServices.removeProjectContextMenuItemSource(ExamplePluginUILabel);
+        this.serviceLocator.uiServices.removeHierarchyContextMenuItemSource(ExamplePluginUILabel);
         this.serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
         this.serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
         Atomic.print("ExamplePluginService.projectUnloaded");
         Atomic.print("ExamplePluginService.projectUnloaded");
         if (this.serviceLocator) {
         if (this.serviceLocator) {
@@ -42,31 +43,52 @@ var TSExamplePluginService = (function () {
             this.serviceLocator.uiServices.unregister(this);
             this.serviceLocator.uiServices.unregister(this);
         }
         }
     };
     };
-    TSExamplePluginService.prototype.projectLoaded = function (ev) {
+    ExamplePluginService.prototype.projectLoaded = function (ev) {
         Atomic.print("ExamplePluginService.projectLoaded");
         Atomic.print("ExamplePluginService.projectLoaded");
-        var menu = this.serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, { "Open": ["tsexampleplugin open"] });
+        this.serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, { "Open": ["exampleplugin open"] });
+        this.serviceLocator.uiServices.createHierarchyContextMenuItemSource(ExamplePluginUILabel, { "Get name": ["exampleplugin hierarchy context"] });
+        this.serviceLocator.uiServices.createProjectContextMenuItemSource(ExamplePluginUILabel, { "Get name": ["exampleplugin project context"] });
     };
     };
-    TSExamplePluginService.prototype.playerStarted = function () {
+    ExamplePluginService.prototype.playerStarted = function () {
         Atomic.print("ExamplePluginService.playerStarted");
         Atomic.print("ExamplePluginService.playerStarted");
     };
     };
-    TSExamplePluginService.prototype.menuItemClicked = function (refId) {
+    ExamplePluginService.prototype.menuItemClicked = function (refId) {
         Atomic.print("ExamplePluginService.menuItemClicked: " + refId);
         Atomic.print("ExamplePluginService.menuItemClicked: " + refId);
-        if (refId == "tsexampleplugin open") {
+        if (refId == "exampleplugin open") {
             this.extensionWindow = this.serviceLocator.uiServices.showModalWindow(ExamplePluginUILabel, ExamplePluginTBPath, this.handleWidgetEvent);
             this.extensionWindow = this.serviceLocator.uiServices.showModalWindow(ExamplePluginUILabel, ExamplePluginTBPath, this.handleWidgetEvent);
             this.getWidgets();
             this.getWidgets();
             return true;
             return true;
         }
         }
         return false;
         return false;
     };
     };
-    TSExamplePluginService.prototype.getWidgets = function () {
-        if (!this.extensionWindow) {
-            return;
+    ExamplePluginService.prototype.hierarchyContextItemClicked = function (node, refid) {
+        Atomic.print("ExamplePluginService.hierarchyContextItemClicked: " + node.name + " " + refid);
+        if (refid == "exampleplugin hierarchy context") {
+            this.lastObjectName = "node " + node.name;
+            return true;
         }
         }
+        return false;
+    };
+    ExamplePluginService.prototype.projectContextItemClicked = function (asset, refid) {
+        Atomic.print("ExamplePluginService.projectContextItemClicked: " + asset.name + " " + refid);
+        if (refid == "exampleplugin project context") {
+            this.lastObjectName = "asset " + asset.name;
+            return true;
+        }
+        return false;
+    };
+    ExamplePluginService.prototype.getWidgets = function () {
+        if (!this.extensionWindow)
+            return;
         this.helloLabel = this.extensionWindow.getWidget("example_hello");
         this.helloLabel = this.extensionWindow.getWidget("example_hello");
         this.nameField = this.extensionWindow.getWidget("example_name");
         this.nameField = this.extensionWindow.getWidget("example_name");
+        if (this.lastObjectName) {
+            this.nameField.text = this.lastObjectName;
+            this.lastObjectName = null;
+        }
     };
     };
-    return TSExamplePluginService;
-}());
-var examplePluginService = new TSExamplePluginService();
+    return ExamplePluginService;
+})();
+var examplePluginService = new ExamplePluginService();
 Object.defineProperty(exports, "__esModule", { value: true });
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.default = examplePluginService;
 exports.default = examplePluginService;

+ 47 - 14
EditorPluginExample/Resources/EditorData/TSExample.plugin.ts

@@ -1,13 +1,13 @@
 /// <reference path="../../typings/Atomic/AtomicWork.d.ts" />
 /// <reference path="../../typings/Atomic/AtomicWork.d.ts" />
 /// <reference path="../../typings/Atomic/EditorWork.d.ts" />
 /// <reference path="../../typings/Atomic/EditorWork.d.ts" />
 
 
-const ExamplePluginUILabel = "TS Example Plugin";
+const ExamplePluginUILabel = "Example Plugin";
 const ExamplePluginTBPath = "EditorData/Example.tb.txt";
 const ExamplePluginTBPath = "EditorData/Example.tb.txt";
 
 
-class TSExamplePluginService implements Editor.HostExtensions.HostEditorService, Editor.HostExtensions.ProjectServicesEventListener, Editor.HostExtensions.UIServicesEventListener {
+class ExamplePluginService implements Editor.HostExtensions.HostEditorService, Editor.HostExtensions.ProjectServicesEventListener, Editor.HostExtensions.UIServicesEventListener {
 
 
-    name: string = "TSExampleService";
-    description: string = "This service demonstrates plugin functionality written in TypeScript.";
+    name: string = "ExampleService";
+    description: string = "This service demonstrates plugin functionality functionality.";
 
 
     private serviceLocator: Editor.HostExtensions.HostServiceLocator = null;
     private serviceLocator: Editor.HostExtensions.HostServiceLocator = null;
     private extensionWindow: Editor.Modal.ExtensionWindow = null;
     private extensionWindow: Editor.Modal.ExtensionWindow = null;
@@ -15,6 +15,8 @@ class TSExamplePluginService implements Editor.HostExtensions.HostEditorService,
     private helloLabel: Atomic.UITextField;
     private helloLabel: Atomic.UITextField;
     private nameField: Atomic.UIEditField;
     private nameField: Atomic.UIEditField;
 
 
+    private lastObjectName: string = null;
+
     initialize(serviceLoader: Editor.HostExtensions.HostServiceLocator) {
     initialize(serviceLoader: Editor.HostExtensions.HostServiceLocator) {
         Atomic.print("ExamplePluginService.initialize");
         Atomic.print("ExamplePluginService.initialize");
 
 
@@ -25,6 +27,8 @@ class TSExamplePluginService implements Editor.HostExtensions.HostEditorService,
         }
         }
     }
     }
     projectUnloaded() {
     projectUnloaded() {
+        this.serviceLocator.uiServices.removeProjectContextMenuItemSource(ExamplePluginUILabel);
+        this.serviceLocator.uiServices.removeHierarchyContextMenuItemSource(ExamplePluginUILabel);
         this.serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
         this.serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
 
 
         Atomic.print("ExamplePluginService.projectUnloaded");
         Atomic.print("ExamplePluginService.projectUnloaded");
@@ -35,7 +39,9 @@ class TSExamplePluginService implements Editor.HostExtensions.HostEditorService,
     }
     }
     projectLoaded(ev: Editor.EditorEvents.LoadProjectEvent) {
     projectLoaded(ev: Editor.EditorEvents.LoadProjectEvent) {
         Atomic.print("ExamplePluginService.projectLoaded");
         Atomic.print("ExamplePluginService.projectLoaded");
-        let menu = this.serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, { "Open" : ["tsexampleplugin open"] });
+        this.serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, { "Open" : ["exampleplugin open"] });
+        this.serviceLocator.uiServices.createHierarchyContextMenuItemSource(ExamplePluginUILabel, { "Get name" : ["exampleplugin hierarchy context"]});
+        this.serviceLocator.uiServices.createProjectContextMenuItemSource(ExamplePluginUILabel, { "Get name" : ["exampleplugin project context"]});
     }
     }
     playerStarted() {
     playerStarted() {
         Atomic.print("ExamplePluginService.playerStarted");
         Atomic.print("ExamplePluginService.playerStarted");
@@ -43,8 +49,8 @@ class TSExamplePluginService implements Editor.HostExtensions.HostEditorService,
 
 
     menuItemClicked(refId: string): boolean {
     menuItemClicked(refId: string): boolean {
         Atomic.print("ExamplePluginService.menuItemClicked: " + refId);
         Atomic.print("ExamplePluginService.menuItemClicked: " + refId);
-
-        if (refId == "tsexampleplugin open") {
+        
+        if (refId == "exampleplugin open") {
             this.extensionWindow = this.serviceLocator.uiServices.showModalWindow(
             this.extensionWindow = this.serviceLocator.uiServices.showModalWindow(
                 ExamplePluginUILabel, ExamplePluginTBPath, this.handleWidgetEvent);
                 ExamplePluginUILabel, ExamplePluginTBPath, this.handleWidgetEvent);
             this.getWidgets();
             this.getWidgets();
@@ -54,19 +60,46 @@ class TSExamplePluginService implements Editor.HostExtensions.HostEditorService,
         return false;
         return false;
     }
     }
 
 
+    hierarchyContextItemClicked(node: Atomic.Node, refid: string): boolean {
+        Atomic.print("ExamplePluginService.hierarchyContextItemClicked: " + node.name + " " + refid);
+
+        if (refid == "exampleplugin hierarchy context") {
+            this.lastObjectName = "node " + node.name;
+
+            return true;
+        }
+
+        return false;
+    }
+
+    projectContextItemClicked(asset: ToolCore.Asset, refid: string): boolean {
+        Atomic.print("ExamplePluginService.projectContextItemClicked: " + asset.name + " " + refid);
+
+        if (refid == "exampleplugin project context") {
+            this.lastObjectName = "asset " + asset.name;
+
+            return true;
+        }
+
+        return false;
+    }
+
     getWidgets() {
     getWidgets() {
-        if (!this.extensionWindow) {
+        if (!this.extensionWindow)
             return;
             return;
-        }
 
 
         this.helloLabel = <Atomic.UITextField>this.extensionWindow.getWidget("example_hello");
         this.helloLabel = <Atomic.UITextField>this.extensionWindow.getWidget("example_hello");
         this.nameField = <Atomic.UIEditField>this.extensionWindow.getWidget("example_name");
         this.nameField = <Atomic.UIEditField>this.extensionWindow.getWidget("example_name");
+
+        if (this.lastObjectName) {
+            this.nameField.text = this.lastObjectName;
+            this.lastObjectName = null;
+        }
     }
     }
 
 
     handleWidgetEvent = (ev: Atomic.UIWidgetEvent): boolean => { // => notation used to bind "this" to the method
     handleWidgetEvent = (ev: Atomic.UIWidgetEvent): boolean => { // => notation used to bind "this" to the method
-        if (!this.extensionWindow) {
+        if (!this.extensionWindow)
             return;
             return;
-        }
 
 
         if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
         if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
 
 
@@ -86,8 +119,8 @@ class TSExamplePluginService implements Editor.HostExtensions.HostEditorService,
 
 
         return false;
         return false;
 
 
-    };
+    }
 }
 }
 
 
-const examplePluginService = new TSExamplePluginService();
-export default examplePluginService;
+const examplePluginService = new ExamplePluginService();
+export default examplePluginService;

+ 8 - 1
EditorPluginExample/typings/Atomic/EditorWork.d.ts

@@ -7,6 +7,7 @@
 
 
 /// <reference path="Atomic.d.ts" />
 /// <reference path="Atomic.d.ts" />
 /// <reference path="Editor.d.ts" />
 /// <reference path="Editor.d.ts" />
+/// <reference path="ToolCore.d.ts" />
 
 
 declare module Editor.EditorEvents {
 declare module Editor.EditorEvents {
 
 
@@ -254,11 +255,17 @@ declare module Editor.HostExtensions {
     export interface ProjectServicesProvider extends Editor.Extensions.ServicesProvider<ProjectServicesEventListener> { }
     export interface ProjectServicesProvider extends Editor.Extensions.ServicesProvider<ProjectServicesEventListener> { }
 
 
     export interface UIServicesEventListener extends Editor.Extensions.ServiceEventListener {
     export interface UIServicesEventListener extends Editor.Extensions.ServiceEventListener {
-        menuItemClicked?(refId: string): boolean;
+        menuItemClicked?(refid: string): boolean;
+        projectContextItemClicked?(asset: ToolCore.Asset, refid: string): boolean;
+        hierarchyContextItemClicked?(node: Atomic.Node, refid: string): boolean;
     }
     }
     export interface UIServicesProvider extends Editor.Extensions.ServicesProvider<UIServicesEventListener> {
     export interface UIServicesProvider extends Editor.Extensions.ServicesProvider<UIServicesEventListener> {
         createPluginMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
         createPluginMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
         removePluginMenuItemSource(id: string);
         removePluginMenuItemSource(id: string);
+        createHierarchyContextMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
+        removeHierarchyContextMenuItemSource(id: string);
+        createProjectContextMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource;
+        removeProjectContextMenuItemSource(id: string);
         showModalWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow;
         showModalWindow(windowText: string, uifilename: string, handleWidgetEventCB: (ev: Atomic.UIWidgetEvent) => void): Editor.Modal.ExtensionWindow;
     }
     }
 }
 }