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.

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