ProjectFrameMenu.ts 6.2 KB

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