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.

187 lines
5.6KB

  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& layout, const String& newName_)
  44. : ComponentUndoableAction <Component> (comp, layout),
  45. newName (newName_)
  46. {
  47. oldName = comp->getName();
  48. }
  49. bool perform()
  50. {
  51. showCorrectTab();
  52. getComponent()->setName (newName);
  53. changed();
  54. return true;
  55. }
  56. bool undo()
  57. {
  58. showCorrectTab();
  59. getComponent()->setName (oldName);
  60. changed();
  61. return true;
  62. }
  63. String newName, oldName;
  64. };
  65. };
  66. //==============================================================================
  67. class ComponentMemberNameProperty : public ComponentTextProperty <Component>
  68. {
  69. public:
  70. ComponentMemberNameProperty (Component* comp, JucerDocument& doc)
  71. : ComponentTextProperty <Component> ("member name", 40, false, comp, doc)
  72. {
  73. }
  74. void setText (const String& newText)
  75. {
  76. document.perform (new CompMemberNameChangeAction (component, *document.getComponentLayout(), newText),
  77. "Change component member name");
  78. }
  79. String getText() const
  80. {
  81. return document.getComponentLayout()->getComponentMemberVariableName (component);
  82. }
  83. private:
  84. class CompMemberNameChangeAction : public ComponentUndoableAction <Component>
  85. {
  86. public:
  87. CompMemberNameChangeAction (Component* const comp, ComponentLayout& layout, const String& newName_)
  88. : ComponentUndoableAction <Component> (comp, layout),
  89. newName (newName_)
  90. {
  91. oldName = layout.getComponentMemberVariableName (comp);
  92. }
  93. bool perform()
  94. {
  95. showCorrectTab();
  96. layout.setComponentMemberVariableName (getComponent(), newName);
  97. return true;
  98. }
  99. bool undo()
  100. {
  101. showCorrectTab();
  102. layout.setComponentMemberVariableName (getComponent(), oldName);
  103. return true;
  104. }
  105. String newName, oldName;
  106. };
  107. };
  108. //==============================================================================
  109. class ComponentVirtualClassProperty : public ComponentTextProperty <Component>
  110. {
  111. public:
  112. ComponentVirtualClassProperty (Component* comp, JucerDocument& doc)
  113. : ComponentTextProperty <Component> ("virtual class", 40, false, comp, doc)
  114. {
  115. }
  116. void setText (const String& newText)
  117. {
  118. document.perform (new CompVirtualClassChangeAction (component, *document.getComponentLayout(), newText),
  119. "Change component virtual class name");
  120. }
  121. String getText() const
  122. {
  123. return document.getComponentLayout()->getComponentVirtualClassName (component);
  124. }
  125. private:
  126. class CompVirtualClassChangeAction : public ComponentUndoableAction <Component>
  127. {
  128. public:
  129. CompVirtualClassChangeAction (Component* const comp, ComponentLayout& layout, const String& newName_)
  130. : ComponentUndoableAction <Component> (comp, layout),
  131. newName (newName_)
  132. {
  133. oldName = layout.getComponentVirtualClassName (comp);
  134. }
  135. bool perform()
  136. {
  137. showCorrectTab();
  138. layout.setComponentVirtualClassName (getComponent(), newName);
  139. return true;
  140. }
  141. bool undo()
  142. {
  143. showCorrectTab();
  144. layout.setComponentVirtualClassName (getComponent(), oldName);
  145. return true;
  146. }
  147. String newName, oldName;
  148. };
  149. };
  150. #endif // __JUCER_COMPONENTNAMEPROPERTY_JUCEHEADER__