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.

114 lines
4.1KB

  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 = value.toString().isEmpty();
  46. getValue().referTo (pathValue);
  47. if (initialValueIsEmpty)
  48. getValue().setValue (String::empty);
  49. getValue().addListener (this);
  50. setColour (textColourId, getTextColourToDisplay());
  51. if (Label* label = dynamic_cast<Label*> (getChildComponent (0)))
  52. label->addListener (this);
  53. else
  54. jassertfalse;
  55. }
  56. catch (const std::bad_cast&)
  57. {
  58. // a DependencyPathPropertyComponent must be initialised with a Value
  59. // that is referring to a DependencyPathValueSource!
  60. jassertfalse;
  61. throw;
  62. }
  63. void DependencyPathPropertyComponent::valueChanged (Value& value)
  64. {
  65. // this callback handles the update of this setting in case
  66. // the user changed the global preferences.
  67. if (value.refersToSameSourceAs (pathValue) && pathValueSource.isUsingGlobalSettings())
  68. textWasEdited();
  69. }
  70. void DependencyPathPropertyComponent::textWasEdited()
  71. {
  72. setColour (textColourId, getTextColourToDisplay());
  73. TextPropertyComponent::textWasEdited();
  74. }
  75. Colour DependencyPathPropertyComponent::getTextColourToDisplay() const
  76. {
  77. if (! pathValueSource.isUsingProjectSettings())
  78. return pathValueSource.isValidPath() ? Colours::grey
  79. : Colours::lightpink;
  80. return pathValueSource.isValidPath() ? Colours::black
  81. : Colours::red;
  82. }
  83. void DependencyPathPropertyComponent::labelTextChanged (Label*)
  84. {
  85. }
  86. void DependencyPathPropertyComponent::editorShown (Label* /*label*/, TextEditor& editor)
  87. {
  88. if (! pathValueSource.isUsingProjectSettings())
  89. editor.setText (String::empty, dontSendNotification);
  90. }
  91. void DependencyPathPropertyComponent::editorHidden (Label*, TextEditor&)
  92. {
  93. }