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.

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