ProjectModuleDependList.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. function ProjectModuleDependList::onAdd(%this)
  2. {
  3. %this.startListening(ThemeManager);
  4. }
  5. function ProjectModuleDependList::onThemeChange(%this, %theme)
  6. {
  7. if(isObject(%this.activeModule))
  8. {
  9. %this.show(%this.activeModule);
  10. }
  11. }
  12. function ProjectModuleDependList::show(%this, %module)
  13. {
  14. %this.activeModule = %module;
  15. %this.clearItems();
  16. %isSynced = %module.Synchronized;
  17. for(%i = 0; %i < %module.getdependencyCount(); %i++)
  18. {
  19. %dep = %module.getDependency(%i);
  20. %name = getWord(%dep, 0);
  21. %version = getWord(%dep, 1);
  22. if(%version $= "*" || %version $= "0")
  23. {
  24. %version = "Latest";
  25. }
  26. %this.addDependItem(%name, %version, %isSynced);
  27. }
  28. if(!%module.Synchronized)
  29. {
  30. %this.addAddButton();
  31. }
  32. }
  33. function ProjectModuleDependList::hide(%this)
  34. {
  35. %this.activeModule = 0;
  36. %this.clearItems();
  37. }
  38. function ProjectModuleDependList::clearItems(%this)
  39. {
  40. for(%i = %this.getCount() - 1; %i >= 0; %i--)
  41. {
  42. %item = %this.getObject(%i);
  43. %item.delete();
  44. }
  45. }
  46. function ProjectModuleDependList::addDependItem(%this, %name, %version, %isSynced)
  47. {
  48. %width = getWord(%this.extent, 0) - 6;
  49. %text = new GuiControl()
  50. {
  51. HorizSizing="width";
  52. Position = "3 0";
  53. Extent = %width SPC "26";
  54. Text = %name @ ":" @ %version;
  55. Align = "Left";
  56. VAlign = "Middle";
  57. };
  58. ThemeManager.setProfile(%text, "subListProfile");
  59. %this.add(%text);
  60. if(!%isSynced)
  61. {
  62. %deleteButton = new GuiButtonCtrl()
  63. {
  64. Class="ProjectModuleDependButton";
  65. ButtonEvent = "RemoveDepend";
  66. ButtonData = %name;
  67. HorizSizing="left";
  68. Position = (%width - 40) SPC "0";
  69. Extent = "22 22";
  70. MinExtent = "22 22";
  71. Text = "X";
  72. Align = "Center";
  73. VAlign = "Middle";
  74. TextExtend = 1;
  75. };
  76. %deleteButton.position = (%width - (getWord(%deleteButton.extent, 0) + 10)) SPC "0";
  77. ThemeManager.setProfile(%deleteButton, "subListProfile");
  78. %text.add(%deleteButton);
  79. %this.startListening(%deleteButton);
  80. }
  81. }
  82. function ProjectModuleDependList::addAddButton(%this)
  83. {
  84. %this.dependList = %this.buildPossibleDependList();
  85. %width = 140;
  86. %addButton = new GuiButtonCtrl()
  87. {
  88. Class="ProjectModuleDependButton";
  89. ButtonEvent = "AddDepend";
  90. ButtonData = "";
  91. HorizSizing="right";
  92. Position = "3 0";
  93. Extent = %width SPC "26";
  94. MinExtent = %width SPC "26";
  95. Text = "+Add Dependency";
  96. Align = "Center";
  97. VAlign = "Middle";
  98. TextExtend = 1;
  99. Active = (getWordCount(%this.dependList) > 0);
  100. };
  101. ThemeManager.setProfile(%addButton, "subListProfile");
  102. %this.add(%addButton);
  103. %this.startListening(%addButton);
  104. }
  105. function ProjectModuleDependButton::onClick(%this)
  106. {
  107. %this.postEvent(%this.buttonEvent, %this.buttonData);
  108. }
  109. function ProjectModuleDependList::onAddDepend(%this)
  110. {
  111. %width = 500;
  112. %height = 190;
  113. %dialog = new GuiControl()
  114. {
  115. class = "NewDependencyDialog";
  116. superclass = "EditorDialog";
  117. dialogSize = (%width + 8) SPC (%height + 8);
  118. dialogCanClose = true;
  119. dialogText = "New Dependency";
  120. dependList = %this.dependList;
  121. };
  122. %dialog.init(%width, %height);
  123. %this.startListening(%dialog);
  124. Canvas.pushDialog(%dialog);
  125. }
  126. function ProjectModuleDependList::onDependencyAdded(%this, %data)
  127. {
  128. %this.activeModule.addDependency(%data.module, %data.version);
  129. %this.activeModule.save();
  130. %this.show(%this.activeModule);
  131. }
  132. function ProjectModuleDependList::onRemoveDepend(%this, %data)
  133. {
  134. %this.activeModule.removeDependency(%data);
  135. %this.activeModule.save();
  136. %this.schedule(50, "show", %this.activeModule);
  137. }
  138. function ProjectModuleDependList::onDialogClosed(%this, %dialog)
  139. {
  140. %this.dialog = %dialog;
  141. %this.schedule(100, "deleteDialog");
  142. }
  143. function ProjectModuleDependList::deleteDialog(%this)
  144. {
  145. %this.dialog.delete();
  146. }
  147. function ProjectModuleDependList::buildPossibleDependList(%this)
  148. {
  149. %allModules = ModuleDatabase.findModules(false);
  150. %list = "";
  151. for(%i = 0; %i < getWordCount(%allModules); %i++)
  152. {
  153. %mod = getWord(%allModules, %i);
  154. if(%mod.ModuleID !$= "AppCore" && %mod.ModuleID !$= %this.activeModule.ModuleID)
  155. {
  156. %hasDep = false;
  157. for(%j = 0; %j < %this.activeModule.getdependencyCount(); %j++)
  158. {
  159. %dep = %this.activeModule.getDependency(%j);
  160. if(getWord(%dep, 0) $= %mod.ModuleID)
  161. {
  162. %hasDep = true;
  163. }
  164. }
  165. if(!%hasDep)
  166. {
  167. %list = %list SPC %mod;
  168. }
  169. }
  170. }
  171. return trim(%list);
  172. }