ProjectFrameMenu.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 EditorEvents = require("editor/EditorEvents");
  24. import EditorUI = require("ui/EditorUI");
  25. import MenuItemSources = require("./MenuItemSources");
  26. import ServiceLocator from "../../../hostExtensions/ServiceLocator";
  27. class ProjectFrameMenus extends Atomic.ScriptObject {
  28. contentFolder: string;
  29. private contextMenuItemSource: Atomic.UIMenuItemSource = null;
  30. constructor() {
  31. super();
  32. MenuItemSources.createMenuItemSource("asset context folder", assetFolderContextItems);
  33. this.contextMenuItemSource = MenuItemSources.createMenuItemSource("asset context general", assetGeneralContextItems);
  34. MenuItemSources.createMenuItemSource("project create items", createItems);
  35. this.subscribeToEvent(EditorEvents.ContentFolderChangedEvent((ev: EditorEvents.ContentFolderChangedEvent) => {
  36. this.contentFolder = ev.path;
  37. }));
  38. }
  39. handleAssetContextMenu(target: Atomic.UIWidget, refid: string):boolean {
  40. if (target.id == "asset context menu" || target.id == "create popup") {
  41. var path;
  42. var asset = <ToolCore.Asset> target["asset"];
  43. if (asset) {
  44. path = asset.path;
  45. } else {
  46. path = this.contentFolder;
  47. }
  48. if (refid == "rename_asset") {
  49. EditorUI.getModelOps().showRenameAsset(asset);
  50. return true;
  51. }
  52. if (refid == "delete_asset") {
  53. EditorUI.getModelOps().showResourceDelete(asset);
  54. return true;
  55. }
  56. if (refid == "create_folder") {
  57. EditorUI.getModelOps().showCreateFolder(path);
  58. return true;
  59. }
  60. if (refid == "create_component") {
  61. EditorUI.getModelOps().showCreateComponent(path);
  62. return true;
  63. }
  64. if (refid == "create_script") {
  65. EditorUI.getModelOps().showCreateScript(path);
  66. return true;
  67. }
  68. if (refid == "create_scene") {
  69. EditorUI.getModelOps().showCreateScene(path);
  70. return true;
  71. }
  72. if (refid == "create_material") {
  73. EditorUI.getModelOps().showCreateMaterial(path);
  74. return true;
  75. }
  76. if (refid == "reveal_folder") {
  77. var utils = new Editor.FileUtils();
  78. utils.revealInFinder(path);
  79. return true;
  80. }
  81. if (refid == "force_reimport") {
  82. asset.setDirty(true);
  83. ToolCore.assetDatabase.scan();
  84. return true;
  85. }
  86. if (refid == "force_reimport_folder") {
  87. ToolCore.assetDatabase.reimportAllAssetsInDirectory(path);
  88. return true;
  89. }
  90. // Let plugins handle context
  91. return ServiceLocator.uiServices.projectContextItemClicked(asset, refid);
  92. }
  93. return false;
  94. }
  95. createFolderContextMenu(parent: Atomic.UIWidget, id: string, folder: ToolCore.Asset, x: number, y: number) {
  96. }
  97. createAssetContextMenu(parent: Atomic.UIWidget, asset: ToolCore.Asset, x: number, y: number) {
  98. var menu = new Atomic.UIMenuWindow(parent, "asset context menu");
  99. menu["asset"] = asset;
  100. var srcName: string;
  101. if (asset.isFolder()) {
  102. srcName = "asset context folder";
  103. } else {
  104. srcName = "asset context general";
  105. }
  106. var src = MenuItemSources.getMenuItemSource(srcName);
  107. menu.show(src, x, y);
  108. }
  109. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  110. if (!target || !refid) return;
  111. if (this.handleAssetContextMenu(target, refid)) {
  112. return true;
  113. }
  114. return false;
  115. }
  116. createPluginItemSource(id: string, items: any): Atomic.UIMenuItemSource {
  117. return MenuItemSources.createSubMenuItemSource(this.contextMenuItemSource , id, items);
  118. }
  119. removePluginItemSource(id: string) {
  120. this.contextMenuItemSource.removeItemWithStr(id);
  121. }
  122. }
  123. export = ProjectFrameMenus;
  124. // initialization
  125. var StringID = strings.StringID;
  126. //Change the words "Reveal in Finder" based on platform
  127. var showInFs = "Reveal in File Manager";
  128. if (Atomic.platform == "Windows") {
  129. showInFs = "Reveal in Explorer";
  130. }
  131. else if (Atomic.platform == "MacOSX") {
  132. showInFs = "Reveal in Finder";
  133. }
  134. var assetGeneralContextItems = {
  135. "Rename": ["rename_asset", undefined, ""],
  136. "Force Reimport": ["force_reimport", undefined, ""],
  137. [showInFs]: ["reveal_folder", undefined, ""],
  138. "-1": null,
  139. "Delete": ["delete_asset", undefined, ""]
  140. };
  141. var assetFolderContextItems = {
  142. "Create Folder": ["create_folder", undefined, "Folder.icon"],
  143. "Create Component": ["create_component", undefined, "ComponentBitmap"],
  144. "Create Script": ["create_script", undefined, "ComponentBitmap"],
  145. "Create Material": ["create_material", undefined, "ComponentBitmap"],
  146. "Create Scene": ["create_scene", undefined, "ComponentBitmap"],
  147. "Force Reimport": ["force_reimport_folder", undefined, ""],
  148. "-1": null,
  149. [showInFs]: ["reveal_folder", undefined, ""],
  150. "-2": null,
  151. "Delete": ["delete_asset", undefined, "FolderDeleteBitmap"]
  152. };
  153. var createItems = {
  154. "Create Folder": ["create_folder", undefined, "Folder.icon"],
  155. "Create Component": ["create_component", undefined, "ComponentBitmap"],
  156. "Create Script": ["create_script", undefined, "ComponentBitmap"],
  157. "Create Material": ["create_material", undefined, "ComponentBitmap"],
  158. "Create Scene": ["create_scene", undefined, "ComponentBitmap"],
  159. };