UIResourceOps.ts 8.9 KB

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