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.

256 lines
8.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../jucer_Headers.h"
  19. #include "../../model/Drawable/jucer_DrawableDocument.h"
  20. #include "../jucer_JucerTreeViewBase.h"
  21. #include "../Editor Base/jucer_EditorPanel.h"
  22. #include "../Editor Base/jucer_EditorCanvas.h"
  23. #include "../Editor Base/jucer_EditorDragOperation.h"
  24. #include "jucer_DrawableEditor.h"
  25. #include "jucer_DrawableEditorCanvas.h"
  26. #include "jucer_DrawableEditorTreeView.h"
  27. #include "jucer_DrawableEditorToolbar.h"
  28. //==============================================================================
  29. class DrawableEditor::Panel : public EditorPanelBase
  30. {
  31. public:
  32. Panel (DrawableEditor& editor_)
  33. : toolbarFactory (editor_),
  34. editor (editor_)
  35. {
  36. }
  37. ~Panel()
  38. {
  39. shutdown();
  40. }
  41. void createCanvas()
  42. {
  43. initialise (new DrawableEditorCanvas (editor), toolbarFactory,
  44. new DrawableTreeViewItem (editor, editor.getDocument().getRootDrawableNode()));
  45. }
  46. SelectedItemSet<String>& getSelection()
  47. {
  48. return editor.getSelection();
  49. }
  50. void getSelectedItemProperties (Array<PropertyComponent*>& newComps)
  51. {
  52. //editor.getSelectedItemProperties (newComps);
  53. }
  54. private:
  55. DrawableEditorToolbarFactory toolbarFactory;
  56. DrawableEditor& editor;
  57. };
  58. //==============================================================================
  59. DrawableEditor::DrawableEditor (OpenDocumentManager::Document* document_,
  60. Project* project_,
  61. DrawableDocument* drawableDocument_)
  62. : DocumentEditorComponent (document_),
  63. project (project_),
  64. drawableDocument (drawableDocument_)
  65. {
  66. jassert (drawableDocument_ != 0);
  67. setOpaque (true);
  68. addAndMakeVisible (panel = new Panel (*this));
  69. panel->createCanvas();
  70. }
  71. DrawableEditor::~DrawableEditor()
  72. {
  73. deleteAllChildren();
  74. }
  75. void DrawableEditor::paint (Graphics& g)
  76. {
  77. g.fillAll (Colours::white);
  78. }
  79. void DrawableEditor::resized()
  80. {
  81. panel->setBounds (getLocalBounds());
  82. }
  83. //==============================================================================
  84. void DrawableEditor::deleteSelection()
  85. {
  86. }
  87. void DrawableEditor::selectionToFront()
  88. {
  89. }
  90. void DrawableEditor::selectionToBack()
  91. {
  92. }
  93. void DrawableEditor::showNewShapeMenu (Component* componentToAttachTo)
  94. {
  95. /*
  96. PopupMenu m;
  97. getDocument().addNewComponentMenuItems (m);
  98. const int r = m.showAt (componentToAttachTo);
  99. const ValueTree newComp (getDocument().performNewComponentMenuItem (r));
  100. if (newComp.isValid())
  101. getSelection().selectOnly (newComp [ComponentDocument::idProperty]);
  102. */
  103. }
  104. //==============================================================================
  105. void DrawableEditor::getAllCommands (Array <CommandID>& commands)
  106. {
  107. DocumentEditorComponent::getAllCommands (commands);
  108. const CommandID ids[] = { CommandIDs::undo,
  109. CommandIDs::redo,
  110. CommandIDs::toFront,
  111. CommandIDs::toBack,
  112. CommandIDs::showOrHideProperties,
  113. CommandIDs::showOrHideTree,
  114. CommandIDs::showOrHideMarkers,
  115. CommandIDs::toggleSnapping,
  116. StandardApplicationCommandIDs::del };
  117. commands.addArray (ids, numElementsInArray (ids));
  118. }
  119. void DrawableEditor::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
  120. {
  121. result.setActive (document != 0);
  122. switch (commandID)
  123. {
  124. case CommandIDs::undo:
  125. result.setInfo ("Undo", "Undoes the last change", CommandCategories::general, 0);
  126. result.defaultKeypresses.add (KeyPress ('z', ModifierKeys::commandModifier, 0));
  127. break;
  128. case CommandIDs::redo:
  129. result.setInfo ("Redo", "Redoes the last change", CommandCategories::general, 0);
  130. result.defaultKeypresses.add (KeyPress ('z', ModifierKeys::shiftModifier | ModifierKeys::commandModifier, 0));
  131. result.defaultKeypresses.add (KeyPress ('y', ModifierKeys::commandModifier, 0));
  132. break;
  133. case CommandIDs::toFront:
  134. result.setInfo ("Bring to Front", "Brings the selected items to the front", CommandCategories::editing, 0);
  135. break;
  136. case CommandIDs::toBack:
  137. result.setInfo ("Send to Back", "Moves the selected items to the back", CommandCategories::editing, 0);
  138. break;
  139. case CommandIDs::showOrHideProperties:
  140. result.setInfo ("Show/Hide Tree", "Shows or hides the component tree view", CommandCategories::editing, 0);
  141. result.setTicked (panel != 0 && panel->arePropertiesVisible());
  142. break;
  143. case CommandIDs::showOrHideTree:
  144. result.setInfo ("Show/Hide Properties", "Shows or hides the component properties panel", CommandCategories::editing, 0);
  145. result.setTicked (panel != 0 && panel->isTreeVisible());
  146. break;
  147. case CommandIDs::showOrHideMarkers:
  148. result.setInfo ("Show/Hide Markers", "Shows or hides the markers", CommandCategories::editing, 0);
  149. result.setTicked (panel != 0 && panel->areMarkersVisible());
  150. break;
  151. case CommandIDs::toggleSnapping:
  152. result.setInfo ("Toggle snapping", "Turns object snapping on or off", CommandCategories::editing, 0);
  153. result.setTicked (panel != 0 && panel->isSnappingEnabled());
  154. break;
  155. case StandardApplicationCommandIDs::del:
  156. result.setInfo ("Delete", String::empty, CommandCategories::general, 0);
  157. result.defaultKeypresses.add (KeyPress (KeyPress::deleteKey, 0, 0));
  158. result.defaultKeypresses.add (KeyPress (KeyPress::backspaceKey, 0, 0));
  159. break;
  160. default:
  161. DocumentEditorComponent::getCommandInfo (commandID, result);
  162. break;
  163. }
  164. }
  165. bool DrawableEditor::perform (const InvocationInfo& info)
  166. {
  167. switch (info.commandID)
  168. {
  169. case CommandIDs::undo:
  170. getDocument().getUndoManager()->beginNewTransaction();
  171. getDocument().getUndoManager()->undo();
  172. return true;
  173. case CommandIDs::redo:
  174. getDocument().getUndoManager()->beginNewTransaction();
  175. getDocument().getUndoManager()->redo();
  176. return true;
  177. case CommandIDs::toFront:
  178. selectionToFront();
  179. return true;
  180. case CommandIDs::toBack:
  181. selectionToBack();
  182. return true;
  183. case CommandIDs::showOrHideProperties:
  184. panel->showOrHideProperties();
  185. return true;
  186. case CommandIDs::showOrHideTree:
  187. panel->showOrHideTree();
  188. return true;
  189. case CommandIDs::showOrHideMarkers:
  190. panel->showOrHideMarkers();
  191. return true;
  192. case CommandIDs::toggleSnapping:
  193. panel->toggleSnapping();
  194. return true;
  195. case StandardApplicationCommandIDs::del:
  196. deleteSelection();
  197. return true;
  198. default:
  199. break;
  200. }
  201. return DocumentEditorComponent::perform (info);
  202. }