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.

92 lines
3.2KB

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