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.

184 lines
5.5KB

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