NewDependencyDialog.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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.feedback);
  43. %content.add(%this.cancelButton);
  44. %content.add(%this.createButton);
  45. %this.validate();
  46. }
  47. function NewDependencyDialog::populateModuleDropDown(%this)
  48. {
  49. %this.moduleDropDown.clearItems();
  50. for(%i = 0; %i < getWordCount(%this.dependList); %i++)
  51. {
  52. %mod = getWord(%this.dependList, %i);
  53. if(%mod.ModuleID !$= "AppCore")
  54. {
  55. if(%this.versionList[%mod.ModuleID] $= "")
  56. {
  57. %this.moduleDropDown.addItem(%mod.ModuleID);
  58. %this.versionList[%mod.ModuleID] = %mod.VersionID;
  59. }
  60. else
  61. {
  62. %this.versionList[%mod.ModuleID] = %this.versionList[%mod.ModuleID] SPC %mod.VersionID;
  63. }
  64. }
  65. }
  66. %this.moduleDropDown.sortByText();
  67. %this.moduleDropDown.insertItem(0, "");
  68. %this.moduleDropDown.setSelected(0);
  69. }
  70. function NewDependencyDialog::onDropDownClosed(%this, %dropDown)
  71. {
  72. %this.validate();
  73. }
  74. function NewDependencyDialog::onDropDownSelect(%this, %dropDown)
  75. {
  76. if(%dropDown == %this.moduleDropDown)
  77. {
  78. %this.populateVersionDropDown();
  79. }
  80. }
  81. function NewDependencyDialog::populateVersionDropDown(%this)
  82. {
  83. %this.versionDropDown.clearItems();
  84. if(%this.moduleDropDown.getText() !$= "")
  85. {
  86. %versionList = %this.versionList[%this.moduleDropDown.getText()];
  87. for(%i = 0; %i < getWordCount(%versionList); %i++)
  88. {
  89. %version = getWord(%versionList, %i);
  90. %this.versionDropDown.addItem(%version);
  91. }
  92. %this.versionDropDown.sortByText();
  93. %this.versionDropDown.insertItem(0, "Latest");
  94. %this.versionDropDown.setSelected(0);
  95. }
  96. }
  97. function NewDependencyDialog::Validate(%this)
  98. {
  99. %this.createButton.active = false;
  100. %module = %this.moduleDropDown.getText();
  101. if(%module $= "")
  102. {
  103. return false;
  104. }
  105. %this.createButton.active = true;
  106. return true;
  107. }
  108. function NewDependencyDialog::onClose(%this)
  109. {
  110. Canvas.popDialog(%this);
  111. %this.postEvent("DialogClosed", %this);
  112. }
  113. function NewDependencyDialog::onCreate(%this)
  114. {
  115. if(%this.validate())
  116. {
  117. %module = %this.moduleDropDown.getText();
  118. %version = %this.versionDropDown.getText();
  119. if(%version $= "Latest")
  120. {
  121. %version = "0";
  122. }
  123. %data = new ScriptObject()
  124. {
  125. module = %module;
  126. version = %version;
  127. };
  128. %this.postEvent("DependencyAdded", %data);
  129. %data.delete();
  130. %this.onClose();
  131. }
  132. }