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.

117 lines
4.4KB

  1. /*
  2. ==============================================================================
  3. jucer_GlobalDefaultedTextPropertyComponent.cpp
  4. Created: 27 Jul 2015 10:42:17am
  5. Author: Joshua Gerrard
  6. ==============================================================================
  7. */
  8. #include "../jucer_Headers.h"
  9. #include "jucer_DependencyPathPropertyComponent.h"
  10. #include "../Application/jucer_GlobalPreferences.h"
  11. //==============================================================================
  12. const String DependencyPath::vst2KeyName = "vst2Path";
  13. const String DependencyPath::vst3KeyName = "vst3Path";
  14. const String DependencyPath::rtasKeyName = "rtasPath";
  15. const String DependencyPath::aaxKeyName = "aaxPath";
  16. const String DependencyPath::androidSdkKeyName = "androidSdkPath";
  17. const String DependencyPath::androidNdkKeyName = "androidNdkPath";
  18. //==============================================================================
  19. DependencyPathValueSource::DependencyPathValueSource (const Value& projectSettingsPath,
  20. String globalSettingsKey,
  21. DependencyPathOS osThisSettingAppliesTo)
  22. : projectSettingsValue (projectSettingsPath),
  23. globalKey (globalSettingsKey),
  24. os (osThisSettingAppliesTo),
  25. globalSettingsValue (PathSettingsTab::getPathByKey (globalKey, os)),
  26. fallbackValue (PathSettingsTab::getFallbackPathByKey (globalKey, os))
  27. {
  28. globalSettingsValue.addListener (this);
  29. }
  30. bool DependencyPathValueSource::isValidPath() const
  31. {
  32. // if we are on another OS than the one which this path setting is for,
  33. // we have no way of knowing whether the path is valid - so just assume it is:
  34. if (! appliesToThisOS())
  35. return true;
  36. return PathSettingsTab::checkPathByKey (globalKey, getValue().toString());
  37. }
  38. //==============================================================================
  39. DependencyPathPropertyComponent::DependencyPathPropertyComponent (const Value& value,
  40. const String& propertyName)
  41. try : TextPropertyComponent (propertyName, 1024, false),
  42. pathValue (value),
  43. pathValueSource (dynamic_cast<DependencyPathValueSource&> (pathValue.getValueSource()))
  44. {
  45. bool initialValueIsEmpty = ! pathValueSource.isUsingProjectSettings();
  46. getValue().referTo (pathValue);
  47. // the following step is necessary because the above referTo() has internally called setValue(),
  48. // which has set the project value to whatever is displayed in the label (this may be the
  49. // global/fallback value). In this case we have to reset the project value to blank:
  50. if (initialValueIsEmpty)
  51. getValue().setValue (String::empty);
  52. getValue().addListener (this);
  53. setColour (textColourId, getTextColourToDisplay());
  54. if (Label* label = dynamic_cast<Label*> (getChildComponent (0)))
  55. label->addListener (this);
  56. else
  57. jassertfalse;
  58. }
  59. catch (const std::bad_cast&)
  60. {
  61. // a DependencyPathPropertyComponent must be initialised with a Value
  62. // that is referring to a DependencyPathValueSource!
  63. jassertfalse;
  64. throw;
  65. }
  66. void DependencyPathPropertyComponent::valueChanged (Value& value)
  67. {
  68. // this callback handles the update of this setting in case
  69. // the user changed the global preferences.
  70. if (value.refersToSameSourceAs (pathValue) && pathValueSource.isUsingGlobalSettings())
  71. textWasEdited();
  72. }
  73. void DependencyPathPropertyComponent::textWasEdited()
  74. {
  75. setColour (textColourId, getTextColourToDisplay());
  76. TextPropertyComponent::textWasEdited();
  77. }
  78. Colour DependencyPathPropertyComponent::getTextColourToDisplay() const
  79. {
  80. if (! pathValueSource.isUsingProjectSettings())
  81. return pathValueSource.isValidPath() ? Colours::grey
  82. : Colours::lightpink;
  83. return pathValueSource.isValidPath() ? Colours::black
  84. : Colours::red;
  85. }
  86. void DependencyPathPropertyComponent::labelTextChanged (Label*)
  87. {
  88. }
  89. void DependencyPathPropertyComponent::editorShown (Label* /*label*/, TextEditor& editor)
  90. {
  91. if (! pathValueSource.isUsingProjectSettings())
  92. editor.setText (String::empty, dontSendNotification);
  93. }
  94. void DependencyPathPropertyComponent::editorHidden (Label*, TextEditor&)
  95. {
  96. }