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.

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