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.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  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) override
  31. {
  32. document.perform (new CompNameChangeAction (component, *document.getComponentLayout(), newText),
  33. "Change component name");
  34. }
  35. String getText() const override
  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) override
  74. {
  75. document.perform (new CompMemberNameChangeAction (component, *document.getComponentLayout(), newText),
  76. "Change component member name");
  77. }
  78. String getText() const override
  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) override
  115. {
  116. document.perform (new CompVirtualClassChangeAction (component, *document.getComponentLayout(), newText),
  117. "Change component virtual class name");
  118. }
  119. String getText() const override
  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. };