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.

1075 lines
40KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../Project Saving/jucer_ProjectExporter.h"
  19. #include "jucer_Module.h"
  20. #include "../Application/jucer_JuceUpdater.h"
  21. #include "../Project/jucer_ProjectContentComponent.h"
  22. #include "jucer_ProjectInformationComponent.h"
  23. //==============================================================================
  24. class ModulesPanel : public PropertyComponent,
  25. public FilenameComponentListener,
  26. public ButtonListener
  27. {
  28. public:
  29. ModulesPanel (Project& project_)
  30. : PropertyComponent ("Modules", 500),
  31. project (project_),
  32. modulesLocation ("modules", ModuleList::getLocalModulesFolder (&project),
  33. true, true, false, "*", String::empty,
  34. "Select a folder containing your JUCE modules..."),
  35. modulesLabel (String::empty, "Module source folder:"),
  36. updateModulesButton ("Check for module updates..."),
  37. moduleListBox (moduleList),
  38. copyingMessage (project_, moduleList)
  39. {
  40. moduleList.rescan (ModuleList::getLocalModulesFolder (&project));
  41. addAndMakeVisible (&modulesLocation);
  42. modulesLocation.setBounds ("150, 3, parent.width - 180, 28");
  43. modulesLocation.addListener (this);
  44. modulesLabel.attachToComponent (&modulesLocation, true);
  45. addAndMakeVisible (&updateModulesButton);
  46. updateModulesButton.setBounds ("parent.width - 175, 3, parent.width - 4, 28");
  47. updateModulesButton.addListener (this);
  48. moduleListBox.setOwner (this);
  49. addAndMakeVisible (&moduleListBox);
  50. moduleListBox.setBounds ("4, 31, parent.width / 2 - 4, parent.height - 32");
  51. addAndMakeVisible (&copyingMessage);
  52. copyingMessage.setBounds ("4, parent.height - 30, parent.width - 4, parent.height - 1");
  53. copyingMessage.refresh();
  54. }
  55. void filenameComponentChanged (FilenameComponent*)
  56. {
  57. moduleList.rescan (modulesLocation.getCurrentFile());
  58. modulesLocation.setCurrentFile (moduleList.getModulesFolder(), false, false);
  59. ModuleList::setLocalModulesFolder (moduleList.getModulesFolder());
  60. moduleListBox.refresh();
  61. }
  62. void buttonClicked (Button*)
  63. {
  64. JuceUpdater::show (moduleList, getTopLevelComponent(), "");
  65. filenameComponentChanged (nullptr);
  66. }
  67. bool isEnabled (const ModuleList::Module* m) const
  68. {
  69. return project.isModuleEnabled (m->uid);
  70. }
  71. void setEnabled (const ModuleList::Module* m, bool enable)
  72. {
  73. if (enable)
  74. project.addModule (m->uid, true);
  75. else
  76. project.removeModule (m->uid);
  77. refresh();
  78. }
  79. bool areDependenciesMissing (const ModuleList::Module* m)
  80. {
  81. return moduleList.getExtraDependenciesNeeded (project, *m).size() > 0;
  82. }
  83. void selectionChanged (const ModuleList::Module* selectedModule)
  84. {
  85. settings = nullptr;
  86. if (selectedModule != nullptr)
  87. {
  88. addAndMakeVisible (settings = new ModuleSettingsPanel (project, moduleList, selectedModule->uid));
  89. settings->setBounds ("parent.width / 2 + 1, 31, parent.width - 3, parent.height - 32");
  90. }
  91. copyingMessage.refresh();
  92. }
  93. void refresh()
  94. {
  95. moduleListBox.refresh();
  96. if (settings != nullptr)
  97. settings->refreshAll();
  98. copyingMessage.refresh();
  99. }
  100. void paint (Graphics& g) // (overridden to avoid drawing the name)
  101. {
  102. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  103. }
  104. //==============================================================================
  105. class ModuleSelectionListBox : public ListBox,
  106. public ListBoxModel
  107. {
  108. public:
  109. ModuleSelectionListBox (ModuleList& list_)
  110. : list (list_), owner (nullptr)
  111. {
  112. setColour (ListBox::backgroundColourId, Colours::white.withAlpha (0.4f));
  113. setTooltip ("Use this list to select which modules should be included in your app.\n"
  114. "Any modules which have missing dependencies will be shown in red.");
  115. }
  116. void setOwner (ModulesPanel* owner_)
  117. {
  118. owner = owner_;
  119. setModel (this);
  120. }
  121. void refresh()
  122. {
  123. updateContent();
  124. repaint();
  125. }
  126. int getNumRows()
  127. {
  128. return list.modules.size();
  129. }
  130. void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  131. {
  132. if (rowIsSelected)
  133. g.fillAll (findColour (TextEditor::highlightColourId));
  134. const ModuleList::Module* const m = list.modules [rowNumber];
  135. if (m != nullptr)
  136. {
  137. const float tickSize = height * 0.7f;
  138. getLookAndFeel().drawTickBox (g, *this, (height - tickSize) / 2, (height - tickSize) / 2, tickSize, tickSize,
  139. owner->isEnabled (m), true, false, false);
  140. if (owner->isEnabled (m) && owner->areDependenciesMissing (m))
  141. g.setColour (Colours::red);
  142. else
  143. g.setColour (Colours::black);
  144. g.setFont (Font (height * 0.7f, Font::bold));
  145. g.drawFittedText (m->uid, height, 0, 200, height, Justification::centredLeft, 1);
  146. g.setFont (Font (height * 0.55f, Font::italic));
  147. g.drawText (m->name, height + 200, 0, width - height - 200, height, Justification::centredLeft, true);
  148. }
  149. }
  150. void listBoxItemClicked (int row, const MouseEvent& e)
  151. {
  152. if (e.x < getRowHeight())
  153. flipRow (row);
  154. }
  155. void listBoxItemDoubleClicked (int row, const MouseEvent& e)
  156. {
  157. flipRow (row);
  158. }
  159. void returnKeyPressed (int row)
  160. {
  161. flipRow (row);
  162. }
  163. void selectedRowsChanged (int lastRowSelected)
  164. {
  165. owner->selectionChanged (list.modules [lastRowSelected]);
  166. }
  167. void flipRow (int row)
  168. {
  169. const ModuleList::Module* const m = list.modules [row];
  170. if (m != nullptr)
  171. owner->setEnabled (m, ! owner->isEnabled (m));
  172. }
  173. private:
  174. ModuleList& list;
  175. ModulesPanel* owner;
  176. };
  177. //==============================================================================
  178. class ModuleSettingsPanel : public PropertyPanel
  179. {
  180. public:
  181. ModuleSettingsPanel (Project& project_, ModuleList& moduleList_, const String& moduleID_)
  182. : project (project_), moduleList (moduleList_), moduleID (moduleID_)
  183. {
  184. refreshAll();
  185. }
  186. void refreshAll()
  187. {
  188. setEnabled (project.isModuleEnabled (moduleID));
  189. clear();
  190. PropertyListBuilder props;
  191. ScopedPointer<LibraryModule> module (moduleList.loadModule (moduleID));
  192. if (module != nullptr)
  193. {
  194. props.add (new ModuleInfoComponent (project, moduleList, moduleID));
  195. if (project.isModuleEnabled (moduleID))
  196. {
  197. const ModuleList::Module* m = moduleList.findModuleInfo (moduleID);
  198. if (m != nullptr && moduleList.getExtraDependenciesNeeded (project, *m).size() > 0)
  199. props.add (new MissingDependenciesComponent (project, moduleList, moduleID));
  200. }
  201. props.add (new BooleanPropertyComponent (project.shouldShowAllModuleFilesInProject (moduleID),
  202. "Add source to project", "Make module files browsable in projects"),
  203. "If this is enabled, then the entire source tree from this module will be shown inside your project, "
  204. "making it easy to browse/edit the module's classes. If disabled, then only the minimum number of files "
  205. "required to compile it will appear inside your project.");
  206. props.add (new BooleanPropertyComponent (project.shouldCopyModuleFilesLocally (moduleID),
  207. "Create local copy", "Copy the module into the project folder"),
  208. "If this is enabled, then a local copy of the entire module will be made inside your project (in the auto-generated JuceLibraryFiles folder), "
  209. "so that your project will be self-contained, and won't need to contain any references to files in other folders. "
  210. "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.");
  211. StringArray possibleValues;
  212. possibleValues.add ("(Use Default)");
  213. possibleValues.add ("Enabled");
  214. possibleValues.add ("Disabled");
  215. Array<var> mappings;
  216. mappings.add (Project::configFlagDefault);
  217. mappings.add (Project::configFlagEnabled);
  218. mappings.add (Project::configFlagDisabled);
  219. OwnedArray <Project::ConfigFlag> flags;
  220. module->getConfigFlags (project, flags);
  221. for (int i = 0; i < flags.size(); ++i)
  222. {
  223. ChoicePropertyComponent* c = new ChoicePropertyComponent (flags[i]->value, flags[i]->symbol, possibleValues, mappings);
  224. c->setTooltip (flags[i]->description);
  225. props.add (c);
  226. }
  227. }
  228. addProperties (props.components);
  229. }
  230. private:
  231. Project& project;
  232. ModuleList& moduleList;
  233. String moduleID;
  234. //==============================================================================
  235. class ModuleInfoComponent : public PropertyComponent
  236. {
  237. public:
  238. ModuleInfoComponent (Project& project_, ModuleList& moduleList_, const String& moduleID_)
  239. : PropertyComponent ("Module", 100), project (project_), moduleList (moduleList_), moduleID (moduleID_)
  240. {
  241. }
  242. void refresh() {}
  243. void paint (Graphics& g)
  244. {
  245. g.setColour (Colours::white.withAlpha (0.4f));
  246. g.fillRect (0, 0, getWidth(), getHeight() - 1);
  247. const ModuleList::Module* module = moduleList.findModuleInfo (moduleID);
  248. if (module != nullptr)
  249. {
  250. String text;
  251. text << module->name << newLine << "Version: " << module->version << newLine << newLine
  252. << module->description;
  253. GlyphArrangement ga;
  254. ga.addJustifiedText (Font (13.0f), text, 4.0f, 16.0f, getWidth() - 8.0f, Justification::topLeft);
  255. g.setColour (Colours::black);
  256. ga.draw (g);
  257. }
  258. }
  259. private:
  260. Project& project;
  261. ModuleList& moduleList;
  262. String moduleID;
  263. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ModuleInfoComponent);
  264. };
  265. //==============================================================================
  266. class MissingDependenciesComponent : public PropertyComponent,
  267. public ButtonListener
  268. {
  269. public:
  270. MissingDependenciesComponent (Project& project_, ModuleList& moduleList_, const String& moduleID_)
  271. : PropertyComponent ("Dependencies", 100),
  272. project (project_), moduleList (moduleList_), moduleID (moduleID_),
  273. fixButton ("Enable Required Modules")
  274. {
  275. const ModuleList::Module* module = moduleList.findModuleInfo (moduleID);
  276. if (module != nullptr)
  277. missingDependencies = moduleList.getExtraDependenciesNeeded (project, *module);
  278. addAndMakeVisible (&fixButton);
  279. fixButton.setColour (TextButton::buttonColourId, Colours::red);
  280. fixButton.setColour (TextButton::textColourOffId, Colours::white);
  281. fixButton.setBounds ("right - 160, parent.height - 26, parent.width - 8, top + 22");
  282. fixButton.addListener (this);
  283. }
  284. void refresh() {}
  285. void paint (Graphics& g)
  286. {
  287. g.setColour (Colours::white.withAlpha (0.4f));
  288. g.fillRect (0, 0, getWidth(), getHeight() - 1);
  289. String text ("This module requires the following dependencies:\n");
  290. text << missingDependencies.joinIntoString (", ");
  291. GlyphArrangement ga;
  292. ga.addJustifiedText (Font (13.0f), text, 4.0f, 16.0f, getWidth() - 8.0f, Justification::topLeft);
  293. g.setColour (Colours::red);
  294. ga.draw (g);
  295. }
  296. void buttonClicked (Button*)
  297. {
  298. bool isModuleCopiedLocally = project.shouldCopyModuleFilesLocally (moduleID).getValue();
  299. for (int i = missingDependencies.size(); --i >= 0;)
  300. project.addModule (missingDependencies[i], isModuleCopiedLocally);
  301. ModulesPanel* mp = findParentComponentOfClass<ModulesPanel>();
  302. if (mp != nullptr)
  303. mp->refresh();
  304. }
  305. private:
  306. Project& project;
  307. ModuleList& moduleList;
  308. String moduleID;
  309. StringArray missingDependencies;
  310. TextButton fixButton;
  311. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MissingDependenciesComponent);
  312. };
  313. };
  314. //==============================================================================
  315. class ModuleCopyingInfo : public Component,
  316. public ButtonListener,
  317. public Timer
  318. {
  319. public:
  320. ModuleCopyingInfo (Project& project_, ModuleList& list_)
  321. : project (project_), list (list_),
  322. copyModeButton ("Set Copying Mode...")
  323. {
  324. addAndMakeVisible (&copyModeButton);
  325. copyModeButton.setBounds ("4, parent.height / 2 - 10, 160, parent.height / 2 + 10");
  326. copyModeButton.addListener (this);
  327. startTimer (1500);
  328. }
  329. void paint (Graphics& g)
  330. {
  331. g.setFont (11.0f);
  332. g.setColour (Colours::darkred);
  333. g.drawFittedText (getName(), copyModeButton.getRight() + 10, 0,
  334. getWidth() - copyModeButton.getRight() - 16, getHeight(),
  335. Justification::centredRight, 4);
  336. }
  337. void refresh()
  338. {
  339. int numCopied, numNonCopied;
  340. countCopiedModules (numCopied, numNonCopied);
  341. String newName;
  342. if (numCopied > 0 && numNonCopied > 0)
  343. newName = "Warning! Some of your modules are set to use local copies, and others are using remote references.\n"
  344. "This may create problems if some modules expect to share the same parent folder, so you may "
  345. "want to make sure that they are all either copied or not.";
  346. if (project.isAudioPluginModuleMissing())
  347. newName = "Warning! Your project is an audio plugin, but you haven't enabled the 'juce_audio_plugin_client' module!";
  348. if (newName != getName())
  349. {
  350. setName (newName);
  351. repaint();
  352. }
  353. }
  354. void countCopiedModules (int& numCopied, int& numNonCopied)
  355. {
  356. numCopied = numNonCopied = 0;
  357. for (int i = list.modules.size(); --i >= 0;)
  358. {
  359. const String moduleID (list.modules.getUnchecked(i)->uid);
  360. if (project.isModuleEnabled (moduleID))
  361. {
  362. if (project.shouldCopyModuleFilesLocally (moduleID).getValue())
  363. ++numCopied;
  364. else
  365. ++numNonCopied;
  366. }
  367. }
  368. }
  369. void buttonClicked (Button*)
  370. {
  371. PopupMenu menu;
  372. menu.addItem (1, "Enable local copying for all modules");
  373. menu.addItem (2, "Disable local copying for all modules");
  374. menu.showMenuAsync (PopupMenu::Options().withTargetComponent (&copyModeButton),
  375. ModalCallbackFunction::forComponent (copyMenuItemChosen, this));
  376. }
  377. static void copyMenuItemChosen (int resultCode, ModuleCopyingInfo* comp)
  378. {
  379. if (resultCode > 0 && comp != nullptr)
  380. comp->setCopyModeForAllModules (resultCode == 1);
  381. }
  382. void setCopyModeForAllModules (bool copyEnabled)
  383. {
  384. for (int i = list.modules.size(); --i >= 0;)
  385. project.shouldCopyModuleFilesLocally (list.modules.getUnchecked(i)->uid) = copyEnabled;
  386. refresh();
  387. }
  388. void timerCallback()
  389. {
  390. refresh();
  391. }
  392. private:
  393. Project& project;
  394. ModuleList& list;
  395. TextButton copyModeButton;
  396. };
  397. private:
  398. Project& project;
  399. ModuleList moduleList;
  400. FilenameComponent modulesLocation;
  401. Label modulesLabel;
  402. TextButton updateModulesButton;
  403. ModuleSelectionListBox moduleListBox;
  404. ModuleCopyingInfo copyingMessage;
  405. ScopedPointer<ModuleSettingsPanel> settings;
  406. };
  407. //==============================================================================
  408. struct ProjectSettingsTreeClasses
  409. {
  410. class PropertyGroup : public Component
  411. {
  412. public:
  413. PropertyGroup() {}
  414. void setProperties (const PropertyListBuilder& newProps)
  415. {
  416. properties.clear();
  417. properties.addArray (newProps.components);
  418. for (int i = properties.size(); --i >= 0;)
  419. addAndMakeVisible (properties.getUnchecked(i));
  420. }
  421. int updateSize (int x, int y, int width)
  422. {
  423. int height = 36;
  424. for (int i = 0; i < properties.size(); ++i)
  425. {
  426. PropertyComponent* pp = properties.getUnchecked(i);
  427. pp->setBounds (10, height, width - 20, pp->getPreferredHeight());
  428. height += pp->getHeight();
  429. }
  430. height += 16;
  431. setBounds (x, y, width, height);
  432. return height;
  433. }
  434. void paint (Graphics& g)
  435. {
  436. g.setColour (Colours::white.withAlpha (0.3f));
  437. g.fillRect (0, 28, getWidth(), getHeight() - 38);
  438. g.setColour (Colours::black.withAlpha (0.4f));
  439. g.drawRect (0, 28, getWidth(), getHeight() - 38);
  440. g.setFont (Font (14.0f, Font::bold));
  441. g.setColour (Colours::black);
  442. g.drawFittedText (getName(), 12, 0, getWidth() - 16, 26, Justification::bottomLeft, 1);
  443. }
  444. OwnedArray<PropertyComponent> properties;
  445. private:
  446. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyGroup);
  447. };
  448. //==============================================================================
  449. class PropertyPanelViewport : public Component
  450. {
  451. public:
  452. PropertyPanelViewport (Component* content)
  453. {
  454. addAndMakeVisible (&viewport);
  455. addAndMakeVisible (&rolloverHelp);
  456. viewport.setViewedComponent (content, true);
  457. }
  458. void paint (Graphics& g)
  459. {
  460. g.setTiledImageFill (ImageCache::getFromMemory (BinaryData::brushed_aluminium_png,
  461. BinaryData::brushed_aluminium_pngSize),
  462. 0, 0, 1.0f);
  463. g.fillAll();
  464. drawRecessedShadows (g, getWidth(), getHeight(), 14);
  465. }
  466. void resized()
  467. {
  468. Rectangle<int> r (getLocalBounds());
  469. rolloverHelp.setBounds (r.removeFromBottom (70).reduced (10, 0));
  470. viewport.setBounds (r);
  471. }
  472. Viewport viewport;
  473. RolloverHelpComp rolloverHelp;
  474. private:
  475. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyPanelViewport);
  476. };
  477. //==============================================================================
  478. class SettingsItemBase : public JucerTreeViewBase,
  479. public ValueTree::Listener
  480. {
  481. public:
  482. SettingsItemBase() {}
  483. void showSettingsPage (Component* content)
  484. {
  485. content->setComponentID (getUniqueName());
  486. ScopedPointer<Component> comp (content);
  487. ProjectContentComponent* pcc = getProjectContentComponent();
  488. if (pcc != nullptr)
  489. pcc->setEditorComponent (new PropertyPanelViewport (comp.release()), nullptr);
  490. }
  491. void closeSettingsPage()
  492. {
  493. ProjectContentComponent* pcc = getProjectContentComponent();
  494. if (pcc != nullptr)
  495. {
  496. PropertyPanelViewport* ppv = dynamic_cast<PropertyPanelViewport*> (pcc->getEditorComponent());
  497. if (ppv != nullptr && ppv->viewport.getViewedComponent()->getComponentID() == getUniqueName())
  498. pcc->hideEditor();
  499. }
  500. }
  501. void deleteAllSelectedItems()
  502. {
  503. TreeView* const tree = getOwnerView();
  504. jassert (tree->getNumSelectedItems() <= 1); // multi-select should be disabled
  505. if (SettingsItemBase* s = dynamic_cast <SettingsItemBase*> (tree->getSelectedItem (0)))
  506. s->deleteItem();
  507. }
  508. void itemOpennessChanged (bool isNowOpen)
  509. {
  510. if (isNowOpen)
  511. refreshSubItems();
  512. }
  513. void valueTreePropertyChanged (ValueTree&, const Identifier&) {}
  514. void valueTreeChildAdded (ValueTree&, ValueTree&) {}
  515. void valueTreeChildRemoved (ValueTree&, ValueTree&) {}
  516. void valueTreeChildOrderChanged (ValueTree&) {}
  517. void valueTreeParentChanged (ValueTree&) {}
  518. static void updateSize (Component& comp, PropertyGroup& group)
  519. {
  520. const int width = jmax (550, comp.getParentWidth() - 20);
  521. int y = 0;
  522. y += group.updateSize (12, y, width - 12);
  523. comp.setSize (width, y);
  524. }
  525. };
  526. //==============================================================================
  527. class ConfigItem : public SettingsItemBase
  528. {
  529. public:
  530. ConfigItem (const ProjectExporter::BuildConfiguration::Ptr& config_, const String& exporterName_)
  531. : config (config_), exporterName (exporterName_), configTree (config->config)
  532. {
  533. jassert (config != nullptr);
  534. configTree.addListener (this);
  535. }
  536. bool isRoot() const { return false; }
  537. bool isMissing() { return false; }
  538. bool canBeSelected() const { return true; }
  539. bool mightContainSubItems() { return false; }
  540. String getUniqueName() const { return config->project.getProjectUID() + "_config_" + config->getName(); }
  541. String getRenamingName() const { return getDisplayName(); }
  542. String getDisplayName() const { return config->getName(); }
  543. void setName (const String&) {}
  544. const Drawable* getIcon() const { return StoredSettings::getInstance()->getCogIcon(); }
  545. void showDocument() { showSettingsPage (new SettingsComp (config, exporterName)); }
  546. void itemOpennessChanged (bool) {}
  547. void deleteItem()
  548. {
  549. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Configuration",
  550. "Are you sure you want to delete this configuration?"))
  551. {
  552. closeSettingsPage();
  553. config->removeFromExporter();
  554. }
  555. }
  556. void showPopupMenu()
  557. {
  558. PopupMenu menu;
  559. menu.addItem (1, "Create a copy of this configuration");
  560. menu.addSeparator();
  561. menu.addItem (2, "Delete this configuration");
  562. launchPopupMenu (menu);
  563. }
  564. void handlePopupMenuResult (int resultCode)
  565. {
  566. if (resultCode == 2)
  567. {
  568. deleteAllSelectedItems();
  569. }
  570. else if (resultCode == 1)
  571. {
  572. for (Project::ExporterIterator exporter (config->project); exporter.next();)
  573. {
  574. if (config->config.isAChildOf (exporter.exporter->settings))
  575. {
  576. exporter.exporter->addNewConfiguration (config);
  577. break;
  578. }
  579. }
  580. }
  581. }
  582. var getDragSourceDescription()
  583. {
  584. return getParentItem()->getUniqueName() + "||" + config->getName();
  585. }
  586. void valueTreePropertyChanged (ValueTree&, const Identifier&) { repaintItem(); }
  587. private:
  588. ProjectExporter::BuildConfiguration::Ptr config;
  589. String exporterName;
  590. ValueTree configTree;
  591. //==============================================================================
  592. class SettingsComp : public Component
  593. {
  594. public:
  595. SettingsComp (ProjectExporter::BuildConfiguration* config, const String& exporterName)
  596. {
  597. addAndMakeVisible (&group);
  598. PropertyListBuilder props;
  599. config->createPropertyEditors (props);
  600. group.setProperties (props);
  601. group.setName (exporterName + " / " + config->getName());
  602. parentSizeChanged();
  603. }
  604. void parentSizeChanged() { updateSize (*this, group); }
  605. private:
  606. PropertyGroup group;
  607. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp);
  608. };
  609. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigItem);
  610. };
  611. //==============================================================================
  612. class ExporterItem : public SettingsItemBase
  613. {
  614. public:
  615. ExporterItem (Project& project_, ProjectExporter* exporter_, int exporterIndex_)
  616. : project (project_), exporter (exporter_), configListTree (exporter->getConfigurations()),
  617. exporterIndex (exporterIndex_)
  618. {
  619. configListTree.addListener (this);
  620. jassert (exporter != nullptr);
  621. }
  622. bool isRoot() const { return false; }
  623. bool canBeSelected() const { return true; }
  624. bool mightContainSubItems() { return exporter->getNumConfigurations() > 0; }
  625. String getUniqueName() const { return project.getProjectUID() + "_exporter_" + String (exporterIndex); }
  626. String getRenamingName() const { return getDisplayName(); }
  627. String getDisplayName() const { return exporter->getName(); }
  628. void setName (const String&) {}
  629. bool isMissing() { return false; }
  630. const Drawable* getIcon() const { return LookAndFeel::getDefaultLookAndFeel().getDefaultDocumentFileImage(); }
  631. void showDocument() { showSettingsPage (new SettingsComp (exporter)); }
  632. void deleteItem()
  633. {
  634. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Exporter",
  635. "Are you sure you want to delete this export target?"))
  636. {
  637. closeSettingsPage();
  638. ValueTree parent (exporter->settings.getParent());
  639. parent.removeChild (exporter->settings, project.getUndoManagerFor (parent));
  640. }
  641. }
  642. void addSubItems()
  643. {
  644. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  645. addSubItem (new ConfigItem (config.config, exporter->getName()));
  646. }
  647. void showPopupMenu()
  648. {
  649. PopupMenu menu;
  650. menu.addItem (1, "Add a new configuration");
  651. menu.addSeparator();
  652. menu.addItem (2, "Delete this exporter");
  653. launchPopupMenu (menu);
  654. }
  655. void handlePopupMenuResult (int resultCode)
  656. {
  657. if (resultCode == 2)
  658. deleteAllSelectedItems();
  659. else if (resultCode == 1)
  660. exporter->addNewConfiguration (nullptr);
  661. }
  662. var getDragSourceDescription()
  663. {
  664. return getParentItem()->getUniqueName() + "/" + String (exporterIndex);
  665. }
  666. bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails)
  667. {
  668. return dragSourceDetails.description.toString().startsWith (getUniqueName());
  669. }
  670. void itemDropped (const DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex)
  671. {
  672. const int oldIndex = indexOfConfig (dragSourceDetails.description.toString().fromLastOccurrenceOf ("||", false, false));
  673. if (oldIndex >= 0)
  674. configListTree.moveChild (oldIndex, insertIndex, project.getUndoManagerFor (configListTree));
  675. }
  676. int indexOfConfig (const String& configName)
  677. {
  678. int i = 0;
  679. for (ProjectExporter::ConfigIterator config (*exporter); config.next(); ++i)
  680. if (config->getName() == configName)
  681. return i;
  682. return -1;
  683. }
  684. //==============================================================================
  685. void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) { refreshIfNeeded (parentTree); }
  686. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&) { refreshIfNeeded (parentTree); }
  687. void valueTreeChildOrderChanged (ValueTree& parentTree) { refreshIfNeeded (parentTree); }
  688. void refreshIfNeeded (ValueTree& changedTree)
  689. {
  690. if (changedTree == configListTree)
  691. refreshSubItems();
  692. }
  693. private:
  694. Project& project;
  695. ScopedPointer<ProjectExporter> exporter;
  696. ValueTree configListTree;
  697. int exporterIndex;
  698. //==============================================================================
  699. class SettingsComp : public Component
  700. {
  701. public:
  702. SettingsComp (ProjectExporter* exporter)
  703. {
  704. addAndMakeVisible (&group);
  705. PropertyListBuilder props;
  706. exporter->createPropertyEditors (props);
  707. group.setProperties (props);
  708. group.setName ("Export target: " + exporter->getName());
  709. parentSizeChanged();
  710. }
  711. void parentSizeChanged() { updateSize (*this, group); }
  712. private:
  713. PropertyGroup group;
  714. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp);
  715. };
  716. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterItem);
  717. };
  718. //==============================================================================
  719. class ModulesItem : public SettingsItemBase
  720. {
  721. public:
  722. ModulesItem (Project& project_) : project (project_) {}
  723. bool isRoot() const { return false; }
  724. bool canBeSelected() const { return true; }
  725. bool mightContainSubItems() { return false; }
  726. String getUniqueName() const { return project.getProjectUID() + "_modules"; }
  727. String getRenamingName() const { return getDisplayName(); }
  728. String getDisplayName() const { return "Modules"; }
  729. void setName (const String&) {}
  730. bool isMissing() { return false; }
  731. const Drawable* getIcon() const { return project.getMainGroup().getIcon(); }
  732. void showDocument() { showSettingsPage (new SettingsComp (project)); }
  733. private:
  734. Project& project;
  735. //==============================================================================
  736. class SettingsComp : public Component
  737. {
  738. public:
  739. SettingsComp (Project& project_) : project (project_)
  740. {
  741. addAndMakeVisible (&group);
  742. PropertyListBuilder props;
  743. props.add (new ModulesPanel (project));
  744. group.setProperties (props);
  745. group.setName ("Modules");
  746. parentSizeChanged();
  747. }
  748. void parentSizeChanged()
  749. {
  750. updateSize (*this, group);
  751. }
  752. private:
  753. Project& project;
  754. var lastProjectType;
  755. PropertyGroup group;
  756. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp);
  757. };
  758. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ModulesItem);
  759. };
  760. //==============================================================================
  761. class RootItem : public SettingsItemBase
  762. {
  763. public:
  764. RootItem (Project& project_)
  765. : project (project_), exportersTree (project_.getExporters())
  766. {
  767. exportersTree.addListener (this);
  768. }
  769. bool isRoot() const { return true; }
  770. String getRenamingName() const { return getDisplayName(); }
  771. String getDisplayName() const { return project.getTitle(); }
  772. void setName (const String&) {}
  773. bool isMissing() { return false; }
  774. const Drawable* getIcon() const { return project.getMainGroup().getIcon(); }
  775. void showDocument() { showSettingsPage (new SettingsComp (project)); }
  776. bool canBeSelected() const { return true; }
  777. bool mightContainSubItems() { return project.getNumExporters() > 0; }
  778. String getUniqueName() const { return project.getProjectUID() + "_config_root"; }
  779. void addSubItems()
  780. {
  781. addSubItem (new ModulesItem (project));
  782. int i = 0;
  783. for (Project::ExporterIterator exporter (project); exporter.next(); ++i)
  784. addSubItem (new ExporterItem (project, exporter.exporter.release(), i));
  785. }
  786. void showPopupMenu()
  787. {
  788. PopupMenu menu;
  789. const StringArray exporters (ProjectExporter::getExporterNames());
  790. for (int i = 0; i < exporters.size(); ++i)
  791. menu.addItem (i + 1, "Create a new " + exporters[i] + " target");
  792. launchPopupMenu (menu);
  793. }
  794. void handlePopupMenuResult (int resultCode)
  795. {
  796. if (resultCode > 0)
  797. {
  798. String exporterName (ProjectExporter::getExporterNames() [resultCode - 1]);
  799. if (exporterName.isNotEmpty())
  800. project.addNewExporter (exporterName);
  801. }
  802. }
  803. bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails)
  804. {
  805. return dragSourceDetails.description.toString().startsWith (getUniqueName());
  806. }
  807. void itemDropped (const DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex)
  808. {
  809. int oldIndex = dragSourceDetails.description.toString().getTrailingIntValue();
  810. exportersTree.moveChild (oldIndex, insertIndex, project.getUndoManagerFor (exportersTree));
  811. }
  812. //==============================================================================
  813. void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) { refreshIfNeeded (parentTree); }
  814. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&) { refreshIfNeeded (parentTree); }
  815. void valueTreeChildOrderChanged (ValueTree& parentTree) { refreshIfNeeded (parentTree); }
  816. void refreshIfNeeded (ValueTree& changedTree)
  817. {
  818. if (changedTree == exportersTree)
  819. refreshSubItems();
  820. }
  821. private:
  822. Project& project;
  823. ValueTree exportersTree;
  824. //==============================================================================
  825. class SettingsComp : public Component,
  826. private ChangeListener
  827. {
  828. public:
  829. SettingsComp (Project& project_)
  830. : project (project_)
  831. {
  832. addAndMakeVisible (&group);
  833. updatePropertyList();
  834. project.addChangeListener (this);
  835. }
  836. ~SettingsComp()
  837. {
  838. project.removeChangeListener (this);
  839. }
  840. void parentSizeChanged()
  841. {
  842. updateSize (*this, group);
  843. }
  844. void updatePropertyList()
  845. {
  846. PropertyListBuilder props;
  847. project.createPropertyEditors (props);
  848. group.setProperties (props);
  849. group.setName ("Project Settings");
  850. lastProjectType = project.getProjectTypeValue().getValue();
  851. parentSizeChanged();
  852. }
  853. void changeListenerCallback (ChangeBroadcaster*)
  854. {
  855. if (lastProjectType != project.getProjectTypeValue().getValue())
  856. updatePropertyList();
  857. }
  858. private:
  859. Project& project;
  860. var lastProjectType;
  861. PropertyGroup group;
  862. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp);
  863. };
  864. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RootItem);
  865. };
  866. };
  867. JucerTreeViewBase* createProjectConfigTreeViewRoot (Project& project)
  868. {
  869. return new ProjectSettingsTreeClasses::RootItem (project);
  870. }