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.

295 lines
10KB

  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. private Value::Listener
  21. {
  22. public:
  23. ExporterItem (Project& p, ProjectExporter* e, int index)
  24. : project (p), exporter (e), configListTree (exporter->getConfigurations()),
  25. exporterIndex (index)
  26. {
  27. configListTree.addListener (this);
  28. targetLocationValue.referTo (exporter->getTargetLocationValue());
  29. targetLocationValue.addListener (this);
  30. }
  31. int getItemHeight() const override { return 25; }
  32. bool canBeSelected() const override { return true; }
  33. bool mightContainSubItems() override { return exporter->getNumConfigurations() > 0; }
  34. String getUniqueName() const override { return "exporter_" + String (exporterIndex); }
  35. String getRenamingName() const override { return getDisplayName(); }
  36. String getDisplayName() const override { return exporter->getName(); }
  37. void setName (const String&) override {}
  38. bool isMissing() const override { return false; }
  39. String getTooltip() override { return getDisplayName(); }
  40. static Icon getIconForExporter (ProjectExporter* e)
  41. {
  42. if (e != nullptr)
  43. {
  44. if (e->isXcode()) return Icon (getIcons().xcode, Colours::transparentBlack);
  45. else if (e->isVisualStudio()) return Icon (getIcons().visualStudio, Colours::transparentBlack);
  46. else if (e->isAndroid()) return Icon (getIcons().android, Colours::transparentBlack);
  47. else if (e->isCodeBlocks()) return Icon (getIcons().codeBlocks, Colours::transparentBlack);
  48. else if (e->isMakefile()) return Icon (getIcons().linux, Colours::transparentBlack);
  49. }
  50. return Icon();
  51. }
  52. Icon getIcon() const override
  53. {
  54. return getIconForExporter (exporter).withColour (getContentColour (true));
  55. }
  56. void showDocument() override
  57. {
  58. showSettingsPage (new SettingsComp (exporter));
  59. }
  60. void deleteItem() override
  61. {
  62. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Exporter",
  63. "Are you sure you want to delete this export target?"))
  64. {
  65. closeSettingsPage();
  66. ValueTree parent (exporter->settings.getParent());
  67. parent.removeChild (exporter->settings, project.getUndoManagerFor (parent));
  68. }
  69. }
  70. void addSubItems() override
  71. {
  72. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  73. addSubItem (new ConfigItem (config.config, *exporter));
  74. }
  75. void showPopupMenu() override
  76. {
  77. PopupMenu menu;
  78. menu.addItem (1, "Add a new configuration", exporter->supportsUserDefinedConfigurations());
  79. menu.addSeparator();
  80. menu.addItem (2, "Delete this exporter");
  81. launchPopupMenu (menu);
  82. }
  83. void showPlusMenu() override
  84. {
  85. PopupMenu menu;
  86. menu.addItem (1, "Add a new configuration", exporter->supportsUserDefinedConfigurations());
  87. launchPopupMenu (menu);
  88. }
  89. void handlePopupMenuResult (int resultCode) override
  90. {
  91. if (resultCode == 2)
  92. deleteAllSelectedItems();
  93. else if (resultCode == 1)
  94. exporter->addNewConfiguration (nullptr);
  95. }
  96. var getDragSourceDescription() override
  97. {
  98. return getParentItem()->getUniqueName() + "/" + String (exporterIndex);
  99. }
  100. bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails) override
  101. {
  102. return dragSourceDetails.description.toString().startsWith (getUniqueName());
  103. }
  104. void itemDropped (const DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) override
  105. {
  106. const int oldIndex = indexOfConfig (dragSourceDetails.description.toString().fromLastOccurrenceOf ("||", false, false));
  107. if (oldIndex >= 0)
  108. configListTree.moveChild (oldIndex, insertIndex, project.getUndoManagerFor (configListTree));
  109. }
  110. int indexOfConfig (const String& configName)
  111. {
  112. int i = 0;
  113. for (ProjectExporter::ConfigIterator config (*exporter); config.next(); ++i)
  114. if (config->getName() == configName)
  115. return i;
  116. return -1;
  117. }
  118. //==============================================================================
  119. void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
  120. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&, int) override { refreshIfNeeded (parentTree); }
  121. void valueTreeChildOrderChanged (ValueTree& parentTree, int, int) override { refreshIfNeeded (parentTree); }
  122. void refreshIfNeeded (ValueTree& changedTree)
  123. {
  124. if (changedTree == configListTree)
  125. refreshSubItems();
  126. }
  127. private:
  128. Project& project;
  129. ScopedPointer<ProjectExporter> exporter;
  130. ValueTree configListTree;
  131. int exporterIndex;
  132. Value targetLocationValue;
  133. void valueChanged (Value& value) override
  134. {
  135. if (value == exporter->getTargetLocationValue())
  136. refreshSubItems();
  137. }
  138. //==============================================================================
  139. struct SettingsComp : public Component
  140. {
  141. SettingsComp (ProjectExporter* exp)
  142. : group (exp->getName(), ExporterItem::getIconForExporter (exp))
  143. {
  144. addAndMakeVisible (group);
  145. PropertyListBuilder props;
  146. exp->createPropertyEditors (props);
  147. group.setProperties (props);
  148. parentSizeChanged();
  149. }
  150. void parentSizeChanged() override { updateSize (*this, group); }
  151. void resized() override { group.setBounds (getLocalBounds().withTrimmedLeft (12)); }
  152. PropertyGroupComponent group;
  153. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp)
  154. };
  155. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterItem)
  156. };
  157. //==============================================================================
  158. class ConfigItem : public ConfigTreeItemBase
  159. {
  160. public:
  161. ConfigItem (const ProjectExporter::BuildConfiguration::Ptr& conf, ProjectExporter& e)
  162. : config (conf), exporter (e), configTree (config->config)
  163. {
  164. jassert (config != nullptr);
  165. configTree.addListener (this);
  166. }
  167. bool isMissing() const override { return false; }
  168. bool canBeSelected() const override { return true; }
  169. bool mightContainSubItems() override { return false; }
  170. String getUniqueName() const override { return "config_" + config->getName(); }
  171. String getRenamingName() const override { return getDisplayName(); }
  172. String getDisplayName() const override { return config->getName(); }
  173. void setName (const String&) override {}
  174. Icon getIcon() const override { return Icon (getIcons().config, getContentColour (true)); }
  175. void itemOpennessChanged (bool) override {}
  176. void showDocument() override
  177. {
  178. showSettingsPage (new SettingsComp (config));
  179. }
  180. void deleteItem() override
  181. {
  182. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Configuration",
  183. "Are you sure you want to delete this configuration?"))
  184. {
  185. closeSettingsPage();
  186. config->removeFromExporter();
  187. }
  188. }
  189. void showPopupMenu() override
  190. {
  191. bool enabled = exporter.supportsUserDefinedConfigurations();
  192. PopupMenu menu;
  193. menu.addItem (1, "Create a copy of this configuration", enabled);
  194. menu.addSeparator();
  195. menu.addItem (2, "Delete this configuration", enabled);
  196. launchPopupMenu (menu);
  197. }
  198. void handlePopupMenuResult (int resultCode) override
  199. {
  200. if (resultCode == 2)
  201. {
  202. deleteAllSelectedItems();
  203. }
  204. else if (resultCode == 1)
  205. {
  206. exporter.addNewConfiguration (config);
  207. }
  208. }
  209. var getDragSourceDescription() override
  210. {
  211. return getParentItem()->getUniqueName() + "||" + config->getName();
  212. }
  213. void valueTreePropertyChanged (ValueTree&, const Identifier&) override { repaintItem(); }
  214. private:
  215. ProjectExporter::BuildConfiguration::Ptr config;
  216. ProjectExporter& exporter;
  217. ValueTree configTree;
  218. //==============================================================================
  219. class SettingsComp : public Component
  220. {
  221. public:
  222. SettingsComp (ProjectExporter::BuildConfiguration* conf)
  223. : group (conf->exporter.getName() + " - " + conf->getName(), Icon (getIcons().config, Colours::transparentBlack))
  224. {
  225. addAndMakeVisible (group);
  226. PropertyListBuilder props;
  227. conf->createPropertyEditors (props);
  228. group.setProperties (props);
  229. parentSizeChanged();
  230. }
  231. void parentSizeChanged() override { updateSize (*this, group); }
  232. void resized() override { group.setBounds (getLocalBounds().withTrimmedLeft (12)); }
  233. private:
  234. PropertyGroupComponent group;
  235. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp)
  236. };
  237. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigItem)
  238. };