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.

67 lines
1.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. //==============================================================================
  15. /**
  16. Wraps a ValueWithDefault object that has a default which depends on a global value.
  17. */
  18. class ValueWithDefaultWrapper : private Value::Listener
  19. {
  20. public:
  21. ValueWithDefaultWrapper() = default;
  22. void init (const ValueWithDefault& vwd, ValueWithDefault global, TargetOS::OS targetOS)
  23. {
  24. wrappedValue = vwd;
  25. globalValue = global.getPropertyAsValue();
  26. globalIdentifier = global.getPropertyID();
  27. os = targetOS;
  28. if (wrappedValue.get() == var())
  29. wrappedValue.resetToDefault();
  30. globalValue.addListener (this);
  31. valueChanged (globalValue);
  32. }
  33. ValueWithDefault& getWrappedValueWithDefault()
  34. {
  35. return wrappedValue;
  36. }
  37. var getCurrentValue() const
  38. {
  39. return wrappedValue.get();
  40. }
  41. private:
  42. void valueChanged (Value&) override
  43. {
  44. wrappedValue.setDefault (getAppSettings().getStoredPath (globalIdentifier, os).get());
  45. }
  46. ValueWithDefault wrappedValue;
  47. Value globalValue;
  48. Identifier globalIdentifier;
  49. TargetOS::OS os;
  50. };