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.

320 lines
13KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. #include "../../Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h"
  20. //==============================================================================
  21. class GlobalPathsWindowComponent : public Component,
  22. private Timer,
  23. private Value::Listener,
  24. private ChangeListener
  25. {
  26. public:
  27. GlobalPathsWindowComponent()
  28. {
  29. addChildComponent (rescanJUCEPathButton);
  30. rescanJUCEPathButton.onClick = [this]
  31. {
  32. ProjucerApplication::getApp().rescanJUCEPathModules();
  33. lastJUCEModulePath = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get();
  34. };
  35. addChildComponent (rescanUserPathButton);
  36. rescanUserPathButton.onClick = [this]
  37. {
  38. ProjucerApplication::getApp().rescanUserPathModules();
  39. lastUserModulePath = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS()).get();
  40. };
  41. addChildComponent (warnAboutJUCEPathButton);
  42. warnAboutJUCEPathButton.setToggleState (ProjucerApplication::getApp().shouldPromptUserAboutIncorrectJUCEPath(),
  43. dontSendNotification);
  44. warnAboutJUCEPathButton.onClick = [this]
  45. {
  46. ProjucerApplication::getApp().setShouldPromptUserAboutIncorrectJUCEPath (warnAboutJUCEPathButton.getToggleState());
  47. };
  48. getGlobalProperties().addChangeListener (this);
  49. addAndMakeVisible (resetToDefaultsButton);
  50. resetToDefaultsButton.onClick = [this] { resetCurrentOSPathsToDefaults(); };
  51. addAndMakeVisible (propertyViewport);
  52. propertyViewport.setViewedComponent (&propertyGroup, false);
  53. auto os = TargetOS::getThisOS();
  54. if (os == TargetOS::osx) selectedOSValue = "osx";
  55. else if (os == TargetOS::windows) selectedOSValue = "windows";
  56. else if (os == TargetOS::linux) selectedOSValue = "linux";
  57. selectedOSValue.addListener (this);
  58. buildProps();
  59. lastJUCEModulePath = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get();
  60. lastUserModulePath = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS()).get();
  61. }
  62. ~GlobalPathsWindowComponent() override
  63. {
  64. getGlobalProperties().removeChangeListener (this);
  65. auto juceValue = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS());
  66. auto userValue = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS());
  67. if (juceValue.get() != lastJUCEModulePath) ProjucerApplication::getApp().rescanJUCEPathModules();
  68. if (userValue.get() != lastUserModulePath) ProjucerApplication::getApp().rescanUserPathModules();
  69. }
  70. void paint (Graphics& g) override
  71. {
  72. g.fillAll (findColour (backgroundColourId));
  73. }
  74. void paintOverChildren (Graphics& g) override
  75. {
  76. g.setColour (findColour (defaultHighlightColourId).withAlpha (flashAlpha));
  77. g.fillRect (boundsToHighlight);
  78. }
  79. void resized() override
  80. {
  81. auto b = getLocalBounds().reduced (10);
  82. auto bottomBounds = b.removeFromBottom (80);
  83. auto buttonBounds = bottomBounds.removeFromBottom (50);
  84. rescanJUCEPathButton.setBounds (buttonBounds.removeFromLeft (150).reduced (5, 10));
  85. rescanUserPathButton.setBounds (buttonBounds.removeFromLeft (150).reduced (5, 10));
  86. resetToDefaultsButton.setBounds (buttonBounds.removeFromRight (150).reduced (5, 10));
  87. warnAboutJUCEPathButton.setBounds (bottomBounds.reduced (0, 5));
  88. warnAboutJUCEPathButton.changeWidthToFitText();
  89. propertyGroup.updateSize (0, 0, getWidth() - 20 - propertyViewport.getScrollBarThickness());
  90. propertyViewport.setBounds (b);
  91. }
  92. void highlightJUCEPath()
  93. {
  94. if (isTimerRunning() || ! isSelectedOSThisOS())
  95. return;
  96. const auto findJucePathPropertyComponent = [this]() -> PropertyComponent*
  97. {
  98. for (const auto& prop : propertyGroup.getProperties())
  99. if (prop->getName() == "Path to JUCE")
  100. return prop.get();
  101. return nullptr;
  102. };
  103. if (auto* propComponent = findJucePathPropertyComponent())
  104. {
  105. boundsToHighlight = getLocalArea (nullptr, propComponent->getScreenBounds());
  106. flashAlpha = 0.0f;
  107. hasFlashed = false;
  108. startTimer (25);
  109. }
  110. }
  111. private:
  112. //==============================================================================
  113. void timerCallback() override
  114. {
  115. flashAlpha += (hasFlashed ? -0.05f : 0.05f);
  116. if (flashAlpha > 0.75f)
  117. {
  118. hasFlashed = true;
  119. }
  120. else if (flashAlpha < 0.0f)
  121. {
  122. flashAlpha = 0.0f;
  123. boundsToHighlight = {};
  124. stopTimer();
  125. }
  126. repaint();
  127. }
  128. void valueChanged (Value&) override
  129. {
  130. buildProps();
  131. resized();
  132. }
  133. void changeListenerCallback (ChangeBroadcaster*) override
  134. {
  135. warnAboutJUCEPathButton.setToggleState (ProjucerApplication::getApp().shouldPromptUserAboutIncorrectJUCEPath(),
  136. dontSendNotification);
  137. }
  138. //==============================================================================
  139. bool isSelectedOSThisOS() { return TargetOS::getThisOS() == getSelectedOS(); }
  140. TargetOS::OS getSelectedOS() const
  141. {
  142. auto val = selectedOSValue.getValue();
  143. if (val == "osx") return TargetOS::osx;
  144. else if (val == "windows") return TargetOS::windows;
  145. else if (val == "linux") return TargetOS::linux;
  146. jassertfalse;
  147. return TargetOS::unknown;
  148. }
  149. //==============================================================================
  150. void buildProps()
  151. {
  152. updateValues();
  153. PropertyListBuilder builder;
  154. auto isThisOS = isSelectedOSThisOS();
  155. builder.add (new ChoicePropertyComponent (selectedOSValue, "OS", { "OSX", "Windows", "Linux" }, { "osx", "windows", "linux" }),
  156. "Use this dropdown to set the global paths for different OSes. "
  157. "\nN.B. These paths are stored locally and will only be used when "
  158. "saving a project on this machine. Other machines will have their own "
  159. "locally stored paths.");
  160. builder.add (new LabelPropertyComponent ("JUCE"), {});
  161. builder.add (new FilePathPropertyComponent (jucePathValue, "Path to JUCE", true, isThisOS),
  162. "This should be the path to the top-level directory of your JUCE folder. "
  163. "This path will be used when searching for the JUCE examples and DemoRunner application.");
  164. builder.add (new FilePathPropertyComponent (juceModulePathValue, "JUCE Modules", true, isThisOS),
  165. String ("This should be the path to the folder containing the JUCE modules that you wish to use, typically the \"modules\" directory of your JUCE folder.")
  166. + (isThisOS ? " Use the button below to re-scan a new path." : ""));
  167. builder.add (new FilePathPropertyComponent (userModulePathValue, "User Modules", true, isThisOS),
  168. String ("A path to a folder containing any custom modules that you wish to use.")
  169. + (isThisOS ? " Use the button below to re-scan new paths." : ""));
  170. builder.add (new LabelPropertyComponent ("SDKs"), {});
  171. builder.add (new FilePathPropertyComponent (vstPathValue, "VST (Legacy) SDK", true, isThisOS),
  172. "If you are building a legacy VST plug-in then this path should point to a VST2 SDK. "
  173. "The VST2 SDK can be obtained from the vstsdk3610_11_06_2018_build_37 (or older) VST3 SDK or JUCE version 5.3.2. "
  174. "You also need a VST2 license from Steinberg to distribute VST2 plug-ins.");
  175. builder.add (new FilePathPropertyComponent (araPathValue, "ARA SDK", true, isThisOS),
  176. "If you are building ARA enabled plug-ins, this should be the path to the ARA SDK folder.");
  177. if (getSelectedOS() != TargetOS::linux)
  178. {
  179. builder.add (new FilePathPropertyComponent (aaxPathValue, "AAX SDK", true, isThisOS),
  180. "If you are building AAX plug-ins, this should be the path to the AAX SDK folder.");
  181. }
  182. builder.add (new FilePathPropertyComponent (androidSDKPathValue, "Android SDK", true, isThisOS),
  183. "This path will be used when writing the local.properties file of an Android project and should point to the Android SDK folder.");
  184. if (isThisOS)
  185. {
  186. builder.add (new LabelPropertyComponent ("Other"), {});
  187. #if JUCE_MAC
  188. String exeLabel ("app");
  189. #elif JUCE_WINDOWS
  190. String exeLabel ("executable");
  191. #else
  192. String exeLabel ("startup script");
  193. #endif
  194. builder.add (new FilePathPropertyComponent (clionExePathValue, "CLion " + exeLabel, false, isThisOS),
  195. "This path will be used for the \"Save Project and Open in IDE...\" option of the CLion exporter.");
  196. builder.add (new FilePathPropertyComponent (androidStudioExePathValue, "Android Studio " + exeLabel, false, isThisOS),
  197. "This path will be used for the \"Save Project and Open in IDE...\" option of the Android Studio exporter.");
  198. }
  199. rescanJUCEPathButton.setVisible (isThisOS);
  200. rescanUserPathButton.setVisible (isThisOS);
  201. warnAboutJUCEPathButton.setVisible (isThisOS);
  202. propertyGroup.setProperties (builder);
  203. }
  204. void updateValues()
  205. {
  206. auto& settings = getAppSettings();
  207. auto os = getSelectedOS();
  208. jucePathValue = settings.getStoredPath (Ids::jucePath, os);
  209. juceModulePathValue = settings.getStoredPath (Ids::defaultJuceModulePath, os);
  210. userModulePathValue = settings.getStoredPath (Ids::defaultUserModulePath, os);
  211. vstPathValue = settings.getStoredPath (Ids::vstLegacyPath, os);
  212. aaxPathValue = settings.getStoredPath (Ids::aaxPath, os);
  213. araPathValue = settings.getStoredPath (Ids::araPath, os);
  214. androidSDKPathValue = settings.getStoredPath (Ids::androidSDKPath, os);
  215. clionExePathValue = settings.getStoredPath (Ids::clionExePath, os);
  216. androidStudioExePathValue = settings.getStoredPath (Ids::androidStudioExePath, os);
  217. }
  218. void resetCurrentOSPathsToDefaults()
  219. {
  220. jucePathValue .resetToDefault();
  221. juceModulePathValue .resetToDefault();
  222. userModulePathValue .resetToDefault();
  223. vstPathValue .resetToDefault();
  224. aaxPathValue .resetToDefault();
  225. araPathValue .resetToDefault();
  226. androidSDKPathValue .resetToDefault();
  227. clionExePathValue .resetToDefault();
  228. androidStudioExePathValue.resetToDefault();
  229. repaint();
  230. }
  231. //==============================================================================
  232. Value selectedOSValue;
  233. ValueTreePropertyWithDefault jucePathValue, juceModulePathValue, userModulePathValue,
  234. vstPathValue, aaxPathValue, araPathValue, androidSDKPathValue,
  235. clionExePathValue, androidStudioExePathValue;
  236. Viewport propertyViewport;
  237. PropertyGroupComponent propertyGroup { "Global Paths", { getIcons().openFolder, Colours::transparentBlack } };
  238. ToggleButton warnAboutJUCEPathButton { "Warn about incorrect JUCE path" };
  239. TextButton rescanJUCEPathButton { "Re-scan JUCE Modules" },
  240. rescanUserPathButton { "Re-scan User Modules" },
  241. resetToDefaultsButton { "Reset to Defaults" };
  242. Rectangle<int> boundsToHighlight;
  243. float flashAlpha = 0.0f;
  244. bool hasFlashed = false;
  245. var lastJUCEModulePath, lastUserModulePath;
  246. //==============================================================================
  247. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalPathsWindowComponent)
  248. };