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.

376 lines
15KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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 ModuleItem : public ConfigTreeItemBase
  18. {
  19. public:
  20. ModuleItem (Project& p, const String& modID)
  21. : project (p), moduleID (modID)
  22. {
  23. }
  24. bool canBeSelected() const override { return true; }
  25. bool mightContainSubItems() override { return false; }
  26. String getUniqueName() const override { return "module_" + moduleID; }
  27. String getDisplayName() const override { return moduleID; }
  28. String getRenamingName() const override { return getDisplayName(); }
  29. void setName (const String&) override {}
  30. bool isMissing() override { return hasMissingDependencies(); }
  31. Icon getIcon() const override { return Icon (getIcons().jigsaw, getContrastingColour (Colours::red, 0.5f)); }
  32. void showDocument() override { showSettingsPage (new ModuleSettingsPanel (project, moduleID)); }
  33. void deleteItem() override { project.getModules().removeModule (moduleID); }
  34. void showPopupMenu() override
  35. {
  36. PopupMenu menu;
  37. menu.addItem (1, "Remove this module");
  38. launchPopupMenu (menu);
  39. }
  40. void handlePopupMenuResult (int resultCode) override
  41. {
  42. if (resultCode == 1)
  43. deleteItem();
  44. }
  45. Project& project;
  46. String moduleID;
  47. private:
  48. bool hasMissingDependencies() const
  49. {
  50. return project.getModules().getExtraDependenciesNeeded (moduleID).size() > 0;
  51. }
  52. //==============================================================================
  53. class ModuleSettingsPanel : public Component
  54. {
  55. public:
  56. ModuleSettingsPanel (Project& p, const String& modID)
  57. : project (p), moduleID (modID)
  58. {
  59. addAndMakeVisible (group);
  60. group.setName ("Module: " + moduleID);
  61. refresh();
  62. }
  63. void refresh()
  64. {
  65. setEnabled (project.getModules().isModuleEnabled (moduleID));
  66. PropertyListBuilder props;
  67. props.add (new ModuleInfoComponent (project, moduleID));
  68. if (project.getModules().getExtraDependenciesNeeded (moduleID).size() > 0)
  69. props.add (new MissingDependenciesComponent (project, moduleID));
  70. for (Project::ExporterIterator exporter (project); exporter.next();)
  71. props.add (new TextPropertyComponent (exporter->getPathForModuleValue (moduleID),
  72. "Path for " + exporter->getName().quoted(), 1024, false),
  73. "A path to the folder that contains the " + moduleID + " module when compiling the "
  74. + exporter->getName().quoted() + " target. "
  75. "This can be an absolute path, or relative to the jucer project folder, but it "
  76. "must be valid on the filesystem of the target machine that will be performing this build.");
  77. props.add (new BooleanPropertyComponent (project.getModules().shouldCopyModuleFilesLocally (moduleID),
  78. "Create local copy", "Copy the module into the project folder"),
  79. "If this is enabled, then a local copy of the entire module will be made inside your project (in the auto-generated JuceLibraryFiles folder), "
  80. "so that your project will be self-contained, and won't need to contain any references to files in other folders. "
  81. "This also means that you can check the module into your source-control system to make sure it is always in sync with your own code.");
  82. props.add (new BooleanPropertyComponent (project.getModules().shouldShowAllModuleFilesInProject (moduleID),
  83. "Add source to project", "Make module files browsable in projects"),
  84. "If this is enabled, then the entire source tree from this module will be shown inside your project, "
  85. "making it easy to browse/edit the module's classes. If disabled, then only the minimum number of files "
  86. "required to compile it will appear inside your project.");
  87. StringArray possibleValues;
  88. possibleValues.add ("(Use Default)");
  89. possibleValues.add ("Enabled");
  90. possibleValues.add ("Disabled");
  91. Array<var> mappings;
  92. mappings.add (Project::configFlagDefault);
  93. mappings.add (Project::configFlagEnabled);
  94. mappings.add (Project::configFlagDisabled);
  95. ModuleDescription info (project.getModules().getModuleInfo (moduleID));
  96. if (info.isValid())
  97. {
  98. OwnedArray <Project::ConfigFlag> configFlags;
  99. LibraryModule (info).getConfigFlags (project, configFlags);
  100. for (int i = 0; i < configFlags.size(); ++i)
  101. {
  102. ChoicePropertyComponent* c = new ChoicePropertyComponent (configFlags[i]->value,
  103. configFlags[i]->symbol,
  104. possibleValues, mappings);
  105. c->setTooltip (configFlags[i]->description);
  106. props.add (c);
  107. }
  108. }
  109. group.setProperties (props);
  110. parentSizeChanged();
  111. }
  112. void parentSizeChanged() override { updateSize (*this, group); }
  113. private:
  114. PropertyGroupComponent group;
  115. Project& project;
  116. String moduleID;
  117. //==============================================================================
  118. class ModuleInfoComponent : public PropertyComponent
  119. {
  120. public:
  121. ModuleInfoComponent (Project& p, const String& modID)
  122. : PropertyComponent ("Module", 150), project (p), moduleID (modID)
  123. {
  124. }
  125. void refresh() {}
  126. void paint (Graphics& g)
  127. {
  128. g.setColour (Colours::white.withAlpha (0.4f));
  129. g.fillRect (0, 0, getWidth(), getHeight() - 1);
  130. AttributedString s;
  131. s.setJustification (Justification::topLeft);
  132. Font f (14.0f);
  133. ModuleDescription info (project.getModules().getModuleInfo (moduleID));
  134. if (info.isValid())
  135. {
  136. s.append (info.getName() + "\n\n", f.boldened());
  137. s.append ("Version: " + info.getVersion()
  138. + "\nLicense: " + info.getLicense() + "\n", f.italicised());
  139. s.append ("\n" + info.getDescription(), f);
  140. }
  141. else
  142. {
  143. s.append ("Cannot find this module at the specified path!", f.boldened());
  144. s.setColour (Colours::darkred);
  145. }
  146. s.draw (g, getLocalBounds().reduced (6, 5).toFloat());
  147. }
  148. private:
  149. Project& project;
  150. String moduleID;
  151. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ModuleInfoComponent)
  152. };
  153. //==============================================================================
  154. class MissingDependenciesComponent : public PropertyComponent,
  155. public ButtonListener
  156. {
  157. public:
  158. MissingDependenciesComponent (Project& p, const String& modID)
  159. : PropertyComponent ("Dependencies", 100),
  160. project (p), moduleID (modID),
  161. missingDependencies (project.getModules().getExtraDependenciesNeeded (modID)),
  162. fixButton ("Add Required Modules")
  163. {
  164. addAndMakeVisible (fixButton);
  165. fixButton.setColour (TextButton::buttonColourId, Colours::red);
  166. fixButton.setColour (TextButton::textColourOffId, Colours::white);
  167. fixButton.addListener (this);
  168. }
  169. void refresh() {}
  170. void paint (Graphics& g)
  171. {
  172. g.setColour (Colours::white.withAlpha (0.4f));
  173. g.fillRect (0, 0, getWidth(), getHeight() - 1);
  174. String text ("This module has missing dependencies!\n\n"
  175. "To build correctly, it requires the following modules to be added:\n");
  176. text << missingDependencies.joinIntoString (", ");
  177. AttributedString s;
  178. s.setJustification (Justification::topLeft);
  179. s.append (text, Font (13.0f), Colours::red.darker());
  180. s.draw (g, getLocalBounds().reduced (4, 16).toFloat());
  181. }
  182. void buttonClicked (Button*)
  183. {
  184. bool anyFailed = false;
  185. ModuleList list;
  186. list.scanAllKnownFolders (project);
  187. for (int i = missingDependencies.size(); --i >= 0;)
  188. {
  189. if (const ModuleDescription* info = list.getModuleWithID (missingDependencies[i]))
  190. project.getModules().addModule (info->manifestFile, project.getModules().areMostModulesCopiedLocally());
  191. else
  192. anyFailed = true;
  193. }
  194. if (ModuleSettingsPanel* p = findParentComponentOfClass<ModuleSettingsPanel>())
  195. p->refresh();
  196. if (anyFailed)
  197. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  198. "Adding Missing Dependencies",
  199. "Couldn't locate some of these modules - you'll need to find their "
  200. "folders manually and add them to the list.");
  201. }
  202. void resized()
  203. {
  204. fixButton.setBounds (getWidth() - 168, getHeight() - 26, 160, 22);
  205. }
  206. private:
  207. Project& project;
  208. String moduleID;
  209. StringArray missingDependencies;
  210. TextButton fixButton;
  211. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MissingDependenciesComponent)
  212. };
  213. };
  214. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ModuleItem)
  215. };
  216. //==============================================================================
  217. class EnabledModulesItem : public ConfigTreeItemBase
  218. {
  219. public:
  220. EnabledModulesItem (Project& p)
  221. : project (p),
  222. moduleListTree (p.getModules().state)
  223. {
  224. moduleListTree.addListener (this);
  225. }
  226. bool isModulesList() const override { return true; }
  227. bool canBeSelected() const override { return true; }
  228. bool mightContainSubItems() override { return true; }
  229. String getUniqueName() const override { return "modules"; }
  230. String getRenamingName() const override { return getDisplayName(); }
  231. String getDisplayName() const override { return "Modules"; }
  232. void setName (const String&) override {}
  233. bool isMissing() override { return false; }
  234. Icon getIcon() const override { return Icon (getIcons().graph, getContrastingColour (Colours::red, 0.5f)); }
  235. void showDocument()
  236. {
  237. if (ProjectContentComponent* pcc = getProjectContentComponent())
  238. pcc->setEditorComponent (new ModulesPanel (project), nullptr);
  239. }
  240. bool isInterestedInFileDrag (const StringArray& files) override
  241. {
  242. for (int i = files.size(); --i >= 0;)
  243. if (ModuleDescription (File (files[i]).getChildFile (ModuleDescription::getManifestFileName())).isValid())
  244. return true;
  245. return false;
  246. }
  247. void filesDropped (const StringArray& files, int /*insertIndex*/) override
  248. {
  249. Array<ModuleDescription> modules;
  250. for (int i = files.size(); --i >= 0;)
  251. {
  252. ModuleDescription m (File (files[i]).getChildFile (ModuleDescription::getManifestFileName()));
  253. if (m.isValid())
  254. modules.add (m);
  255. }
  256. for (int i = 0; i < modules.size(); ++i)
  257. project.getModules().addModule (modules.getReference(i).manifestFile,
  258. project.getModules().areMostModulesCopiedLocally());
  259. }
  260. void addSubItems() override
  261. {
  262. for (int i = 0; i < project.getModules().getNumModules(); ++i)
  263. addSubItem (new ModuleItem (project, project.getModules().getModuleID (i)));
  264. }
  265. void showPopupMenu() override
  266. {
  267. PopupMenu menu, knownModules, copyModeMenu;
  268. const StringArray modules (getAvailableModules());
  269. for (int i = 0; i < modules.size(); ++i)
  270. knownModules.addItem (1 + i, modules[i], ! project.getModules().isModuleEnabled (modules[i]));
  271. menu.addSubMenu ("Add a module", knownModules);
  272. menu.addSeparator();
  273. menu.addItem (1001, "Add a module from a specified folder...");
  274. launchPopupMenu (menu);
  275. }
  276. void handlePopupMenuResult (int resultCode) override
  277. {
  278. if (resultCode == 1001)
  279. project.getModules().addModuleFromUserSelectedFile();
  280. else if (resultCode > 0)
  281. project.getModules().addModuleInteractive (getAvailableModules() [resultCode - 1]);
  282. }
  283. StringArray getAvailableModules()
  284. {
  285. ModuleList list;
  286. list.scanAllKnownFolders (project);
  287. return list.getIDs();
  288. }
  289. //==============================================================================
  290. void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
  291. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
  292. void valueTreeChildOrderChanged (ValueTree& parentTree) override { refreshIfNeeded (parentTree); }
  293. void refreshIfNeeded (ValueTree& changedTree)
  294. {
  295. if (changedTree == moduleListTree)
  296. refreshSubItems();
  297. }
  298. private:
  299. Project& project;
  300. ValueTree moduleListTree;
  301. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EnabledModulesItem)
  302. };