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.

99 lines
3.7KB

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