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.

283 lines
9.9KB

  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 ExporterItem : public ConfigTreeItemBase
  18. {
  19. public:
  20. ExporterItem (Project& p, ProjectExporter* e, int index)
  21. : project (p), exporter (e), configListTree (exporter->getConfigurations()),
  22. exporterIndex (index)
  23. {
  24. configListTree.addListener (this);
  25. }
  26. int getItemHeight() const override { return 25; }
  27. bool canBeSelected() const override { return true; }
  28. bool mightContainSubItems() override { return exporter->getNumConfigurations() > 0; }
  29. String getUniqueName() const override { return "exporter_" + String (exporterIndex); }
  30. String getRenamingName() const override { return getDisplayName(); }
  31. String getDisplayName() const override { return exporter->getName(); }
  32. void setName (const String&) override {}
  33. bool isMissing() const override { return false; }
  34. static Icon getIconForExporter (ProjectExporter* e)
  35. {
  36. if (e != nullptr)
  37. {
  38. if (e->isXcode()) return Icon (getIcons().xcode, Colours::transparentBlack);
  39. else if (e->isVisualStudio()) return Icon (getIcons().visualStudio, Colours::transparentBlack);
  40. else if (e->isAndroid()) return Icon (getIcons().android, Colours::transparentBlack);
  41. else if (e->isLinux()) return Icon (getIcons().linux, Colours::transparentBlack);
  42. }
  43. return Icon();
  44. }
  45. Icon getIcon() const override
  46. {
  47. return getIconForExporter (exporter).withColour (getContentColour (true));
  48. }
  49. void showDocument() override
  50. {
  51. showSettingsPage (new SettingsComp (exporter));
  52. }
  53. void deleteItem() override
  54. {
  55. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Exporter",
  56. "Are you sure you want to delete this export target?"))
  57. {
  58. closeSettingsPage();
  59. ValueTree parent (exporter->settings.getParent());
  60. parent.removeChild (exporter->settings, project.getUndoManagerFor (parent));
  61. }
  62. }
  63. void addSubItems() override
  64. {
  65. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  66. addSubItem (new ConfigItem (config.config, *exporter));
  67. }
  68. void showPopupMenu() override
  69. {
  70. PopupMenu menu;
  71. menu.addItem (1, "Add a new configuration", exporter->supportsUserDefinedConfigurations());
  72. menu.addSeparator();
  73. menu.addItem (2, "Delete this exporter");
  74. launchPopupMenu (menu);
  75. }
  76. void showPlusMenu() override
  77. {
  78. PopupMenu menu;
  79. menu.addItem (1, "Add a new configuration", exporter->supportsUserDefinedConfigurations());
  80. launchPopupMenu (menu);
  81. }
  82. void handlePopupMenuResult (int resultCode) override
  83. {
  84. if (resultCode == 2)
  85. deleteAllSelectedItems();
  86. else if (resultCode == 1)
  87. exporter->addNewConfiguration (nullptr);
  88. }
  89. var getDragSourceDescription() override
  90. {
  91. return getParentItem()->getUniqueName() + "/" + String (exporterIndex);
  92. }
  93. bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails) override
  94. {
  95. return dragSourceDetails.description.toString().startsWith (getUniqueName());
  96. }
  97. void itemDropped (const DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) override
  98. {
  99. const int oldIndex = indexOfConfig (dragSourceDetails.description.toString().fromLastOccurrenceOf ("||", false, false));
  100. if (oldIndex >= 0)
  101. configListTree.moveChild (oldIndex, insertIndex, project.getUndoManagerFor (configListTree));
  102. }
  103. int indexOfConfig (const String& configName)
  104. {
  105. int i = 0;
  106. for (ProjectExporter::ConfigIterator config (*exporter); config.next(); ++i)
  107. if (config->getName() == configName)
  108. return i;
  109. return -1;
  110. }
  111. //==============================================================================
  112. void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
  113. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&, int) override { refreshIfNeeded (parentTree); }
  114. void valueTreeChildOrderChanged (ValueTree& parentTree, int, int) override { refreshIfNeeded (parentTree); }
  115. void refreshIfNeeded (ValueTree& changedTree)
  116. {
  117. if (changedTree == configListTree)
  118. refreshSubItems();
  119. }
  120. private:
  121. Project& project;
  122. ScopedPointer<ProjectExporter> exporter;
  123. ValueTree configListTree;
  124. int exporterIndex;
  125. //==============================================================================
  126. class SettingsComp : public Component
  127. {
  128. public:
  129. SettingsComp (ProjectExporter* exp)
  130. : group (exp->getName(), ExporterItem::getIconForExporter (exp))
  131. {
  132. addAndMakeVisible (group);
  133. PropertyListBuilder props;
  134. exp->createPropertyEditors (props);
  135. group.setProperties (props);
  136. parentSizeChanged();
  137. }
  138. void parentSizeChanged() override { updateSize (*this, group); }
  139. void resized() override { group.setBounds (getLocalBounds().withTrimmedLeft (12)); }
  140. private:
  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. };