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.

82 lines
2.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_COMPONENTUNDOABLEACTION_JUCEHEADER__
  19. #define __JUCER_COMPONENTUNDOABLEACTION_JUCEHEADER__
  20. #include "../ui/jucer_JucerDocumentEditor.h"
  21. //==============================================================================
  22. template <class ComponentType>
  23. class ComponentUndoableAction : public UndoableAction
  24. {
  25. public:
  26. ComponentUndoableAction (ComponentType* const comp,
  27. ComponentLayout& layout_)
  28. : layout (layout_),
  29. componentIndex (layout_.indexOfComponent (comp))
  30. {
  31. jassert (comp != nullptr);
  32. jassert (componentIndex >= 0);
  33. }
  34. ComponentType* getComponent() const
  35. {
  36. ComponentType* const c = dynamic_cast <ComponentType*> (layout.getComponent (componentIndex));
  37. jassert (c != nullptr);
  38. return c;
  39. }
  40. int getSizeInUnits() { return 2; }
  41. protected:
  42. ComponentLayout& layout;
  43. const int componentIndex;
  44. void changed() const
  45. {
  46. jassert (layout.getDocument() != nullptr);
  47. layout.getDocument()->changed();
  48. }
  49. void showCorrectTab() const
  50. {
  51. if (JucerDocumentEditor* const ed = JucerDocumentEditor::getActiveDocumentHolder())
  52. ed->showLayout();
  53. if (layout.getSelectedSet().getNumSelected() == 0)
  54. if (ComponentType* const c = dynamic_cast <ComponentType*> (layout.getComponent (componentIndex)))
  55. layout.getSelectedSet().selectOnly (getComponent());
  56. }
  57. private:
  58. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentUndoableAction)
  59. };
  60. #endif // __JUCER_COMPONENTUNDOABLEACTION_JUCEHEADER__