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.

201 lines
9.2KB

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