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.

101 lines
3.8KB

  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. bool DependencyPathValueSource::isValidPath() const
  20. {
  21. // if we are on another OS than the one which this path setting is for,
  22. // we have no way of knowing whether the path is valid - so just assume it is:
  23. if (! appliesToThisOS())
  24. return true;
  25. return PathSettingsTab::checkPathByKey (globalKey, getValue().toString());
  26. }
  27. //==============================================================================
  28. DependencyPathPropertyComponent::DependencyPathPropertyComponent (const Value& value,
  29. const String& propertyName,
  30. const String& globalKey,
  31. DependencyPathOS os)
  32. : TextPropertyComponent (propertyName, 1024, false),
  33. pathValueSource (new DependencyPathValueSource (value,
  34. PathSettingsTab::getPathByKey (globalKey, os),
  35. PathSettingsTab::getFallbackPathByKey (globalKey, os),
  36. globalKey,
  37. os)),
  38. pathValue (pathValueSource)
  39. {
  40. bool initialValueIsEmpty = value.toString().isEmpty();
  41. getValue().referTo (pathValue);
  42. if (initialValueIsEmpty)
  43. getValue().setValue (String::empty);
  44. getValue().addListener (this);
  45. setColour (textColourId, getTextColourToDisplay());
  46. if (Label* label = dynamic_cast<Label*> (getChildComponent (0)))
  47. label->addListener (this);
  48. else
  49. jassertfalse;
  50. }
  51. void DependencyPathPropertyComponent::valueChanged (Value& value)
  52. {
  53. // this callback handles the update of this setting in case
  54. // the user changed the global preferences.
  55. if (value.refersToSameSourceAs (pathValue) && pathValueSource->isUsingGlobalSettings())
  56. textWasEdited();
  57. }
  58. void DependencyPathPropertyComponent::textWasEdited()
  59. {
  60. setColour (textColourId, getTextColourToDisplay());
  61. TextPropertyComponent::textWasEdited();
  62. }
  63. Colour DependencyPathPropertyComponent::getTextColourToDisplay() const
  64. {
  65. if (! pathValueSource->isUsingProjectSettings())
  66. return pathValueSource->isValidPath() ? Colours::grey
  67. : Colours::lightpink;
  68. return pathValueSource->isValidPath() ? Colours::black
  69. : Colours::red;
  70. }
  71. void DependencyPathPropertyComponent::labelTextChanged (Label*)
  72. {
  73. }
  74. void DependencyPathPropertyComponent::editorShown (Label* /*label*/, TextEditor& editor)
  75. {
  76. if (! pathValueSource->isUsingProjectSettings())
  77. editor.setText (String::empty, dontSendNotification);
  78. }
  79. void DependencyPathPropertyComponent::editorHidden (Label*, TextEditor&)
  80. {
  81. }