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.

179 lines
5.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 "jucer_ComponentTypeHandler.h"
  19. #include "jucer_ComponentUndoableAction.h"
  20. #include "../properties/jucer_ComponentTextProperty.h"
  21. //==============================================================================
  22. class ComponentNameProperty : public ComponentTextProperty <Component>
  23. {
  24. public:
  25. ComponentNameProperty (Component* comp, JucerDocument& doc)
  26. : ComponentTextProperty <Component> ("name", 40, false, comp, doc)
  27. {
  28. }
  29. void setText (const String& newText) override
  30. {
  31. document.perform (new CompNameChangeAction (component, *document.getComponentLayout(), newText),
  32. "Change component name");
  33. }
  34. String getText() const override
  35. {
  36. return component->getName();
  37. }
  38. private:
  39. class CompNameChangeAction : public ComponentUndoableAction <Component>
  40. {
  41. public:
  42. CompNameChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  43. : ComponentUndoableAction <Component> (comp, l),
  44. newName (nm), oldName (comp->getName())
  45. {
  46. }
  47. bool perform()
  48. {
  49. showCorrectTab();
  50. getComponent()->setName (newName);
  51. changed();
  52. return true;
  53. }
  54. bool undo()
  55. {
  56. showCorrectTab();
  57. getComponent()->setName (oldName);
  58. changed();
  59. return true;
  60. }
  61. String newName, oldName;
  62. };
  63. };
  64. //==============================================================================
  65. class ComponentMemberNameProperty : public ComponentTextProperty <Component>
  66. {
  67. public:
  68. ComponentMemberNameProperty (Component* comp, JucerDocument& doc)
  69. : ComponentTextProperty <Component> ("member name", 40, false, comp, doc)
  70. {
  71. }
  72. void setText (const String& newText) override
  73. {
  74. document.perform (new CompMemberNameChangeAction (component, *document.getComponentLayout(), newText),
  75. "Change component member name");
  76. }
  77. String getText() const override
  78. {
  79. return document.getComponentLayout()->getComponentMemberVariableName (component);
  80. }
  81. private:
  82. class CompMemberNameChangeAction : public ComponentUndoableAction <Component>
  83. {
  84. public:
  85. CompMemberNameChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  86. : ComponentUndoableAction <Component> (comp, l),
  87. newName (nm), oldName (layout.getComponentMemberVariableName (comp))
  88. {
  89. }
  90. bool perform()
  91. {
  92. showCorrectTab();
  93. layout.setComponentMemberVariableName (getComponent(), newName);
  94. return true;
  95. }
  96. bool undo()
  97. {
  98. showCorrectTab();
  99. layout.setComponentMemberVariableName (getComponent(), oldName);
  100. return true;
  101. }
  102. String newName, oldName;
  103. };
  104. };
  105. //==============================================================================
  106. class ComponentVirtualClassProperty : public ComponentTextProperty <Component>
  107. {
  108. public:
  109. ComponentVirtualClassProperty (Component* comp, JucerDocument& doc)
  110. : ComponentTextProperty <Component> ("virtual class", 40, false, comp, doc)
  111. {
  112. }
  113. void setText (const String& newText) override
  114. {
  115. document.perform (new CompVirtualClassChangeAction (component, *document.getComponentLayout(), newText),
  116. "Change component virtual class name");
  117. }
  118. String getText() const override
  119. {
  120. return document.getComponentLayout()->getComponentVirtualClassName (component);
  121. }
  122. private:
  123. class CompVirtualClassChangeAction : public ComponentUndoableAction <Component>
  124. {
  125. public:
  126. CompVirtualClassChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  127. : ComponentUndoableAction <Component> (comp, l),
  128. newName (nm), oldName (layout.getComponentVirtualClassName (comp))
  129. {
  130. }
  131. bool perform()
  132. {
  133. showCorrectTab();
  134. layout.setComponentVirtualClassName (getComponent(), newName);
  135. return true;
  136. }
  137. bool undo()
  138. {
  139. showCorrectTab();
  140. layout.setComponentVirtualClassName (getComponent(), oldName);
  141. return true;
  142. }
  143. String newName, oldName;
  144. };
  145. };