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.

76 lines
2.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. #include "../ui/jucer_JucerDocumentEditor.h"
  19. //==============================================================================
  20. template <class ComponentType>
  21. class ComponentUndoableAction : public UndoableAction
  22. {
  23. public:
  24. ComponentUndoableAction (ComponentType* const comp,
  25. ComponentLayout& layout_)
  26. : layout (layout_),
  27. componentIndex (layout_.indexOfComponent (comp))
  28. {
  29. jassert (comp != nullptr);
  30. jassert (componentIndex >= 0);
  31. }
  32. ComponentType* getComponent() const
  33. {
  34. ComponentType* const c = dynamic_cast<ComponentType*> (layout.getComponent (componentIndex));
  35. jassert (c != nullptr);
  36. return c;
  37. }
  38. int getSizeInUnits() { return 2; }
  39. protected:
  40. ComponentLayout& layout;
  41. const int componentIndex;
  42. void changed() const
  43. {
  44. jassert (layout.getDocument() != nullptr);
  45. layout.getDocument()->changed();
  46. }
  47. void showCorrectTab() const
  48. {
  49. if (JucerDocumentEditor* const ed = JucerDocumentEditor::getActiveDocumentHolder())
  50. ed->showLayout();
  51. if (layout.getSelectedSet().getNumSelected() == 0)
  52. if (ComponentType* const c = dynamic_cast<ComponentType*> (layout.getComponent (componentIndex)))
  53. layout.getSelectedSet().selectOnly (getComponent());
  54. }
  55. private:
  56. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentUndoableAction)
  57. };