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.

252 lines
9.0KB

  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 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. jassert (exporter != nullptr);
  26. }
  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() override { return false; }
  34. Icon getIcon() const override { return Icon (getIcons().exporter, getContrastingColour (0.5f)); }
  35. void showDocument() override { showSettingsPage (new SettingsComp (exporter)); }
  36. void deleteItem() override
  37. {
  38. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Exporter",
  39. "Are you sure you want to delete this export target?"))
  40. {
  41. closeSettingsPage();
  42. ValueTree parent (exporter->settings.getParent());
  43. parent.removeChild (exporter->settings, project.getUndoManagerFor (parent));
  44. }
  45. }
  46. void addSubItems() override
  47. {
  48. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  49. addSubItem (new ConfigItem (config.config, exporter->getName()));
  50. }
  51. void showPopupMenu() override
  52. {
  53. PopupMenu menu;
  54. menu.addItem (1, "Add a new configuration");
  55. menu.addSeparator();
  56. menu.addItem (2, "Delete this exporter");
  57. launchPopupMenu (menu);
  58. }
  59. void handlePopupMenuResult (int resultCode) override
  60. {
  61. if (resultCode == 2)
  62. deleteAllSelectedItems();
  63. else if (resultCode == 1)
  64. exporter->addNewConfiguration (nullptr);
  65. }
  66. var getDragSourceDescription() override
  67. {
  68. return getParentItem()->getUniqueName() + "/" + String (exporterIndex);
  69. }
  70. bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails) override
  71. {
  72. return dragSourceDetails.description.toString().startsWith (getUniqueName());
  73. }
  74. void itemDropped (const DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex) override
  75. {
  76. const int oldIndex = indexOfConfig (dragSourceDetails.description.toString().fromLastOccurrenceOf ("||", false, false));
  77. if (oldIndex >= 0)
  78. configListTree.moveChild (oldIndex, insertIndex, project.getUndoManagerFor (configListTree));
  79. }
  80. int indexOfConfig (const String& configName)
  81. {
  82. int i = 0;
  83. for (ProjectExporter::ConfigIterator config (*exporter); config.next(); ++i)
  84. if (config->getName() == configName)
  85. return i;
  86. return -1;
  87. }
  88. //==============================================================================
  89. void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
  90. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
  91. void valueTreeChildOrderChanged (ValueTree& parentTree) override { refreshIfNeeded (parentTree); }
  92. void refreshIfNeeded (ValueTree& changedTree)
  93. {
  94. if (changedTree == configListTree)
  95. refreshSubItems();
  96. }
  97. private:
  98. Project& project;
  99. ScopedPointer<ProjectExporter> exporter;
  100. ValueTree configListTree;
  101. int exporterIndex;
  102. //==============================================================================
  103. class SettingsComp : public Component
  104. {
  105. public:
  106. SettingsComp (ProjectExporter* exp)
  107. {
  108. addAndMakeVisible (group);
  109. PropertyListBuilder props;
  110. exp->createPropertyEditors (props);
  111. group.setProperties (props);
  112. group.setName ("Export target: " + exp->getName());
  113. parentSizeChanged();
  114. }
  115. void parentSizeChanged() override { updateSize (*this, group); }
  116. private:
  117. PropertyGroupComponent group;
  118. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp)
  119. };
  120. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterItem)
  121. };
  122. //==============================================================================
  123. class ConfigItem : public ConfigTreeItemBase
  124. {
  125. public:
  126. ConfigItem (const ProjectExporter::BuildConfiguration::Ptr& conf, const String& expName)
  127. : config (conf), exporterName (expName), configTree (config->config)
  128. {
  129. jassert (config != nullptr);
  130. configTree.addListener (this);
  131. }
  132. bool isMissing() override { return false; }
  133. bool canBeSelected() const override { return true; }
  134. bool mightContainSubItems() override { return false; }
  135. String getUniqueName() const override { return "config_" + config->getName(); }
  136. String getRenamingName() const override { return getDisplayName(); }
  137. String getDisplayName() const override { return config->getName(); }
  138. void setName (const String&) override {}
  139. Icon getIcon() const override { return Icon (getIcons().config, getContrastingColour (Colours::green, 0.5f)); }
  140. void showDocument() override { showSettingsPage (new SettingsComp (config, exporterName)); }
  141. void itemOpennessChanged (bool) override {}
  142. void deleteItem() override
  143. {
  144. if (AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, "Delete Configuration",
  145. "Are you sure you want to delete this configuration?"))
  146. {
  147. closeSettingsPage();
  148. config->removeFromExporter();
  149. }
  150. }
  151. void showPopupMenu() override
  152. {
  153. PopupMenu menu;
  154. menu.addItem (1, "Create a copy of this configuration");
  155. menu.addSeparator();
  156. menu.addItem (2, "Delete this configuration");
  157. launchPopupMenu (menu);
  158. }
  159. void handlePopupMenuResult (int resultCode) override
  160. {
  161. if (resultCode == 2)
  162. {
  163. deleteAllSelectedItems();
  164. }
  165. else if (resultCode == 1)
  166. {
  167. for (Project::ExporterIterator exporter (config->project); exporter.next();)
  168. {
  169. if (config->config.isAChildOf (exporter->settings))
  170. {
  171. exporter->addNewConfiguration (config);
  172. break;
  173. }
  174. }
  175. }
  176. }
  177. var getDragSourceDescription()
  178. {
  179. return getParentItem()->getUniqueName() + "||" + config->getName();
  180. }
  181. void valueTreePropertyChanged (ValueTree&, const Identifier&) override { repaintItem(); }
  182. private:
  183. ProjectExporter::BuildConfiguration::Ptr config;
  184. String exporterName;
  185. ValueTree configTree;
  186. //==============================================================================
  187. class SettingsComp : public Component
  188. {
  189. public:
  190. SettingsComp (ProjectExporter::BuildConfiguration* conf, const String& expName)
  191. {
  192. addAndMakeVisible (group);
  193. PropertyListBuilder props;
  194. conf->createPropertyEditors (props);
  195. group.setProperties (props);
  196. group.setName (expName + " / " + conf->getName());
  197. parentSizeChanged();
  198. }
  199. void parentSizeChanged() override { updateSize (*this, group); }
  200. private:
  201. PropertyGroupComponent group;
  202. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SettingsComp)
  203. };
  204. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ConfigItem)
  205. };