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.

232 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. #pragma once
  20. //==============================================================================
  21. class GlobalSearchPathsWindowComponent : public Component,
  22. private ComboBox::Listener
  23. {
  24. public:
  25. GlobalSearchPathsWindowComponent()
  26. : modulesLabel ("modulesLabel", "Modules"),
  27. sdksLabel ("sdksLabel", "SDKs"),
  28. cLionLabel ("cLionLabel", "CLion")
  29. {
  30. addAndMakeVisible (modulesLabel);
  31. addAndMakeVisible (sdksLabel);
  32. addAndMakeVisible (cLionLabel);
  33. modulesLabel.setFont (Font (18.0f, Font::FontStyleFlags::bold));
  34. sdksLabel .setFont (Font (18.0f, Font::FontStyleFlags::bold));
  35. cLionLabel .setFont (Font (18.0f, Font::FontStyleFlags::bold));
  36. modulesLabel.setJustificationType (Justification::centredLeft);
  37. sdksLabel .setJustificationType (Justification::centredLeft);
  38. cLionLabel .setJustificationType (Justification::centredLeft);
  39. addAndMakeVisible (info);
  40. info.setInfoToDisplay ("Use this dropdown to set the global paths for different OSes. "
  41. "\nN.B. These paths are stored locally and will only be used when "
  42. "saving a project on this machine. Other machines will have their own "
  43. "locally stored paths.");
  44. addAndMakeVisible (osSelector);
  45. osSelector.addItem ("OSX", 1);
  46. osSelector.addItem ("Windows", 2);
  47. osSelector.addItem ("Linux", 3);
  48. osSelector.addListener (this);
  49. auto os = TargetOS::getThisOS();
  50. if (os == TargetOS::osx) osSelector.setSelectedId (1);
  51. else if (os == TargetOS::windows) osSelector.setSelectedId (2);
  52. else if (os == TargetOS::linux) osSelector.setSelectedId (3);
  53. updateFilePathPropertyComponents();
  54. }
  55. void paint (Graphics& g) override
  56. {
  57. g.fillAll (findColour (backgroundColourId));
  58. }
  59. void resized() override
  60. {
  61. auto b = getLocalBounds().reduced (10);
  62. auto topSlice = b.removeFromTop (25);
  63. osSelector.setSize (200, 25);
  64. osSelector.setCentrePosition (topSlice.getCentre());
  65. info.setBounds (osSelector.getBounds().withWidth (osSelector.getHeight()).translated ((osSelector.getWidth() + 5), 0).reduced (2));
  66. modulesLabel.setBounds (b.removeFromTop (20));
  67. b.removeFromTop (20);
  68. auto thisOS = TargetOS::getThisOS();
  69. auto selectedOS = getSelectedOS();
  70. const int numComps = pathPropertyComponents.size();
  71. for (int i = 0; i < numComps; ++i)
  72. {
  73. pathPropertyComponents[i]->setBounds (b.removeFromTop (pathPropertyComponents[i]->getPreferredHeight()));
  74. b.removeFromTop (5);
  75. if (i == 1)
  76. {
  77. b.removeFromTop (15);
  78. sdksLabel.setBounds (b.removeFromTop (20));
  79. b.removeFromTop (20);
  80. }
  81. if (selectedOS == thisOS && i == numComps - 2)
  82. {
  83. b.removeFromTop (15);
  84. cLionLabel.setBounds (b.removeFromTop (20));
  85. b.removeFromTop (20);
  86. }
  87. }
  88. }
  89. private:
  90. Label modulesLabel, sdksLabel, cLionLabel;
  91. OwnedArray<PropertyComponent> pathPropertyComponents;
  92. ComboBox osSelector;
  93. InfoButton info;
  94. void comboBoxChanged (ComboBox*) override
  95. {
  96. updateFilePathPropertyComponents();
  97. }
  98. TargetOS::OS getSelectedOS() const
  99. {
  100. auto selectedOS = TargetOS::unknown;
  101. switch (osSelector.getSelectedId())
  102. {
  103. case 1: selectedOS = TargetOS::osx; break;
  104. case 2: selectedOS = TargetOS::windows; break;
  105. case 3: selectedOS = TargetOS::linux; break;
  106. default: break;
  107. }
  108. return selectedOS;
  109. }
  110. void updateFilePathPropertyComponents()
  111. {
  112. pathPropertyComponents.clear();
  113. const auto thisOS = TargetOS::getThisOS();
  114. const auto selectedOS = getSelectedOS();
  115. auto& settings = getAppSettings();
  116. if (selectedOS == thisOS)
  117. {
  118. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::defaultJuceModulePath),
  119. "JUCE Modules", true)));
  120. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::defaultUserModulePath),
  121. "User Modules", true, {}, {}, true)));
  122. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::vst3Path),
  123. "VST3 SDK", true)));
  124. if (selectedOS == TargetOS::linux)
  125. {
  126. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (Value(), "RTAS SDK", true)));
  127. pathPropertyComponents.getLast()->setEnabled (false);
  128. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (Value(), "AAX SDK", true)));
  129. pathPropertyComponents.getLast()->setEnabled (false);
  130. }
  131. else
  132. {
  133. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::rtasPath),
  134. "RTAS SDK", true)));
  135. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::aaxPath),
  136. "AAX SDK", true)));
  137. }
  138. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::androidSDKPath),
  139. "Android SDK", true)));
  140. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::androidNDKPath),
  141. "Android NDK", true)));
  142. #if JUCE_MAC
  143. String exeLabel ("app");
  144. #elif JUCE_WINDOWS
  145. String exeLabel ("executable");
  146. #else
  147. String exeLabel ("startup script");
  148. #endif
  149. addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::clionExePath),
  150. "CLion " + exeLabel, false)));
  151. }
  152. else
  153. {
  154. auto maxChars = 1024;
  155. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::defaultJuceModulePath, selectedOS),
  156. "JUCE Modules", maxChars, false)));
  157. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::defaultUserModulePath, selectedOS),
  158. "User Modules", maxChars, false)));
  159. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::vst3Path, selectedOS),
  160. "VST3 SDK", maxChars, false)));
  161. if (selectedOS == TargetOS::linux)
  162. {
  163. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (Value(), "RTAS SDK", maxChars, false)));
  164. pathPropertyComponents.getLast()->setEnabled (false);
  165. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (Value(), "AAX SDK", maxChars, false)));
  166. pathPropertyComponents.getLast()->setEnabled (false);
  167. }
  168. else
  169. {
  170. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::rtasPath, selectedOS),
  171. "RTAS SDK", maxChars, false)));
  172. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::aaxPath, selectedOS),
  173. "AAX SDK", maxChars, false)));
  174. }
  175. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::androidSDKPath, selectedOS),
  176. "Android SDK", maxChars, false)));
  177. addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::androidNDKPath, selectedOS),
  178. "Android NDK", maxChars, false)));
  179. }
  180. resized();
  181. }
  182. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalSearchPathsWindowComponent)
  183. };