NewDeclaredAssetDialog.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. function NewDeclaredAssetDialog::init(%this, %width, %height)
  2. {
  3. //Get the dialog contents
  4. %window = %this.getObject(0);
  5. %content = %window.getObject(0);
  6. //Create the file text box
  7. %form = new GuiGridCtrl()
  8. {
  9. class = "DeclaredAssetForm";
  10. superclass = "EditorForm";
  11. extent = %width SPC %height;
  12. cellSizeX = %width;
  13. cellSizeY = 50;
  14. module = %this.module;
  15. };
  16. %form.addListener(%this);
  17. %item = %form.addFormItem("Asset Directory", %width SPC 30);
  18. %this.folderBox = %form.createFolderOpenItem(%item, "Select Folder to Scan");
  19. %this.folderBox.Command = %this.getId() @ ".Validate();";
  20. %item = %form.addFormItem("Extension", %width SPC 30);
  21. %this.extensionBox = %form.createTextEditItem(%item);
  22. %this.extensionBox.text = "asset.taml";
  23. %item = %form.addFormItem("Scan Sub Directories", %width SPC 30);
  24. %this.recursiveCheckBox = %form.createCheckboxItem(%item);
  25. %content.add(%form);
  26. %this.cancelButton = new GuiButtonCtrl()
  27. {
  28. HorizSizing = "right";
  29. VertSizing = "bottom";
  30. Position = "278 170";
  31. Extent = "100 30";
  32. Text = "Cancel";
  33. Command = %this.getID() @ ".onClose();";
  34. };
  35. ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
  36. %this.createButton = new GuiButtonCtrl()
  37. {
  38. HorizSizing = "right";
  39. VertSizing = "bottom";
  40. Position = "388 168";
  41. Extent = "100 34";
  42. Text = "Add";
  43. Command = %this.getID() @ ".onCreate();";
  44. };
  45. ThemeManager.setProfile(%this.createButton, "primaryButtonProfile");
  46. %content.add(%this.cancelButton);
  47. %content.add(%this.createButton);
  48. %this.validate();
  49. }
  50. function NewDeclaredAssetDialog::onFolderOpened(%this, %textBox)
  51. {
  52. %this.Validate();
  53. }
  54. function NewDeclaredAssetDialog::onKeyPressed(%this, %textBox)
  55. {
  56. %this.validate();
  57. }
  58. function NewDeclaredAssetDialog::onReturnPressed(%this, %textBox)
  59. {
  60. %this.onCreate();
  61. }
  62. function NewDeclaredAssetDialog::Validate(%this)
  63. {
  64. %this.createButton.active = false;
  65. %folder = %this.folderBox.getText();
  66. %ext = %this.extensionBox.getText();
  67. %isRecursive = %this.recursiveCheckBox.getStateOn();
  68. if(%ext $= "")
  69. {
  70. return false;
  71. }
  72. %this.createButton.active = true;
  73. return true;
  74. }
  75. function NewDeclaredAssetDialog::onClose(%this)
  76. {
  77. Canvas.popDialog(%this);
  78. %this.postEvent("DialogClosed", %this);
  79. }
  80. function NewDeclaredAssetDialog::onCreate(%this)
  81. {
  82. if(%this.validate())
  83. {
  84. %folder = %this.folderBox.getText();
  85. %ext = %this.extensionBox.getText();
  86. %isRecursive = %this.recursiveCheckBox.getStateOn();
  87. %asset = new DeclaredAssets()
  88. {
  89. path = %folder;
  90. extension = %ext;
  91. recurse = %isRecursive;
  92. };
  93. %this.postEvent("DeclaredAssetAdded", %asset);
  94. %this.onClose();
  95. }
  96. }