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.

282 lines
9.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. class ExporterItem : public ConfigTreeItemBase
  20. {
  21. public:
  22. ExporterItem (Project& p, ProjectExporter* e, int index)
  23. : project (p), exporter (e), configListTree (exporter->getConfigurations()),
  24. exporterIndex (index)
  25. {
  26. configListTree.addListener (this);
  27. }
  28. int getItemHeight() const override { return 25; }
  29. bool canBeSelected() const override { return true; }
  30. bool mightContainSubItems() override { return exporter->getNumConfigurations() > 0; }
  31. String getUniqueName() const override { return "exporter_" + String (exporterIndex); }
  32. String getRenamingName() const override { return getDisplayName(); }
  33. String getDisplayName() const override { return exporter->getName(); }
  34. void setName (const String&) override {}
  35. bool isMissing() const override { return false; }
  36. static Icon getIconForExporter (ProjectExporter* e)
  37. {
  38. if (e != nullptr)
  39. {
  40. if (e->isXcode()) return Icon (getIcons().xcode, Colours::transparentBlack);
  41. else if (e->isVisualStudio()) return Icon (getIcons().visualStudio, Colours::transparentBlack);
  42. else if (e->isAndroid()) return Icon (getIcons().android, Colours::transparentBlack);
  43. else if (e->isLinux()) return Icon (getIcons().linux, Colours::transparentBlack);
  44. }
  45. return Icon();
  46. }
  47. Icon getIcon() const override
  48. {
  49. return getIconForExporter (exporter).withColour (getContentColour (true));
  50. }
  51. void showDocument() override
  52. {
  53. showSettingsPage (new SettingsComp (exporter));
  54. }
  55. void deleteItem() override
  56. {
  57. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Exporter",
  58. "Are you sure you want to delete this export target?"))
  59. {
  60. closeSettingsPage();
  61. ValueTree parent (exporter->settings.getParent());
  62. parent.removeChild (exporter->settings, project.getUndoManagerFor (parent));
  63. }
  64. }
  65. void addSubItems() override
  66. {
  67. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  68. addSubItem (new ConfigItem (config.config, *exporter));
  69. }
  70. void showPopupMenu() override
  71. {
  72. PopupMenu menu;
  73. menu.addItem (1, "Add a new configuration", exporter->supportsUserDefinedConfigurations());
  74. menu.addSeparator();
  75. menu.addItem (2, "Delete this exporter");
  76. launchPopupMenu (menu);
  77. }
  78. void showPlusMenu() override
  79. {
  80. PopupMenu menu;
  81. menu.addItem (1, "Add a new configuration", exporter->supportsUserDefinedConfigurations());
  82. launchPopupMenu (menu);
  83. }
  84. void handlePopupMenuResult (int resultCode) override
  85. {
  86. if (resultCode == 2)
  87. deleteAllSelectedItems();
  88. else if (resultCode == 1)
  89. exporter->addNewConfiguration (nullptr);
  90. }
  91. var getDragSourceDescription() override
  92. {
  93. return getParentItem()->getUniqueName() + "/" + String (exporterIndex);
  94. }
  95. bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails) override
  96. {
  97. return dragSourceDetails.description.toString().startsWith (getUniqueName());
  98. }
  99. void itemDropped (const DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) override
  100. {
  101. const int oldIndex = indexOfConfig (dragSourceDetails.description.toString().fromLastOccurrenceOf ("||", false, false));
  102. if (oldIndex >= 0)
  103. configListTree.moveChild (oldIndex, insertIndex, project.getUndoManagerFor (configListTree));
  104. }
  105. int indexOfConfig (const String& configName)
  106. {
  107. int i = 0;
  108. for (ProjectExporter::ConfigIterator config (*exporter); config.next(); ++i)
  109. if (config->getName() == configName)
  110. return i;
  111. return -1;
  112. }
  113. //==============================================================================
  114. void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
  115. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&, int) override { refreshIfNeeded (parentTree); }
  116. void valueTreeChildOrderChanged (ValueTree& parentTree, int, int) override { refreshIfNeeded (parentTree); }
  117. void refreshIfNeeded (ValueTree& changedTree)
  118. {
  119. if (changedTree == configListTree)
  120. refreshSubItems();
  121. }
  122. private:
  123. Project& project;
  124. ScopedPointer<ProjectExporter> exporter;
  125. ValueTree configListTree;
  126. int exporterIndex;
  127. //==============================================================================
  128. struct SettingsComp : public Component
  129. {
  130. SettingsComp (ProjectExporter* exp)
  131. : group (exp->getName(), ExporterItem::getIconForExporter (exp))
  132. {
  133. addAndMakeVisible (group);
  134. PropertyListBuilder props;
  135. exp->createPropertyEditors (props);
  136. group.setProperties (props);
  137. parentSizeChanged();
  138. }
  139. void parentSizeChanged() override { updateSize (*this, group); }
  140. void resized() override { group.setBounds (getLocalBounds().withTrimmedLeft (12)); }
  141. PropertyGroupComponent group;
  142. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp)
  143. };
  144. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterItem)
  145. };
  146. //==============================================================================
  147. class ConfigItem : public ConfigTreeItemBase
  148. {
  149. public:
  150. ConfigItem (const ProjectExporter::BuildConfiguration::Ptr& conf, ProjectExporter& e)
  151. : config (conf), exporter (e), configTree (config->config)
  152. {
  153. jassert (config != nullptr);
  154. configTree.addListener (this);
  155. }
  156. bool isMissing() const override { return false; }
  157. bool canBeSelected() const override { return true; }
  158. bool mightContainSubItems() override { return false; }
  159. String getUniqueName() const override { return "config_" + config->getName(); }
  160. String getRenamingName() const override { return getDisplayName(); }
  161. String getDisplayName() const override { return config->getName(); }
  162. void setName (const String&) override {}
  163. Icon getIcon() const override { return Icon (getIcons().config, getContentColour (true)); }
  164. void itemOpennessChanged (bool) override {}
  165. void showDocument() override
  166. {
  167. showSettingsPage (new SettingsComp (config));
  168. }
  169. void deleteItem() override
  170. {
  171. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Configuration",
  172. "Are you sure you want to delete this configuration?"))
  173. {
  174. closeSettingsPage();
  175. config->removeFromExporter();
  176. }
  177. }
  178. void showPopupMenu() override
  179. {
  180. bool enabled = exporter.supportsUserDefinedConfigurations();
  181. PopupMenu menu;
  182. menu.addItem (1, "Create a copy of this configuration", enabled);
  183. menu.addSeparator();
  184. menu.addItem (2, "Delete this configuration", enabled);
  185. launchPopupMenu (menu);
  186. }
  187. void handlePopupMenuResult (int resultCode) override
  188. {
  189. if (resultCode == 2)
  190. {
  191. deleteAllSelectedItems();
  192. }
  193. else if (resultCode == 1)
  194. {
  195. exporter.addNewConfiguration (config);
  196. }
  197. }
  198. var getDragSourceDescription() override
  199. {
  200. return getParentItem()->getUniqueName() + "||" + config->getName();
  201. }
  202. void valueTreePropertyChanged (ValueTree&, const Identifier&) override { repaintItem(); }
  203. private:
  204. ProjectExporter::BuildConfiguration::Ptr config;
  205. ProjectExporter& exporter;
  206. ValueTree configTree;
  207. //==============================================================================
  208. class SettingsComp : public Component
  209. {
  210. public:
  211. SettingsComp (ProjectExporter::BuildConfiguration* conf)
  212. : group (conf->exporter.getName() + " - " + conf->getName(), Icon (getIcons().config, Colours::transparentBlack))
  213. {
  214. addAndMakeVisible (group);
  215. PropertyListBuilder props;
  216. conf->createPropertyEditors (props);
  217. group.setProperties (props);
  218. parentSizeChanged();
  219. }
  220. void parentSizeChanged() override { updateSize (*this, group); }
  221. void resized() override { group.setBounds (getLocalBounds().withTrimmedLeft (12)); }
  222. private:
  223. PropertyGroupComponent group;
  224. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp)
  225. };
  226. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigItem)
  227. };