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
6.8KB

  1. /*
  2. ==============================================================================
  3. jucer_GlobalDefaultedTextPropertyComponent.h
  4. Created: 27 Jul 2015 10:42:17am
  5. Author: Joshua Gerrard
  6. ==============================================================================
  7. */
  8. #ifndef JUCER_DEPENDENCYPATHPROPERTYCOMPONENT_H_INCLUDED
  9. #define JUCER_DEPENDENCYPATHPROPERTYCOMPONENT_H_INCLUDED
  10. //==============================================================================
  11. class DependencyPath
  12. {
  13. public:
  14. enum OS
  15. {
  16. windows = 0,
  17. osx,
  18. linux,
  19. unknown
  20. };
  21. static OS getThisOS()
  22. {
  23. #if JUCE_WINDOWS
  24. return DependencyPath::windows;
  25. #elif JUCE_MAC
  26. return DependencyPath::osx;
  27. #elif JUCE_LINUX
  28. return DependencyPath::linux;
  29. #else
  30. return DependencyPath::unknown;
  31. #endif
  32. }
  33. const static String vst2KeyName, vst3KeyName, rtasKeyName, aaxKeyName,
  34. androidSdkKeyName, androidNdkKeyName;
  35. };
  36. typedef DependencyPath::OS DependencyPathOS;
  37. //==============================================================================
  38. /** This ValueSource type implements the fallback logic required for dependency
  39. path settings: use the project exporter value; if this is empty, fall back to
  40. the global preference value; if the exporter is supposed to run on another
  41. OS and we don't know what the global preferences on that other machine are,
  42. fall back to a generic OS-specific fallback value.
  43. */
  44. class DependencyPathValueSource : public Value::ValueSource,
  45. private Value::Listener
  46. {
  47. public:
  48. DependencyPathValueSource (const Value& projectSettingsPath,
  49. const Value& globalSettingsPath,
  50. const String& fallbackPath,
  51. DependencyPathOS osThisSettingAppliesTo)
  52. : projectSettingsValue (projectSettingsPath),
  53. globalSettingsValue (globalSettingsPath),
  54. fallbackValue (fallbackPath),
  55. os (osThisSettingAppliesTo)
  56. {
  57. globalSettingsValue.addListener (this);
  58. }
  59. /** This gets the currently used value, which may be either
  60. the project setting, the global setting, or the fallback value. */
  61. var getValue() const override
  62. {
  63. if (isUsingProjectSettings())
  64. return projectSettingsValue;
  65. if (isUsingGlobalSettings())
  66. return globalSettingsValue;
  67. return fallbackValue;
  68. }
  69. void setValue (const var& newValue) override
  70. {
  71. projectSettingsValue = newValue;
  72. if (isUsingProjectSettings())
  73. sendChangeMessage (false);
  74. }
  75. bool isUsingProjectSettings() const
  76. {
  77. return projectSettingsValueIsValid();
  78. }
  79. bool isUsingGlobalSettings() const
  80. {
  81. return ! projectSettingsValueIsValid() && globalSettingsValueIsValid();
  82. }
  83. bool isUsingFallbackValue() const
  84. {
  85. return ! projectSettingsValueIsValid() && !globalSettingsValueIsValid();
  86. }
  87. bool appliesToThisOS() const
  88. {
  89. return os == DependencyPath::getThisOS();
  90. }
  91. private:
  92. void valueChanged (Value& value) override
  93. {
  94. if ((value.refersToSameSourceAs (globalSettingsValue) && isUsingGlobalSettings()))
  95. {
  96. sendChangeMessage (true);
  97. setValue (String::empty); // make sure that the project-specific value is still blank
  98. }
  99. }
  100. /** This defines when to use the project setting, and when to
  101. consider it invalid and to fall back to the global setting or
  102. the fallback value. */
  103. bool projectSettingsValueIsValid() const
  104. {
  105. return ! projectSettingsValue.toString().isEmpty();
  106. }
  107. /** This defines when to use the global setting - given the project setting
  108. is invalid, and when to fall back to the fallback value instead. */
  109. bool globalSettingsValueIsValid() const
  110. {
  111. // only use the global settings if they are set on the same OS
  112. // that this setting is for!
  113. DependencyPathOS thisOS = DependencyPath::getThisOS();
  114. return thisOS == DependencyPath::unknown ? false : os == thisOS;
  115. }
  116. /** the dependency path setting as set in this Introjucer project. */
  117. Value projectSettingsValue;
  118. /** the dependency path global setting on this machine.
  119. used when there value set for this project is invalid. */
  120. Value globalSettingsValue;
  121. /** the dependency path fallback setting. used instead of the global setting
  122. whenever the latter doesn't apply, e.g. the setting is for another
  123. OS than the ome this machine is running. */
  124. String fallbackValue;
  125. /** on what operating system should this dependency path be used?
  126. note that this is *not* the os that is targeted by the project,
  127. but rather the os on which the project will be compiled
  128. (= on which the path settings need to be set correctly). */
  129. DependencyPathOS os;
  130. };
  131. //==============================================================================
  132. class DependencyPathPropertyComponent : public TextPropertyComponent,
  133. private Value::Listener,
  134. private Label::Listener
  135. {
  136. public:
  137. DependencyPathPropertyComponent (const Value& value,
  138. const String& propertyName,
  139. const String& globalKey,
  140. DependencyPathOS os = DependencyPath::getThisOS());
  141. private:
  142. /** This function defines what colour the label text should assume
  143. depending on the current state of the value the component tracks. */
  144. Colour getTextColourToDisplay() const;
  145. /** This function handles path changes because of user input. */
  146. void textWasEdited() override;
  147. /** This function handles path changes because the global path changed. */
  148. void valueChanged (Value& value) override;
  149. /** Check if the current value is a valid path. */
  150. bool isValidPath() const;
  151. /** the property key of the global property that this component is tracking. */
  152. String globalKey;
  153. /** the value source of this dependency path setting. */
  154. DependencyPathValueSource* pathValueSource;
  155. /** the value object around the value source. */
  156. Value pathValue;
  157. // Label::Listener overrides:
  158. void labelTextChanged (Label* labelThatHasChanged) override;
  159. void editorShown (Label*, TextEditor&) override;
  160. void editorHidden (Label*, TextEditor&) override;
  161. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DependencyPathPropertyComponent)
  162. };
  163. #endif // JUCER_DEPENDENCYPATHPROPERTYCOMPONENT_H_INCLUDED