The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
7.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class ModulesPanel : public Component,
  18. private TableListBoxModel,
  19. private ValueTree::Listener,
  20. private Button::Listener
  21. {
  22. public:
  23. ModulesPanel (Project& p)
  24. : project (p),
  25. modulesValueTree (p.getModules().state),
  26. setCopyModeButton ("Set copy-mode for all modules..."),
  27. copyPathButton ("Set paths for all modules...")
  28. {
  29. table.getHeader().addColumn ("Module", nameCol, 180, 100, 400, TableHeaderComponent::notSortable);
  30. table.getHeader().addColumn ("Version", versionCol, 100, 100, 100, TableHeaderComponent::notSortable);
  31. table.getHeader().addColumn ("Make Local Copy", copyCol, 100, 100, 100, TableHeaderComponent::notSortable);
  32. table.getHeader().addColumn ("Paths", pathCol, 250, 100, 600, TableHeaderComponent::notSortable);
  33. table.setModel (this);
  34. table.setColour (TableListBox::backgroundColourId, Colours::transparentBlack);
  35. addAndMakeVisible (table);
  36. table.updateContent();
  37. table.setRowHeight (20);
  38. addAndMakeVisible (setCopyModeButton);
  39. addAndMakeVisible (copyPathButton);
  40. setCopyModeButton.addListener (this);
  41. setCopyModeButton.setTriggeredOnMouseDown (true);
  42. copyPathButton.addListener (this);
  43. copyPathButton.setTriggeredOnMouseDown (true);
  44. modulesValueTree.addListener (this);
  45. lookAndFeelChanged();
  46. }
  47. void paint (Graphics& g) override
  48. {
  49. ProjucerLookAndFeel::fillWithBackgroundTexture (*this, g);
  50. }
  51. void resized() override
  52. {
  53. Rectangle<int> r (getLocalBounds().reduced (5, 4));
  54. table.setBounds (r.removeFromTop (table.getRowPosition (getNumRows() - 1, true).getBottom() + 20));
  55. Rectangle<int> buttonRow (r.removeFromTop (32).removeFromBottom (28));
  56. setCopyModeButton.setBounds (buttonRow.removeFromLeft (jmin (260, r.getWidth() / 3)));
  57. buttonRow.removeFromLeft (8);
  58. copyPathButton.setBounds (buttonRow.removeFromLeft (jmin (260, r.getWidth() / 3)));
  59. }
  60. int getNumRows() override
  61. {
  62. return project.getModules().getNumModules();
  63. }
  64. void paintRowBackground (Graphics& g, int /*rowNumber*/, int width, int height, bool rowIsSelected) override
  65. {
  66. g.setColour (rowIsSelected ? Colours::lightblue.withAlpha (0.4f)
  67. : Colours::white.withAlpha (0.4f));
  68. g.fillRect (0, 0, width, height - 1);
  69. }
  70. void paintCell (Graphics& g, int rowNumber, int columnId, int width, int height, bool /*rowIsSelected*/) override
  71. {
  72. String text;
  73. const String moduleID (project.getModules().getModuleID (rowNumber));
  74. if (columnId == nameCol)
  75. {
  76. text = moduleID;
  77. }
  78. else if (columnId == versionCol)
  79. {
  80. text = project.getModules().getModuleInfo (moduleID).getVersion();
  81. if (text.isEmpty())
  82. text = "?";
  83. }
  84. else if (columnId == copyCol)
  85. {
  86. text = project.getModules().shouldCopyModuleFilesLocally (moduleID).getValue()
  87. ? "Yes" : "No";
  88. }
  89. else if (columnId == pathCol)
  90. {
  91. StringArray paths;
  92. for (Project::ExporterIterator exporter (project); exporter.next();)
  93. paths.addIfNotAlreadyThere (exporter->getPathForModuleString (moduleID).trim());
  94. text = paths.joinIntoString (", ");
  95. }
  96. g.setColour (Colours::black);
  97. g.setFont (height * 0.65f);
  98. g.drawText (text, Rectangle<int> (width, height).reduced (4, 0), Justification::centredLeft, true);
  99. }
  100. void cellDoubleClicked (int rowNumber, int, const MouseEvent&) override
  101. {
  102. const String moduleID (project.getModules().getModuleID (rowNumber));
  103. if (moduleID.isNotEmpty())
  104. if (ProjectContentComponent* pcc = findParentComponentOfClass<ProjectContentComponent>())
  105. pcc->showModule (moduleID);
  106. }
  107. void deleteKeyPressed (int row) override
  108. {
  109. project.getModules().removeModule (project.getModules().getModuleID (row));
  110. }
  111. void buttonClicked (Button* b) override
  112. {
  113. if (b == &setCopyModeButton) showCopyModeMenu();
  114. if (b == &copyPathButton) showSetPathsMenu();
  115. }
  116. private:
  117. enum
  118. {
  119. nameCol = 1,
  120. versionCol,
  121. copyCol,
  122. pathCol
  123. };
  124. Project& project;
  125. ValueTree modulesValueTree;
  126. TableListBox table;
  127. TextButton setCopyModeButton, copyPathButton;
  128. void valueTreePropertyChanged (ValueTree&, const Identifier&) override { itemChanged(); }
  129. void valueTreeChildAdded (ValueTree&, ValueTree&) override { itemChanged(); }
  130. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override { itemChanged(); }
  131. void valueTreeChildOrderChanged (ValueTree&, int, int) override { itemChanged(); }
  132. void valueTreeParentChanged (ValueTree&) override { itemChanged(); }
  133. void itemChanged()
  134. {
  135. table.updateContent();
  136. resized();
  137. repaint();
  138. }
  139. void showCopyModeMenu()
  140. {
  141. PopupMenu m;
  142. m.addItem (1, "Set all modules to copy locally");
  143. m.addItem (2, "Set all modules to not copy locally");
  144. int res = m.showAt (&setCopyModeButton);
  145. if (res != 0)
  146. project.getModules().setLocalCopyModeForAllModules (res == 1);
  147. }
  148. void showSetPathsMenu()
  149. {
  150. EnabledModuleList& moduleList = project.getModules();
  151. const String moduleToCopy (moduleList.getModuleID (table.getSelectedRow()));
  152. if (moduleToCopy.isNotEmpty())
  153. {
  154. PopupMenu m;
  155. m.addItem (1, "Copy the paths from the module '" + moduleToCopy + "' to all other modules");
  156. int res = m.showAt (&copyPathButton);
  157. if (res != 0)
  158. {
  159. for (Project::ExporterIterator exporter (project); exporter.next();)
  160. {
  161. for (int i = 0; i < moduleList.getNumModules(); ++i)
  162. {
  163. String modID = moduleList.getModuleID (i);
  164. if (modID != moduleToCopy)
  165. exporter->getPathForModuleValue (modID) = exporter->getPathForModuleValue (moduleToCopy).getValue();
  166. }
  167. }
  168. }
  169. table.repaint();
  170. }
  171. else
  172. {
  173. PopupMenu m;
  174. m.addItem (1, "(Select a module in the list above to use this option)", false);
  175. m.showAt (&copyPathButton);
  176. }
  177. }
  178. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ModulesPanel)
  179. };