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.

172 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "jucer_ComponentTypeHandler.h"
  15. #include "jucer_ComponentUndoableAction.h"
  16. #include "../Properties/jucer_ComponentTextProperty.h"
  17. //==============================================================================
  18. class ComponentNameProperty : public ComponentTextProperty <Component>
  19. {
  20. public:
  21. ComponentNameProperty (Component* comp, JucerDocument& doc)
  22. : ComponentTextProperty <Component> ("name", 40, false, comp, doc)
  23. {
  24. }
  25. void setText (const String& newText) override
  26. {
  27. document.perform (new CompNameChangeAction (component, *document.getComponentLayout(), newText),
  28. "Change component name");
  29. }
  30. String getText() const override
  31. {
  32. return component->getName();
  33. }
  34. private:
  35. class CompNameChangeAction : public ComponentUndoableAction <Component>
  36. {
  37. public:
  38. CompNameChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  39. : ComponentUndoableAction <Component> (comp, l),
  40. newName (nm), oldName (comp->getName())
  41. {
  42. }
  43. bool perform()
  44. {
  45. showCorrectTab();
  46. getComponent()->setName (newName);
  47. changed();
  48. return true;
  49. }
  50. bool undo()
  51. {
  52. showCorrectTab();
  53. getComponent()->setName (oldName);
  54. changed();
  55. return true;
  56. }
  57. String newName, oldName;
  58. };
  59. };
  60. //==============================================================================
  61. class ComponentMemberNameProperty : public ComponentTextProperty <Component>
  62. {
  63. public:
  64. ComponentMemberNameProperty (Component* comp, JucerDocument& doc)
  65. : ComponentTextProperty <Component> ("member name", 40, false, comp, doc)
  66. {
  67. }
  68. void setText (const String& newText) override
  69. {
  70. document.perform (new CompMemberNameChangeAction (component, *document.getComponentLayout(), newText),
  71. "Change component member name");
  72. }
  73. String getText() const override
  74. {
  75. return document.getComponentLayout()->getComponentMemberVariableName (component);
  76. }
  77. private:
  78. class CompMemberNameChangeAction : public ComponentUndoableAction <Component>
  79. {
  80. public:
  81. CompMemberNameChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  82. : ComponentUndoableAction <Component> (comp, l),
  83. newName (nm), oldName (layout.getComponentMemberVariableName (comp))
  84. {
  85. }
  86. bool perform()
  87. {
  88. showCorrectTab();
  89. layout.setComponentMemberVariableName (getComponent(), newName);
  90. return true;
  91. }
  92. bool undo()
  93. {
  94. showCorrectTab();
  95. layout.setComponentMemberVariableName (getComponent(), oldName);
  96. return true;
  97. }
  98. String newName, oldName;
  99. };
  100. };
  101. //==============================================================================
  102. class ComponentVirtualClassProperty : public ComponentTextProperty <Component>
  103. {
  104. public:
  105. ComponentVirtualClassProperty (Component* comp, JucerDocument& doc)
  106. : ComponentTextProperty <Component> ("virtual class", 40, false, comp, doc)
  107. {
  108. }
  109. void setText (const String& newText) override
  110. {
  111. document.perform (new CompVirtualClassChangeAction (component, *document.getComponentLayout(), newText),
  112. "Change component virtual class name");
  113. }
  114. String getText() const override
  115. {
  116. return document.getComponentLayout()->getComponentVirtualClassName (component);
  117. }
  118. private:
  119. class CompVirtualClassChangeAction : public ComponentUndoableAction <Component>
  120. {
  121. public:
  122. CompVirtualClassChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  123. : ComponentUndoableAction <Component> (comp, l),
  124. newName (nm), oldName (layout.getComponentVirtualClassName (comp))
  125. {
  126. }
  127. bool perform()
  128. {
  129. showCorrectTab();
  130. layout.setComponentVirtualClassName (getComponent(), newName);
  131. return true;
  132. }
  133. bool undo()
  134. {
  135. showCorrectTab();
  136. layout.setComponentVirtualClassName (getComponent(), oldName);
  137. return true;
  138. }
  139. String newName, oldName;
  140. };
  141. };