NewDependencyDialog.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. function NewDependencyDialog::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("Dependency", %width SPC 30);
  16. %this.moduleDropDown = %form.createDropDownItem(%item);
  17. %item = %form.addFormItem("Version", %width SPC 30);
  18. %this.versionDropDown = %form.createDropDownItem(%item);
  19. %this.populateModuleDropDown();
  20. %this.populateVersionDropDown();
  21. %content.add(%form);
  22. %this.cancelButton = new GuiButtonCtrl()
  23. {
  24. HorizSizing = "right";
  25. VertSizing = "bottom";
  26. Position = "278 120";
  27. Extent = "100 30";
  28. Text = "Cancel";
  29. Command = %this.getID() @ ".onClose();";
  30. };
  31. ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
  32. %this.createButton = new GuiButtonCtrl()
  33. {
  34. HorizSizing = "right";
  35. VertSizing = "bottom";
  36. Position = "388 118";
  37. Extent = "100 34";
  38. Text = "Add";
  39. Command = %this.getID() @ ".onCreate();";
  40. };
  41. ThemeManager.setProfile(%this.createButton, "primaryButtonProfile");
  42. %content.add(%this.cancelButton);
  43. %content.add(%this.createButton);
  44. %this.validate();
  45. }
  46. function NewDependencyDialog::populateModuleDropDown(%this)
  47. {
  48. %this.moduleDropDown.clearItems();
  49. for(%i = 0; %i < getWordCount(%this.dependList); %i++)
  50. {
  51. %mod = getWord(%this.dependList, %i);
  52. if(%mod.ModuleID !$= "AppCore")
  53. {
  54. if(%this.versionList[%mod.ModuleID] $= "")
  55. {
  56. %this.moduleDropDown.addItem(%mod.ModuleID);
  57. %this.versionList[%mod.ModuleID] = %mod.VersionID;
  58. }
  59. else
  60. {
  61. %this.versionList[%mod.ModuleID] = %this.versionList[%mod.ModuleID] SPC %mod.VersionID;
  62. }
  63. }
  64. }
  65. %this.moduleDropDown.sortByText();
  66. %this.moduleDropDown.insertItem(0, "");
  67. %this.moduleDropDown.setSelected(0);
  68. }
  69. function NewDependencyDialog::onDropDownClosed(%this, %dropDown)
  70. {
  71. %this.validate();
  72. }
  73. function NewDependencyDialog::onDropDownSelect(%this, %dropDown)
  74. {
  75. if(%dropDown == %this.moduleDropDown)
  76. {
  77. %this.populateVersionDropDown();
  78. }
  79. }
  80. function NewDependencyDialog::populateVersionDropDown(%this)
  81. {
  82. %this.versionDropDown.clearItems();
  83. if(%this.moduleDropDown.getText() !$= "")
  84. {
  85. %versionList = %this.versionList[%this.moduleDropDown.getText()];
  86. for(%i = 0; %i < getWordCount(%versionList); %i++)
  87. {
  88. %version = getWord(%versionList, %i);
  89. %this.versionDropDown.addItem(%version);
  90. }
  91. %this.versionDropDown.sortByText();
  92. %this.versionDropDown.insertItem(0, "Latest");
  93. %this.versionDropDown.setSelected(0);
  94. }
  95. }
  96. function NewDependencyDialog::Validate(%this)
  97. {
  98. %this.createButton.active = false;
  99. %module = %this.moduleDropDown.getText();
  100. if(%module $= "")
  101. {
  102. return false;
  103. }
  104. %this.createButton.active = true;
  105. return true;
  106. }
  107. function NewDependencyDialog::onClose(%this)
  108. {
  109. Canvas.popDialog(%this);
  110. %this.postEvent("DialogClosed", %this);
  111. }
  112. function NewDependencyDialog::onCreate(%this)
  113. {
  114. if(%this.validate())
  115. {
  116. %module = %this.moduleDropDown.getText();
  117. %version = %this.versionDropDown.getText();
  118. if(%version $= "Latest")
  119. {
  120. %version = "0";
  121. }
  122. %data = new ScriptObject()
  123. {
  124. module = %module;
  125. version = %version;
  126. };
  127. %this.postEvent("DependencyAdded", %data);
  128. %data.delete();
  129. %this.onClose();
  130. }
  131. }