ProjectFrameMenu.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import strings = require("ui/EditorStrings");
  23. import EditorUI = require("ui/EditorUI");
  24. import MenuItemSources = require("./MenuItemSources");
  25. import ServiceLocator from "../../../hostExtensions/ServiceLocator";
  26. class ProjectFrameMenus extends Atomic.ScriptObject {
  27. contentFolder: string;
  28. private contextMenuItemSource: Atomic.UIMenuItemSource = null;
  29. constructor() {
  30. super();
  31. MenuItemSources.createMenuItemSource("asset context folder", assetFolderContextItems);
  32. this.contextMenuItemSource = MenuItemSources.createMenuItemSource("asset context general", assetGeneralContextItems);
  33. MenuItemSources.createMenuItemSource("project create items", createItems);
  34. this.subscribeToEvent(Editor.ContentFolderChangedEvent((ev: Editor.ContentFolderChangedEvent) => {
  35. this.contentFolder = ev.path;
  36. }));
  37. }
  38. handleAssetContextMenu(target: Atomic.UIWidget, refid: string):boolean {
  39. if (target.id == "asset context menu" || target.id == "create popup") {
  40. var path;
  41. var asset = <ToolCore.Asset> target["asset"];
  42. if (asset) {
  43. path = asset.path;
  44. } else {
  45. path = this.contentFolder;
  46. }
  47. if (refid == "rename_asset") {
  48. EditorUI.getModelOps().showRenameAsset(asset);
  49. return true;
  50. }
  51. if (refid == "delete_asset") {
  52. EditorUI.getModelOps().showResourceDelete(asset);
  53. return true;
  54. }
  55. if (refid == "create_folder") {
  56. EditorUI.getModelOps().showCreateFolder(path);
  57. return true;
  58. }
  59. if (refid == "create_component") {
  60. EditorUI.getModelOps().showCreateComponent(path);
  61. return true;
  62. }
  63. if (refid == "create_script") {
  64. EditorUI.getModelOps().showCreateScript(path);
  65. return true;
  66. }
  67. if (refid == "create_scene") {
  68. EditorUI.getModelOps().showCreateScene(path);
  69. return true;
  70. }
  71. if (refid == "create_material") {
  72. EditorUI.getModelOps().showCreateMaterial(path);
  73. return true;
  74. }
  75. if (refid == "reveal_folder") {
  76. var utils = new Editor.FileUtils();
  77. utils.revealInFinder(path);
  78. return true;
  79. }
  80. if (refid == "force_reimport") {
  81. asset.setDirty(true);
  82. ToolCore.assetDatabase.scan();
  83. return true;
  84. }
  85. if (refid == "import_asset") {
  86. var fileUtils = new Editor.FileUtils();
  87. var myassets = fileUtils.findFile("" , "");
  88. if ( myassets.length > 0 ) {
  89. this.sendEvent("ImportAssetEvent", { "file" : myassets, "destination" : path });
  90. }
  91. return true;
  92. }
  93. if (refid == "force_reimport_folder") {
  94. ToolCore.assetDatabase.reimportAllAssetsInDirectory(path);
  95. return true;
  96. }
  97. // Let plugins handle context
  98. return ServiceLocator.uiServices.projectContextItemClicked(asset, refid);
  99. }
  100. return false;
  101. }
  102. createFolderContextMenu(parent: Atomic.UIWidget, id: string, folder: ToolCore.Asset, x: number, y: number) {
  103. }
  104. createAssetContextMenu(parent: Atomic.UIWidget, asset: ToolCore.Asset, x: number, y: number) {
  105. var menu = new Atomic.UIMenuWindow(parent, "asset context menu");
  106. menu["asset"] = asset;
  107. var srcName: string;
  108. if (asset.isFolder()) {
  109. srcName = "asset context folder";
  110. } else {
  111. srcName = "asset context general";
  112. }
  113. var src = MenuItemSources.getMenuItemSource(srcName);
  114. menu.show(src, x, y);
  115. }
  116. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  117. if (!target || !refid) return;
  118. if (this.handleAssetContextMenu(target, refid)) {
  119. return true;
  120. }
  121. return false;
  122. }
  123. createPluginItemSource(id: string, items: any): Atomic.UIMenuItemSource {
  124. return MenuItemSources.createSubMenuItemSource(this.contextMenuItemSource , id, items);
  125. }
  126. removePluginItemSource(id: string) {
  127. this.contextMenuItemSource.removeItemWithStr(id);
  128. }
  129. }
  130. export = ProjectFrameMenus;
  131. // initialization
  132. var StringID = strings.StringID;
  133. //Change the words "Reveal in Finder" based on platform
  134. var showInFs = "Reveal in File Manager";
  135. if (Atomic.platform == "Windows") {
  136. showInFs = "Reveal in Explorer";
  137. }
  138. else if (Atomic.platform == "MacOSX") {
  139. showInFs = "Reveal in Finder";
  140. }
  141. var assetGeneralContextItems = {
  142. "Rename": ["rename_asset", undefined, ""],
  143. "Force Reimport": ["force_reimport", undefined, ""],
  144. [showInFs]: ["reveal_folder", undefined, ""],
  145. "-1": null,
  146. "Delete": ["delete_asset", undefined, ""]
  147. };
  148. var assetFolderContextItems = {
  149. "Create Folder": ["create_folder", undefined, "Folder.icon"],
  150. "Create Component": ["create_component", undefined, "ComponentBitmap"],
  151. "Create Script": ["create_script", undefined, "ComponentBitmap"],
  152. "Create Material": ["create_material", undefined, "ComponentBitmap"],
  153. "Create Scene": ["create_scene", undefined, "ComponentBitmap"],
  154. "Force Reimport": ["force_reimport_folder", undefined, ""],
  155. "Import Asset...": ["import_asset", undefined, ""],
  156. "-1": null,
  157. [showInFs]: ["reveal_folder", undefined, ""],
  158. "-2": null,
  159. "Delete": ["delete_asset", undefined, "FolderDeleteBitmap"]
  160. };
  161. var createItems = {
  162. "Create Folder": ["create_folder", undefined, "Folder.icon"],
  163. "Create Component": ["create_component", undefined, "ComponentBitmap"],
  164. "Create Script": ["create_script", undefined, "ComponentBitmap"],
  165. "Create Material": ["create_material", undefined, "ComponentBitmap"],
  166. "Create Scene": ["create_scene", undefined, "ComponentBitmap"],
  167. };