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.

203 lines
9.3KB

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