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.

193 lines
6.4KB

  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. String globalSettingsKey,
  50. DependencyPathOS osThisSettingAppliesTo);
  51. /** This gets the currently used value, which may be either
  52. the project setting, the global setting, or the fallback value. */
  53. var getValue() const override
  54. {
  55. if (isUsingProjectSettings())
  56. return projectSettingsValue;
  57. if (isUsingGlobalSettings())
  58. return globalSettingsValue;
  59. return fallbackValue;
  60. }
  61. void setValue (const var& newValue) override
  62. {
  63. projectSettingsValue = newValue;
  64. if (isUsingProjectSettings())
  65. sendChangeMessage (false);
  66. }
  67. bool isUsingProjectSettings() const
  68. {
  69. return projectSettingsValueIsValid();
  70. }
  71. bool isUsingGlobalSettings() const
  72. {
  73. return ! projectSettingsValueIsValid() && globalSettingsValueIsValid();
  74. }
  75. bool isUsingFallbackValue() const
  76. {
  77. return ! projectSettingsValueIsValid() && !globalSettingsValueIsValid();
  78. }
  79. bool appliesToThisOS() const
  80. {
  81. return os == DependencyPath::getThisOS();
  82. }
  83. bool isValidPath() const;
  84. private:
  85. void valueChanged (Value& value) override
  86. {
  87. if ((value.refersToSameSourceAs (globalSettingsValue) && isUsingGlobalSettings()))
  88. {
  89. sendChangeMessage (true);
  90. setValue (String::empty); // make sure that the project-specific value is still blank
  91. }
  92. }
  93. /** This defines when to use the project setting, and when to
  94. consider it invalid and to fall back to the global setting or
  95. the fallback value. */
  96. bool projectSettingsValueIsValid() const
  97. {
  98. return ! projectSettingsValue.toString().isEmpty();
  99. }
  100. /** This defines when to use the global setting - given the project setting
  101. is invalid, and when to fall back to the fallback value instead. */
  102. bool globalSettingsValueIsValid() const
  103. {
  104. // only use the global settings if they are set on the same OS
  105. // that this setting is for!
  106. DependencyPathOS thisOS = DependencyPath::getThisOS();
  107. return thisOS == DependencyPath::unknown ? false : os == thisOS;
  108. }
  109. /** the dependency path setting as set in this Introjucer project. */
  110. Value projectSettingsValue;
  111. /** the global key used in the application settings for the global setting value.
  112. needed for checking whether the path is valid. */
  113. String globalKey;
  114. /** on what operating system should this dependency path be used?
  115. note that this is *not* the os that is targeted by the project,
  116. but rather the os on which the project will be compiled
  117. (= on which the path settings need to be set correctly). */
  118. DependencyPathOS os;
  119. /** the dependency path global setting on this machine.
  120. used when there value set for this project is invalid. */
  121. Value globalSettingsValue;
  122. /** the dependency path fallback setting. used instead of the global setting
  123. whenever the latter doesn't apply, e.g. the setting is for another
  124. OS than the ome this machine is running. */
  125. String fallbackValue;
  126. };
  127. //==============================================================================
  128. class DependencyPathPropertyComponent : public TextPropertyComponent,
  129. private Value::Listener,
  130. private Label::Listener
  131. {
  132. public:
  133. DependencyPathPropertyComponent (const Value& value,
  134. const String& propertyName);
  135. private:
  136. /** This function defines what colour the label text should assume
  137. depending on the current state of the value the component tracks. */
  138. Colour getTextColourToDisplay() const;
  139. /** This function handles path changes because of user input. */
  140. void textWasEdited() override;
  141. /** This function handles path changes because the global path changed. */
  142. void valueChanged (Value& value) override;
  143. /** the value that represents this dependency path setting. */
  144. Value pathValue;
  145. /** a reference to the value source that this value refers to. */
  146. DependencyPathValueSource& pathValueSource;
  147. // Label::Listener overrides:
  148. void labelTextChanged (Label* labelThatHasChanged) override;
  149. void editorShown (Label*, TextEditor&) override;
  150. void editorHidden (Label*, TextEditor&) override;
  151. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DependencyPathPropertyComponent)
  152. };
  153. #endif // JUCER_DEPENDENCYPATHPROPERTYCOMPONENT_H_INCLUDED