NewModuleDialog.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. function NewModuleDialog::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 = "EditorForm";
  10. extent = %width SPC %height;
  11. cellSizeX = %width;
  12. cellSizeY = 50;
  13. };
  14. %form.addListener(%this);
  15. %item = %form.addFormItem("Module Name", %width SPC 30);
  16. %this.moduleNameBox = %form.createTextEditItem(%item);
  17. %item = %form.addFormItem("Template", %width SPC 30);
  18. %this.templateDropDown = %form.createDropDownItem(%item);
  19. %this.populateModuleDropDown();
  20. %content.add(%form);
  21. %this.cancelButton = new GuiButtonCtrl()
  22. {
  23. HorizSizing = "right";
  24. VertSizing = "bottom";
  25. Position = "278 120";
  26. Extent = "100 30";
  27. Text = "Cancel";
  28. Command = %this.getID() @ ".onClose();";
  29. };
  30. ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
  31. %this.createButton = new GuiButtonCtrl()
  32. {
  33. HorizSizing = "right";
  34. VertSizing = "bottom";
  35. Position = "388 118";
  36. Extent = "100 34";
  37. Text = "Create";
  38. Command = %this.getID() @ ".onCreate();";
  39. };
  40. ThemeManager.setProfile(%this.createButton, "primaryButtonProfile");
  41. %content.add(%this.cancelButton);
  42. %content.add(%this.createButton);
  43. %this.validate();
  44. }
  45. function NewModuleDialog::populateModuleDropDown(%this)
  46. {
  47. %manager = new ModuleManager();
  48. %manager.EchoInfo = false;
  49. %manager.ScanModules(pathConcat(getMainDotCsDir(), "library"));
  50. %allModules = %manager.findModules(false);
  51. for(%i = 0; %i < getWordCount(%allModules); %i++)
  52. {
  53. %mod = getWord(%allModules, %i);
  54. if(%mod.type $= "template")
  55. {
  56. %this.templateDropDown.addItem(%mod.ModuleID);
  57. }
  58. }
  59. %this.templateDropDown.sortByText();
  60. %this.templateDropDown.insertItem(0, "none");
  61. %this.templateDropDown.setSelected(0);
  62. }
  63. function NewModuleDialog::onDropDownClosed(%this, %dropDown)
  64. {
  65. %this.validate();
  66. }
  67. function NewModuleDialog::onKeyPressed(%this, %textBox)
  68. {
  69. %this.validate();
  70. }
  71. function NewModuleDialog::onReturnPressed(%this, %textBox)
  72. {
  73. %this.onCreate();
  74. }
  75. function NewModuleDialog::Validate(%this)
  76. {
  77. %this.createButton.active = false;
  78. %module = %this.templateDropDown.getText();
  79. %name = %this.moduleNameBox.getText();
  80. %path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder(), %name);
  81. if(%name $= "" || isDirectory(%path))
  82. {
  83. return false;
  84. }
  85. %this.moduleNameBox.text = stripChars(%name, " ");
  86. %this.createButton.active = true;
  87. return true;
  88. }
  89. function NewModuleDialog::onClose(%this)
  90. {
  91. Canvas.popDialog(%this);
  92. %this.postEvent("DialogClosed", %this);
  93. }
  94. function NewModuleDialog::onCreate(%this)
  95. {
  96. if(%this.validate())
  97. {
  98. %module = %this.templateDropDown.getText();
  99. %name = %this.moduleNameBox.getText();
  100. %path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder(), %name);
  101. %data = new ScriptObject()
  102. {
  103. template = %module;
  104. moduleName = %name;
  105. path = %path;
  106. };
  107. %this.postEvent("ModuleCreated", %data);
  108. %data.delete();
  109. %this.onClose();
  110. }
  111. }