ProjectModuleDependList.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. %width = 140;
  85. %addButton = new GuiButtonCtrl()
  86. {
  87. Class="ProjectModuleDependButton";
  88. ButtonEvent = "AddDepend";
  89. ButtonData = "";
  90. HorizSizing="right";
  91. Position = "3 0";
  92. Extent = %width SPC "26";
  93. MinExtent = %width SPC "26";
  94. Text = "+Add Dependency";
  95. Align = "Center";
  96. VAlign = "Middle";
  97. TextExtend = 1;
  98. };
  99. ThemeManager.setProfile(%addButton, "subListProfile");
  100. %this.add(%addButton);
  101. %this.startListening(%addButton);
  102. }
  103. function ProjectModuleDependButton::onClick(%this)
  104. {
  105. %this.postEvent(%this.buttonEvent, %this.buttonData);
  106. }
  107. function ProjectModuleDependList::onAddDepend(%this)
  108. {
  109. %width = 500;
  110. %height = 190;
  111. %dialog = new GuiControl()
  112. {
  113. class = "NewDependencyDialog";
  114. superclass = "EditorDialog";
  115. dialogSize = (%width + 8) SPC (%height + 8);
  116. dialogCanClose = true;
  117. dialogText = "New Dependency";
  118. };
  119. %dialog.init(%width, %height);
  120. %this.startListening(%dialog);
  121. Canvas.pushDialog(%dialog);
  122. }
  123. function ProjectModuleDependList::onDependencyAdded(%this, %data)
  124. {
  125. %this.activeModule.addDependency(%data.module, %data.version);
  126. %this.activeModule.save();
  127. %this.show(%this.activeModule);
  128. }
  129. function ProjectModuleDependList::onRemoveDepend(%this, %data)
  130. {
  131. %this.activeModule.removeDependency(%data);
  132. %this.activeModule.save();
  133. %this.schedule(50, "show", %this.activeModule);
  134. }
  135. function ProjectModuleDependList::onDialogClosed(%this, %dialog)
  136. {
  137. %this.dialog = %dialog;
  138. %this.schedule(100, "deleteDialog");
  139. }
  140. function ProjectModuleDependList::deleteDialog(%this)
  141. {
  142. %this.dialog.delete();
  143. }