UIResourceOps.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 EditorEvents = require("editor/EditorEvents");
  23. import EditorUI = require("../EditorUI");
  24. import ModalWindow = require("./ModalWindow");
  25. import ResourceOps = require("resources/ResourceOps");
  26. export class ResourceDelete extends ModalWindow {
  27. constructor(asset: ToolCore.Asset) {
  28. super();
  29. this.asset = asset;
  30. this.init("Delete Resource", "AtomicEditor/editor/ui/resourcedelete.tb.txt");
  31. var message = <Atomic.UIEditField>this.getWidget("message");
  32. var text = "Are you sure you want to delete resource:\n\n";
  33. text += asset.path;
  34. text += "\n\nThis operation cannot be undone";
  35. message.text = text;
  36. this.resizeToFitContent();
  37. this.center();
  38. }
  39. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  40. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  41. var id = ev.target.id;
  42. if (id == "delete") {
  43. this.hide();
  44. let eventData = {
  45. path: this.asset.path
  46. };
  47. var db = ToolCore.getAssetDatabase();
  48. db.deleteAsset(this.asset);
  49. this.sendEvent(EditorEvents.DeleteResourceNotification, eventData);
  50. return true;
  51. }
  52. if (id == "cancel") {
  53. this.hide();
  54. return true;
  55. }
  56. }
  57. }
  58. asset: ToolCore.Asset;
  59. }
  60. export class CreateFolder extends ModalWindow {
  61. constructor(resourcePath: string) {
  62. super();
  63. this.resourcePath = resourcePath;
  64. this.init("New Folder", "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
  65. this.nameField = <Atomic.UIEditField>this.getWidget("folder_name");
  66. }
  67. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  68. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  69. var id = ev.target.id;
  70. if (id == "create") {
  71. var resourcePath = Atomic.addTrailingSlash(this.resourcePath) + this.nameField.text;
  72. if (ResourceOps.CreateNewFolder(resourcePath)) {
  73. this.hide();
  74. }
  75. return true;
  76. }
  77. if (id == "cancel") {
  78. this.hide();
  79. return true;
  80. }
  81. }
  82. }
  83. resourcePath: string;
  84. nameField: Atomic.UIEditField;
  85. }
  86. export class CreateComponent extends ModalWindow {
  87. constructor(resourcePath: string) {
  88. super();
  89. this.resourcePath = resourcePath;
  90. this.init("New Component", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  91. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  92. }
  93. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  94. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  95. var id = ev.target.id;
  96. if (id == "create") {
  97. var componentName = this.nameField.text;
  98. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + componentName;
  99. if (outputFile.indexOf(".js") == -1) outputFile += ".js";
  100. if (ResourceOps.CreateNewComponent(outputFile, componentName)) {
  101. this.hide();
  102. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  103. }
  104. return true;
  105. }
  106. if (id == "cancel") {
  107. this.hide();
  108. return true;
  109. }
  110. }
  111. }
  112. resourcePath: string;
  113. nameField: Atomic.UIEditField;
  114. }
  115. export class CreateScript extends ModalWindow {
  116. constructor(resourcePath: string) {
  117. super();
  118. this.resourcePath = resourcePath;
  119. this.init("New Script", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  120. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  121. }
  122. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  123. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  124. var id = ev.target.id;
  125. if (id == "create") {
  126. var scriptName = this.nameField.text;
  127. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + scriptName;
  128. if (outputFile.indexOf(".js") == -1) outputFile += ".js";
  129. if (ResourceOps.CreateNewScript(outputFile, scriptName)) {
  130. this.hide();
  131. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  132. }
  133. return true;
  134. }
  135. if (id == "cancel") {
  136. this.hide();
  137. return true;
  138. }
  139. }
  140. }
  141. resourcePath: string;
  142. nameField: Atomic.UIEditField;
  143. }
  144. export class CreateScene extends ModalWindow {
  145. constructor(resourcePath: string) {
  146. super();
  147. this.resourcePath = resourcePath;
  148. this.init("New Scene", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  149. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  150. }
  151. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  152. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  153. var id = ev.target.id;
  154. if (id == "create") {
  155. var sceneName = this.nameField.text;
  156. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + sceneName;
  157. if (outputFile.indexOf(".scene") == -1) outputFile += ".scene";
  158. if (ResourceOps.CreateNewScene(outputFile, sceneName)) {
  159. this.hide();
  160. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  161. }
  162. return true;
  163. }
  164. if (id == "cancel") {
  165. this.hide();
  166. return true;
  167. }
  168. }
  169. }
  170. resourcePath: string;
  171. nameField: Atomic.UIEditField;
  172. }
  173. export class CreateMaterial extends ModalWindow {
  174. constructor(resourcePath: string) {
  175. super();
  176. this.resourcePath = resourcePath;
  177. this.init("New Material", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  178. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  179. }
  180. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  181. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  182. var id = ev.target.id;
  183. if (id == "create") {
  184. var materialName = this.nameField.text;
  185. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + materialName;
  186. if (outputFile.indexOf(".material") == -1) outputFile += ".material";
  187. if (ResourceOps.CreateNewMaterial(outputFile, materialName)) {
  188. this.hide();
  189. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  190. }
  191. return true;
  192. }
  193. if (id == "cancel") {
  194. this.hide();
  195. return true;
  196. }
  197. }
  198. }
  199. resourcePath: string;
  200. nameField: Atomic.UIEditField;
  201. }
  202. export class RenameAsset extends ModalWindow {
  203. constructor(asset: ToolCore.Asset) {
  204. super();
  205. this.asset = asset;
  206. this.init("Rename Resource", "AtomicEditor/editor/ui/renameasset.tb.txt");
  207. var currentName = <Atomic.UITextField>this.getWidget("current_name");
  208. this.nameEdit = <Atomic.UIEditField>this.getWidget("new_name");
  209. currentName.text = asset.name;
  210. this.nameEdit.text = asset.name;
  211. this.resizeToFitContent();
  212. this.center();
  213. }
  214. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  215. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  216. var id = ev.target.id;
  217. if (id == "rename") {
  218. this.hide();
  219. if (this.asset.name != this.nameEdit.text) {
  220. let eventData = {
  221. path: this.asset.path,
  222. newPath: this.nameEdit.text,
  223. asset: this.asset
  224. };
  225. this.asset.rename(this.nameEdit.text);
  226. this.sendEvent(EditorEvents.RenameResourceNotification, eventData);
  227. }
  228. return true;
  229. }
  230. if (id == "cancel") {
  231. this.hide();
  232. return true;
  233. }
  234. }
  235. }
  236. nameEdit: Atomic.UIEditField;
  237. asset: ToolCore.Asset;
  238. }