UIResourceOps.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import EditorEvents = require("editor/EditorEvents");
  2. import EditorUI = require("../EditorUI");
  3. import ModalWindow = require("./ModalWindow");
  4. import ResourceOps = require("resources/ResourceOps");
  5. export class ResourceDelete extends ModalWindow {
  6. constructor(asset: ToolCore.Asset) {
  7. super();
  8. this.asset = asset;
  9. this.init("Delete Resource", "AtomicEditor/editor/ui/resourcedelete.tb.txt");
  10. var message = <Atomic.UIEditField> this.getWidget("message");
  11. var text = "Are you sure you want to delete resource:\n\n";
  12. text += asset.path;
  13. text += "\n\nThis operation cannot be undone";
  14. message.text = text;
  15. this.resizeToFitContent();
  16. this.center();
  17. }
  18. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  19. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  20. var id = ev.target.id;
  21. if (id == "delete") {
  22. this.hide();
  23. var db = ToolCore.getAssetDatabase();
  24. db.deleteAsset(this.asset);
  25. return true;
  26. }
  27. if (id == "cancel") {
  28. this.hide();
  29. return true;
  30. }
  31. }
  32. }
  33. asset: ToolCore.Asset;
  34. }
  35. export class CreateFolder extends ModalWindow {
  36. constructor(resourcePath: string) {
  37. super();
  38. this.resourcePath = resourcePath;
  39. this.init("New Folder", "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
  40. this.nameField = <Atomic.UIEditField> this.getWidget("folder_name");
  41. }
  42. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  43. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  44. var id = ev.target.id;
  45. if (id == "create") {
  46. var resourcePath = Atomic.addTrailingSlash(this.resourcePath) + this.nameField.text;
  47. if (ResourceOps.CreateNewFolder(resourcePath)) {
  48. this.hide();
  49. }
  50. return true;
  51. }
  52. if (id == "cancel") {
  53. this.hide();
  54. return true;
  55. }
  56. }
  57. }
  58. resourcePath: string;
  59. nameField: Atomic.UIEditField;
  60. }
  61. export class CreateComponent extends ModalWindow {
  62. constructor(resourcePath: string) {
  63. super();
  64. this.resourcePath = resourcePath;
  65. this.init("New Component", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  66. this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
  67. }
  68. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  69. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  70. var id = ev.target.id;
  71. if (id == "create") {
  72. var componentName = this.nameField.text;
  73. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + componentName;
  74. if (outputFile.indexOf(".js") == -1) outputFile += ".js";
  75. if (ResourceOps.CreateNewComponent(outputFile, componentName)) {
  76. this.hide();
  77. this.sendEvent(EditorEvents.EditResource, { path:outputFile});
  78. }
  79. return true;
  80. }
  81. if (id == "cancel") {
  82. this.hide();
  83. return true;
  84. }
  85. }
  86. }
  87. resourcePath: string;
  88. nameField: Atomic.UIEditField;
  89. }
  90. export class CreateScript extends ModalWindow {
  91. constructor(resourcePath: string) {
  92. super();
  93. this.resourcePath = resourcePath;
  94. this.init("New Script", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  95. this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
  96. }
  97. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  98. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  99. var id = ev.target.id;
  100. if (id == "create") {
  101. var scriptName = this.nameField.text;
  102. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + scriptName;
  103. if (outputFile.indexOf(".js") == -1) outputFile += ".js";
  104. if (ResourceOps.CreateNewScript(outputFile, scriptName)) {
  105. this.hide();
  106. this.sendEvent(EditorEvents.EditResource, { path:outputFile});
  107. }
  108. return true;
  109. }
  110. if (id == "cancel") {
  111. this.hide();
  112. return true;
  113. }
  114. }
  115. }
  116. resourcePath: string;
  117. nameField: Atomic.UIEditField;
  118. }
  119. export class CreateScene extends ModalWindow {
  120. constructor(resourcePath: string) {
  121. super();
  122. this.resourcePath = resourcePath;
  123. this.init("New Scene", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  124. this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
  125. }
  126. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  127. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  128. var id = ev.target.id;
  129. if (id == "create") {
  130. var sceneName = this.nameField.text;
  131. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + sceneName;
  132. if (outputFile.indexOf(".scene") == -1) outputFile += ".scene";
  133. if (ResourceOps.CreateNewScene(outputFile, sceneName)) {
  134. this.hide();
  135. this.sendEvent(EditorEvents.EditResource, { path:outputFile});
  136. }
  137. return true;
  138. }
  139. if (id == "cancel") {
  140. this.hide();
  141. return true;
  142. }
  143. }
  144. }
  145. resourcePath: string;
  146. nameField: Atomic.UIEditField;
  147. }
  148. export class CreateMaterial extends ModalWindow {
  149. constructor(resourcePath: string) {
  150. super();
  151. this.resourcePath = resourcePath;
  152. this.init("New Material", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  153. this.nameField = <Atomic.UIEditField> this.getWidget("component_name");
  154. }
  155. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  156. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  157. var id = ev.target.id;
  158. if (id == "create") {
  159. var materialName = this.nameField.text;
  160. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + materialName;
  161. if (outputFile.indexOf(".material") == -1) outputFile += ".material";
  162. if (ResourceOps.CreateNewMaterial(outputFile, materialName)) {
  163. this.hide();
  164. this.sendEvent(EditorEvents.EditResource, { path:outputFile});
  165. }
  166. return true;
  167. }
  168. if (id == "cancel") {
  169. this.hide();
  170. return true;
  171. }
  172. }
  173. }
  174. resourcePath: string;
  175. nameField: Atomic.UIEditField;
  176. }