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.

180 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  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) override
  32. {
  33. document.perform (new CompNameChangeAction (component, *document.getComponentLayout(), newText),
  34. "Change component name");
  35. }
  36. String getText() const override
  37. {
  38. return component->getName();
  39. }
  40. private:
  41. class CompNameChangeAction : public ComponentUndoableAction <Component>
  42. {
  43. public:
  44. CompNameChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  45. : ComponentUndoableAction <Component> (comp, l),
  46. newName (nm), oldName (comp->getName())
  47. {
  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) override
  75. {
  76. document.perform (new CompMemberNameChangeAction (component, *document.getComponentLayout(), newText),
  77. "Change component member name");
  78. }
  79. String getText() const override
  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& l, const String& nm)
  88. : ComponentUndoableAction <Component> (comp, l),
  89. newName (nm), oldName (layout.getComponentMemberVariableName (comp))
  90. {
  91. }
  92. bool perform()
  93. {
  94. showCorrectTab();
  95. layout.setComponentMemberVariableName (getComponent(), newName);
  96. return true;
  97. }
  98. bool undo()
  99. {
  100. showCorrectTab();
  101. layout.setComponentMemberVariableName (getComponent(), oldName);
  102. return true;
  103. }
  104. String newName, oldName;
  105. };
  106. };
  107. //==============================================================================
  108. class ComponentVirtualClassProperty : public ComponentTextProperty <Component>
  109. {
  110. public:
  111. ComponentVirtualClassProperty (Component* comp, JucerDocument& doc)
  112. : ComponentTextProperty <Component> ("virtual class", 40, false, comp, doc)
  113. {
  114. }
  115. void setText (const String& newText) override
  116. {
  117. document.perform (new CompVirtualClassChangeAction (component, *document.getComponentLayout(), newText),
  118. "Change component virtual class name");
  119. }
  120. String getText() const override
  121. {
  122. return document.getComponentLayout()->getComponentVirtualClassName (component);
  123. }
  124. private:
  125. class CompVirtualClassChangeAction : public ComponentUndoableAction <Component>
  126. {
  127. public:
  128. CompVirtualClassChangeAction (Component* const comp, ComponentLayout& l, const String& nm)
  129. : ComponentUndoableAction <Component> (comp, l),
  130. newName (nm), oldName (layout.getComponentVirtualClassName (comp))
  131. {
  132. }
  133. bool perform()
  134. {
  135. showCorrectTab();
  136. layout.setComponentVirtualClassName (getComponent(), newName);
  137. return true;
  138. }
  139. bool undo()
  140. {
  141. showCorrectTab();
  142. layout.setComponentVirtualClassName (getComponent(), oldName);
  143. return true;
  144. }
  145. String newName, oldName;
  146. };
  147. };