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.

1328 lines
49KB

  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. #include "../../Application/jucer_Headers.h"
  20. #include "../../Settings/jucer_AppearanceSettings.h"
  21. #include "../../Application/jucer_Application.h"
  22. #include "jucer_JucerDocumentEditor.h"
  23. #include "jucer_TestComponent.h"
  24. #include "../jucer_ObjectTypes.h"
  25. #include "jucer_ComponentLayoutPanel.h"
  26. #include "jucer_PaintRoutinePanel.h"
  27. #include "jucer_ResourceEditorPanel.h"
  28. #include "../Properties/jucer_ComponentTextProperty.h"
  29. #include "../Properties/jucer_ComponentChoiceProperty.h"
  30. #include "../UI/jucer_JucerCommandIDs.h"
  31. //==============================================================================
  32. class ExtraMethodsList : public PropertyComponent,
  33. public ListBoxModel,
  34. public ChangeListener
  35. {
  36. public:
  37. ExtraMethodsList (JucerDocument& doc)
  38. : PropertyComponent ("extra callbacks", 250),
  39. document (doc)
  40. {
  41. addAndMakeVisible (listBox = new ListBox (String(), this));
  42. listBox->setRowHeight (22);
  43. document.addChangeListener (this);
  44. }
  45. ~ExtraMethodsList()
  46. {
  47. document.removeChangeListener (this);
  48. }
  49. int getNumRows() override
  50. {
  51. return methods.size();
  52. }
  53. void paintListBoxItem (int row, Graphics& g, int width, int height, bool rowIsSelected) override
  54. {
  55. if (row < 0 || row >= getNumRows())
  56. return;
  57. if (rowIsSelected)
  58. {
  59. g.fillAll (findColour (TextEditor::highlightColourId));
  60. g.setColour (findColour (defaultHighlightedTextColourId));
  61. }
  62. else
  63. {
  64. g.setColour (findColour (defaultTextColourId));
  65. }
  66. g.setFont (height * 0.6f);
  67. g.drawText (returnValues [row] + " " + baseClasses [row] + "::" + methods [row],
  68. 30, 0, width - 32, height,
  69. Justification::centredLeft, true);
  70. getLookAndFeel().drawTickBox (g, *this, 6, 2, 18, 18, document.isOptionalMethodEnabled (methods [row]), true, false, false);
  71. }
  72. void listBoxItemClicked (int row, const MouseEvent& e) override
  73. {
  74. if (row < 0 || row >= getNumRows())
  75. return;
  76. if (e.x < 30)
  77. document.setOptionalMethodEnabled (methods [row],
  78. ! document.isOptionalMethodEnabled (methods [row]));
  79. }
  80. void paint (Graphics& g) override
  81. {
  82. g.fillAll (Colours::white);
  83. }
  84. void resized() override
  85. {
  86. listBox->setBounds (getLocalBounds());
  87. }
  88. void refresh() override
  89. {
  90. baseClasses.clear();
  91. returnValues.clear();
  92. methods.clear();
  93. initialContents.clear();
  94. document.getOptionalMethods (baseClasses, returnValues, methods, initialContents);
  95. listBox->updateContent();
  96. listBox->repaint();
  97. }
  98. void changeListenerCallback (ChangeBroadcaster*) override
  99. {
  100. refresh();
  101. }
  102. private:
  103. JucerDocument& document;
  104. ScopedPointer<ListBox> listBox;
  105. StringArray baseClasses, returnValues, methods, initialContents;
  106. };
  107. //==============================================================================
  108. class ClassPropertiesPanel : public Component,
  109. private ChangeListener
  110. {
  111. public:
  112. ClassPropertiesPanel (JucerDocument& doc)
  113. : document (doc)
  114. {
  115. addAndMakeVisible (panel1);
  116. addAndMakeVisible (panel2);
  117. Array <PropertyComponent*> props;
  118. props.add (new ComponentClassNameProperty (doc));
  119. props.add (new TemplateFileProperty (doc));
  120. props.add (new ComponentCompNameProperty (doc));
  121. props.add (new ComponentParentClassesProperty (doc));
  122. props.add (new ComponentConstructorParamsProperty (doc));
  123. props.add (new ComponentInitialisersProperty (doc));
  124. props.add (new ComponentInitialSizeProperty (doc, true));
  125. props.add (new ComponentInitialSizeProperty (doc, false));
  126. props.add (new FixedSizeProperty (doc));
  127. panel1.addSection ("General class settings", props);
  128. Array <PropertyComponent*> props2;
  129. props2.add (new ExtraMethodsList (doc));
  130. panel2.addSection ("Extra callback methods to generate", props2);
  131. doc.addExtraClassProperties (panel1);
  132. doc.addChangeListener (this);
  133. }
  134. ~ClassPropertiesPanel()
  135. {
  136. document.removeChangeListener (this);
  137. }
  138. void resized() override
  139. {
  140. int pw = jmin (getWidth() / 2 - 20, 350);
  141. panel1.setBounds (10, 6, pw, getHeight() - 12);
  142. panel2.setBounds (panel1.getRight() + 20, panel1.getY(), pw, panel1.getHeight());
  143. }
  144. void paint (Graphics& g) override
  145. {
  146. g.fillAll (findColour (secondaryBackgroundColourId));
  147. }
  148. void changeListenerCallback (ChangeBroadcaster*) override
  149. {
  150. panel1.refreshAll();
  151. panel2.refreshAll();
  152. }
  153. private:
  154. JucerDocument& document;
  155. PropertyPanel panel1, panel2;
  156. //==============================================================================
  157. class ComponentClassNameProperty : public ComponentTextProperty <Component>
  158. {
  159. public:
  160. ComponentClassNameProperty (JucerDocument& doc)
  161. : ComponentTextProperty <Component> ("Class name", 128, false, 0, doc)
  162. {}
  163. void setText (const String& newText) override { document.setClassName (newText); }
  164. String getText() const override { return document.getClassName(); }
  165. };
  166. //==============================================================================
  167. class ComponentCompNameProperty : public ComponentTextProperty <Component>
  168. {
  169. public:
  170. ComponentCompNameProperty (JucerDocument& doc)
  171. : ComponentTextProperty <Component> ("Component name", 200, false, 0, doc)
  172. {}
  173. void setText (const String& newText) override { document.setComponentName (newText); }
  174. String getText() const override { return document.getComponentName(); }
  175. };
  176. //==============================================================================
  177. class ComponentParentClassesProperty : public ComponentTextProperty <Component>
  178. {
  179. public:
  180. ComponentParentClassesProperty (JucerDocument& doc)
  181. : ComponentTextProperty <Component> ("Parent classes", 512, false, 0, doc)
  182. {}
  183. void setText (const String& newText) override { document.setParentClasses (newText); }
  184. String getText() const override { return document.getParentClassString(); }
  185. };
  186. //==============================================================================
  187. class ComponentConstructorParamsProperty : public ComponentTextProperty <Component>
  188. {
  189. public:
  190. ComponentConstructorParamsProperty (JucerDocument& doc)
  191. : ComponentTextProperty <Component> ("Constructor params", 2048, false, 0, doc)
  192. {}
  193. void setText (const String& newText) override { document.setConstructorParams (newText); }
  194. String getText() const override { return document.getConstructorParams(); }
  195. };
  196. //==============================================================================
  197. class ComponentInitialisersProperty : public ComponentTextProperty <Component>
  198. {
  199. public:
  200. ComponentInitialisersProperty (JucerDocument& doc)
  201. : ComponentTextProperty <Component> ("Member initialisers", 16384, true, 0, doc)
  202. {
  203. preferredHeight = 24 * 3;
  204. }
  205. void setText (const String& newText) override { document.setVariableInitialisers (newText); }
  206. String getText() const override { return document.getVariableInitialisers(); }
  207. };
  208. //==============================================================================
  209. class ComponentInitialSizeProperty : public ComponentTextProperty <Component>
  210. {
  211. public:
  212. ComponentInitialSizeProperty (JucerDocument& doc, const bool isWidth_)
  213. : ComponentTextProperty <Component> (isWidth_ ? "Initial width"
  214. : "Initial height",
  215. 10, false, 0, doc),
  216. isWidth (isWidth_)
  217. {}
  218. void setText (const String& newText) override
  219. {
  220. if (isWidth)
  221. document.setInitialSize (newText.getIntValue(), document.getInitialHeight());
  222. else
  223. document.setInitialSize (document.getInitialWidth(), newText.getIntValue());
  224. }
  225. String getText() const override
  226. {
  227. return String (isWidth ? document.getInitialWidth()
  228. : document.getInitialHeight());
  229. }
  230. private:
  231. const bool isWidth;
  232. };
  233. //==============================================================================
  234. class FixedSizeProperty : public ComponentChoiceProperty <Component>
  235. {
  236. public:
  237. FixedSizeProperty (JucerDocument& doc)
  238. : ComponentChoiceProperty <Component> ("Fixed size", 0, doc)
  239. {
  240. choices.add ("Resize component to fit workspace");
  241. choices.add ("Keep component size fixed");
  242. }
  243. void setIndex (int newIndex) { document.setFixedSize (newIndex != 0); }
  244. int getIndex() const { return document.isFixedSize() ? 1 : 0; }
  245. };
  246. //==============================================================================
  247. class TemplateFileProperty : public ComponentTextProperty <Component>
  248. {
  249. public:
  250. TemplateFileProperty (JucerDocument& doc)
  251. : ComponentTextProperty <Component> ("Template file", 2048, false, 0, doc)
  252. {}
  253. void setText (const String& newText) override { document.setTemplateFile (newText); }
  254. String getText() const override { return document.getTemplateFile(); }
  255. };
  256. };
  257. static const Colour tabColour (Colour (0xff888888));
  258. static SourceCodeEditor* createCodeEditor (const File& file, SourceCodeDocument& sourceCodeDoc)
  259. {
  260. return new SourceCodeEditor (&sourceCodeDoc,
  261. new CppCodeEditorComponent (file, sourceCodeDoc.getCodeDocument()));
  262. }
  263. //==============================================================================
  264. JucerDocumentEditor::JucerDocumentEditor (JucerDocument* const doc)
  265. : document (doc),
  266. tabbedComponent (doc)
  267. {
  268. setOpaque (true);
  269. if (document != nullptr)
  270. {
  271. setSize (document->getInitialWidth(),
  272. document->getInitialHeight());
  273. addAndMakeVisible (tabbedComponent);
  274. tabbedComponent.setOutline (0);
  275. tabbedComponent.addTab ("Class", tabColour, new ClassPropertiesPanel (*document), true);
  276. if (document->getComponentLayout() != nullptr)
  277. tabbedComponent.addTab ("Subcomponents", tabColour,
  278. compLayoutPanel = new ComponentLayoutPanel (*document, *document->getComponentLayout()), true);
  279. tabbedComponent.addTab ("Resources", tabColour, new ResourceEditorPanel (*document), true);
  280. tabbedComponent.addTab ("Code", tabColour, createCodeEditor (document->getCppFile(),
  281. document->getCppDocument()), true);
  282. updateTabs();
  283. restoreLastSelectedTab();
  284. document->addChangeListener (this);
  285. resized();
  286. refreshPropertiesPanel();
  287. changeListenerCallback (nullptr);
  288. }
  289. }
  290. JucerDocumentEditor::~JucerDocumentEditor()
  291. {
  292. saveLastSelectedTab();
  293. tabbedComponent.clearTabs();
  294. }
  295. void JucerDocumentEditor::refreshPropertiesPanel() const
  296. {
  297. for (int i = tabbedComponent.getNumTabs(); --i >= 0;)
  298. {
  299. if (ComponentLayoutPanel* layoutPanel = dynamic_cast<ComponentLayoutPanel*> (tabbedComponent.getTabContentComponent (i)))
  300. {
  301. if (layoutPanel->isVisible())
  302. layoutPanel->updatePropertiesList();
  303. }
  304. else
  305. {
  306. if (PaintRoutinePanel* pr = dynamic_cast<PaintRoutinePanel*> (tabbedComponent.getTabContentComponent (i)))
  307. if (pr->isVisible())
  308. pr->updatePropertiesList();
  309. }
  310. }
  311. }
  312. void JucerDocumentEditor::updateTabs()
  313. {
  314. const StringArray paintRoutineNames (document->getPaintRoutineNames());
  315. for (int i = tabbedComponent.getNumTabs(); --i >= 0;)
  316. {
  317. if (dynamic_cast<PaintRoutinePanel*> (tabbedComponent.getTabContentComponent (i)) != 0
  318. && ! paintRoutineNames.contains (tabbedComponent.getTabNames() [i]))
  319. {
  320. tabbedComponent.removeTab (i);
  321. }
  322. }
  323. for (int i = 0; i < document->getNumPaintRoutines(); ++i)
  324. {
  325. if (! tabbedComponent.getTabNames().contains (paintRoutineNames [i]))
  326. {
  327. int index, numPaintRoutinesSeen = 0;
  328. for (index = 1; index < tabbedComponent.getNumTabs(); ++index)
  329. {
  330. if (dynamic_cast<PaintRoutinePanel*> (tabbedComponent.getTabContentComponent (index)) != nullptr)
  331. {
  332. if (++numPaintRoutinesSeen == i)
  333. {
  334. ++index;
  335. break;
  336. }
  337. }
  338. }
  339. if (numPaintRoutinesSeen == 0)
  340. index = document->getComponentLayout() != nullptr ? 2 : 1;
  341. tabbedComponent.addTab (paintRoutineNames[i], tabColour,
  342. new PaintRoutinePanel (*document,
  343. *document->getPaintRoutine (i),
  344. this), true, index);
  345. }
  346. }
  347. }
  348. //==============================================================================
  349. void JucerDocumentEditor::paint (Graphics& g)
  350. {
  351. g.fillAll (findColour (backgroundColourId));
  352. }
  353. void JucerDocumentEditor::resized()
  354. {
  355. tabbedComponent.setBounds (getLocalBounds().withTrimmedLeft (12));
  356. }
  357. void JucerDocumentEditor::changeListenerCallback (ChangeBroadcaster*)
  358. {
  359. setName (document->getClassName());
  360. updateTabs();
  361. }
  362. //==============================================================================
  363. ApplicationCommandTarget* JucerDocumentEditor::getNextCommandTarget()
  364. {
  365. return findFirstTargetParentComponent();
  366. }
  367. ComponentLayout* JucerDocumentEditor::getCurrentLayout() const
  368. {
  369. if (ComponentLayoutPanel* panel = dynamic_cast<ComponentLayoutPanel*> (tabbedComponent.getCurrentContentComponent()))
  370. return &(panel->layout);
  371. return nullptr;
  372. }
  373. PaintRoutine* JucerDocumentEditor::getCurrentPaintRoutine() const
  374. {
  375. if (PaintRoutinePanel* panel = dynamic_cast<PaintRoutinePanel*> (tabbedComponent.getCurrentContentComponent()))
  376. return &(panel->getPaintRoutine());
  377. return nullptr;
  378. }
  379. void JucerDocumentEditor::showLayout()
  380. {
  381. if (getCurrentLayout() == nullptr)
  382. {
  383. for (int i = 0; i < tabbedComponent.getNumTabs(); ++i)
  384. {
  385. if (dynamic_cast<ComponentLayoutPanel*> (tabbedComponent.getTabContentComponent (i)) != nullptr)
  386. {
  387. tabbedComponent.setCurrentTabIndex (i);
  388. break;
  389. }
  390. }
  391. }
  392. }
  393. void JucerDocumentEditor::showGraphics (PaintRoutine* routine)
  394. {
  395. if (getCurrentPaintRoutine() != routine || routine == 0)
  396. {
  397. for (int i = 0; i < tabbedComponent.getNumTabs(); ++i)
  398. {
  399. if (PaintRoutinePanel* pr = dynamic_cast<PaintRoutinePanel*> (tabbedComponent.getTabContentComponent (i)))
  400. {
  401. if (routine == &(pr->getPaintRoutine()) || routine == nullptr)
  402. {
  403. tabbedComponent.setCurrentTabIndex (i);
  404. break;
  405. }
  406. }
  407. }
  408. }
  409. }
  410. //==============================================================================
  411. void JucerDocumentEditor::setViewportToLastPos (Viewport* vp, EditingPanelBase& editor)
  412. {
  413. vp->setViewPosition (lastViewportX, lastViewportY);
  414. editor.setZoom (currentZoomLevel);
  415. }
  416. void JucerDocumentEditor::storeLastViewportPos (Viewport* vp, EditingPanelBase& editor)
  417. {
  418. lastViewportX = vp->getViewPositionX();
  419. lastViewportY = vp->getViewPositionY();
  420. currentZoomLevel = editor.getZoom();
  421. }
  422. void JucerDocumentEditor::setZoom (double scale)
  423. {
  424. scale = jlimit (1.0 / 4.0, 32.0, scale);
  425. if (EditingPanelBase* panel = dynamic_cast<EditingPanelBase*> (tabbedComponent.getCurrentContentComponent()))
  426. panel->setZoom (scale);
  427. }
  428. double JucerDocumentEditor::getZoom() const
  429. {
  430. if (EditingPanelBase* panel = dynamic_cast<EditingPanelBase*> (tabbedComponent.getCurrentContentComponent()))
  431. return panel->getZoom();
  432. return 1.0;
  433. }
  434. static double snapToIntegerZoom (double zoom)
  435. {
  436. if (zoom >= 1.0)
  437. return (double) (int) (zoom + 0.5);
  438. return 1.0 / (int) (1.0 / zoom + 0.5);
  439. }
  440. void JucerDocumentEditor::addElement (const int index)
  441. {
  442. if (PaintRoutinePanel* const panel = dynamic_cast<PaintRoutinePanel*> (tabbedComponent.getCurrentContentComponent()))
  443. {
  444. PaintRoutine* const currentPaintRoutine = & (panel->getPaintRoutine());
  445. const Rectangle<int> area (panel->getComponentArea());
  446. document->beginTransaction();
  447. PaintElement* e = ObjectTypes::createNewElement (index, currentPaintRoutine);
  448. e->setInitialBounds (area.getWidth(), area.getHeight());
  449. e = currentPaintRoutine->addNewElement (e, -1, true);
  450. if (e != nullptr)
  451. {
  452. const int randomness = jmin (80, area.getWidth() / 2, area.getHeight() / 2);
  453. int x = area.getX() + area.getWidth() / 2 + Random::getSystemRandom().nextInt (randomness) - randomness / 2;
  454. int y = area.getY() + area.getHeight() / 2 + Random::getSystemRandom().nextInt (randomness) - randomness / 2;
  455. x = document->snapPosition (x);
  456. y = document->snapPosition (y);
  457. panel->xyToTargetXY (x, y);
  458. Rectangle<int> r (e->getCurrentBounds (area));
  459. r.setPosition (x, y);
  460. e->setCurrentBounds (r, area, true);
  461. currentPaintRoutine->getSelectedElements().selectOnly (e);
  462. }
  463. document->beginTransaction();
  464. }
  465. }
  466. void JucerDocumentEditor::addComponent (const int index)
  467. {
  468. showLayout();
  469. if (ComponentLayoutPanel* const panel = dynamic_cast<ComponentLayoutPanel*> (tabbedComponent.getCurrentContentComponent()))
  470. {
  471. const Rectangle<int> area (panel->getComponentArea());
  472. document->beginTransaction ("Add new " + ObjectTypes::componentTypeHandlers [index]->getTypeName());
  473. const int randomness = jmin (80, area.getWidth() / 2, area.getHeight() / 2);
  474. int x = area.getWidth() / 2 + Random::getSystemRandom().nextInt (randomness) - randomness / 2;
  475. int y = area.getHeight() / 2 + Random::getSystemRandom().nextInt (randomness) - randomness / 2;
  476. x = document->snapPosition (x);
  477. y = document->snapPosition (y);
  478. panel->xyToTargetXY (x, y);
  479. if (Component* newOne = panel->layout.addNewComponent (ObjectTypes::componentTypeHandlers [index], x, y))
  480. panel->layout.getSelectedSet().selectOnly (newOne);
  481. document->beginTransaction();
  482. }
  483. }
  484. //==============================================================================
  485. void JucerDocumentEditor::saveLastSelectedTab() const
  486. {
  487. if (document != nullptr)
  488. {
  489. if (auto* project = document->getCppDocument().getProject())
  490. {
  491. auto& projectProps = project->getStoredProperties();
  492. ScopedPointer<XmlElement> root (projectProps.getXmlValue ("GUIComponentsLastTab"));
  493. if (root == nullptr)
  494. root = new XmlElement ("FILES");
  495. auto fileName = document->getCppFile().getFileName();
  496. auto* child = root->getChildByName (fileName);
  497. if (child == nullptr)
  498. child = root->createNewChildElement (fileName);
  499. child->setAttribute ("tab", tabbedComponent.getCurrentTabIndex());
  500. projectProps.setValue ("GUIComponentsLastTab", root.get());
  501. }
  502. }
  503. }
  504. void JucerDocumentEditor::restoreLastSelectedTab()
  505. {
  506. if (document != nullptr)
  507. {
  508. if (auto* project = document->getCppDocument().getProject())
  509. {
  510. ScopedPointer<XmlElement> root (project->getStoredProperties().getXmlValue ("GUIComponentsLastTab"));
  511. if (root != nullptr)
  512. {
  513. auto* child = root->getChildByName (document->getCppFile().getFileName());
  514. if (child != nullptr)
  515. tabbedComponent.setCurrentTabIndex (child->getIntAttribute ("tab"));
  516. }
  517. }
  518. }
  519. }
  520. //==============================================================================
  521. bool JucerDocumentEditor::isSomethingSelected() const
  522. {
  523. if (auto* layout = getCurrentLayout())
  524. return layout->getSelectedSet().getNumSelected() > 0;
  525. if (auto* routine = getCurrentPaintRoutine())
  526. return routine->getSelectedElements().getNumSelected() > 0;
  527. return false;
  528. }
  529. bool JucerDocumentEditor::areMultipleThingsSelected() const
  530. {
  531. if (auto* layout = getCurrentLayout())
  532. return layout->getSelectedSet().getNumSelected() > 1;
  533. if (auto* routine = getCurrentPaintRoutine())
  534. return routine->getSelectedElements().getNumSelected() > 1;
  535. return false;
  536. }
  537. //==============================================================================
  538. void JucerDocumentEditor::getAllCommands (Array <CommandID>& commands)
  539. {
  540. const CommandID ids[] =
  541. {
  542. JucerCommandIDs::test,
  543. JucerCommandIDs::toFront,
  544. JucerCommandIDs::toBack,
  545. JucerCommandIDs::group,
  546. JucerCommandIDs::ungroup,
  547. JucerCommandIDs::bringBackLostItems,
  548. JucerCommandIDs::enableSnapToGrid,
  549. JucerCommandIDs::showGrid,
  550. JucerCommandIDs::editCompLayout,
  551. JucerCommandIDs::editCompGraphics,
  552. JucerCommandIDs::zoomIn,
  553. JucerCommandIDs::zoomOut,
  554. JucerCommandIDs::zoomNormal,
  555. JucerCommandIDs::spaceBarDrag,
  556. JucerCommandIDs::compOverlay0,
  557. JucerCommandIDs::compOverlay33,
  558. JucerCommandIDs::compOverlay66,
  559. JucerCommandIDs::compOverlay100,
  560. JucerCommandIDs::alignTop,
  561. JucerCommandIDs::alignRight,
  562. JucerCommandIDs::alignBottom,
  563. JucerCommandIDs::alignLeft,
  564. StandardApplicationCommandIDs::undo,
  565. StandardApplicationCommandIDs::redo,
  566. StandardApplicationCommandIDs::cut,
  567. StandardApplicationCommandIDs::copy,
  568. StandardApplicationCommandIDs::paste,
  569. StandardApplicationCommandIDs::del,
  570. StandardApplicationCommandIDs::selectAll,
  571. StandardApplicationCommandIDs::deselectAll
  572. };
  573. commands.addArray (ids, numElementsInArray (ids));
  574. for (int i = 0; i < ObjectTypes::numComponentTypes; ++i)
  575. commands.add (JucerCommandIDs::newComponentBase + i);
  576. for (int i = 0; i < ObjectTypes::numElementTypes; ++i)
  577. commands.add (JucerCommandIDs::newElementBase + i);
  578. }
  579. void JucerDocumentEditor::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  580. {
  581. ComponentLayout* const currentLayout = getCurrentLayout();
  582. PaintRoutine* const currentPaintRoutine = getCurrentPaintRoutine();
  583. const int cmd = ModifierKeys::commandModifier;
  584. const int shift = ModifierKeys::shiftModifier;
  585. if (commandID >= JucerCommandIDs::newComponentBase
  586. && commandID < JucerCommandIDs::newComponentBase + ObjectTypes::numComponentTypes)
  587. {
  588. const int index = commandID - JucerCommandIDs::newComponentBase;
  589. result.setInfo ("New " + ObjectTypes::componentTypeHandlers [index]->getTypeName(),
  590. "Creates a new " + ObjectTypes::componentTypeHandlers [index]->getTypeName(),
  591. CommandCategories::editing, 0);
  592. return;
  593. }
  594. if (commandID >= JucerCommandIDs::newElementBase
  595. && commandID < JucerCommandIDs::newElementBase + ObjectTypes::numElementTypes)
  596. {
  597. const int index = commandID - JucerCommandIDs::newElementBase;
  598. result.setInfo (String ("New ") + ObjectTypes::elementTypeNames [index],
  599. String ("Adds a new ") + ObjectTypes::elementTypeNames [index],
  600. CommandCategories::editing, 0);
  601. result.setActive (currentPaintRoutine != nullptr);
  602. return;
  603. }
  604. switch (commandID)
  605. {
  606. case JucerCommandIDs::toFront:
  607. result.setInfo (TRANS("Bring to front"), TRANS("Brings the currently selected component to the front."), CommandCategories::editing, 0);
  608. result.setActive (isSomethingSelected());
  609. result.defaultKeypresses.add (KeyPress ('f', cmd, 0));
  610. break;
  611. case JucerCommandIDs::toBack:
  612. result.setInfo (TRANS("Send to back"), TRANS("Sends the currently selected component to the back."), CommandCategories::editing, 0);
  613. result.setActive (isSomethingSelected());
  614. result.defaultKeypresses.add (KeyPress ('b', cmd, 0));
  615. break;
  616. case JucerCommandIDs::group:
  617. result.setInfo (TRANS("Group selected items"), TRANS("Turns the currently selected elements into a single group object."), CommandCategories::editing, 0);
  618. result.setActive (currentPaintRoutine != nullptr && currentPaintRoutine->getSelectedElements().getNumSelected() > 1);
  619. result.defaultKeypresses.add (KeyPress ('k', cmd, 0));
  620. break;
  621. case JucerCommandIDs::ungroup:
  622. result.setInfo (TRANS("Ungroup selected items"), TRANS("Turns the currently selected elements into a single group object."), CommandCategories::editing, 0);
  623. result.setActive (currentPaintRoutine != nullptr
  624. && currentPaintRoutine->getSelectedElements().getNumSelected() == 1
  625. && currentPaintRoutine->getSelectedElements().getSelectedItem (0)->getTypeName() == "Group");
  626. result.defaultKeypresses.add (KeyPress ('k', cmd | shift, 0));
  627. break;
  628. case JucerCommandIDs::test:
  629. result.setInfo (TRANS("Test component..."), TRANS("Runs the current component interactively."), CommandCategories::view, 0);
  630. result.defaultKeypresses.add (KeyPress ('t', cmd, 0));
  631. break;
  632. case JucerCommandIDs::enableSnapToGrid:
  633. result.setInfo (TRANS("Enable snap-to-grid"), TRANS("Toggles whether components' positions are aligned to a grid."), CommandCategories::view, 0);
  634. result.setTicked (document != nullptr && document->isSnapActive (false));
  635. result.defaultKeypresses.add (KeyPress ('g', cmd, 0));
  636. break;
  637. case JucerCommandIDs::showGrid:
  638. result.setInfo (TRANS("Show snap-to-grid"), TRANS("Toggles whether the snapping grid is displayed on-screen."), CommandCategories::view, 0);
  639. result.setTicked (document != nullptr && document->isSnapShown());
  640. result.defaultKeypresses.add (KeyPress ('g', cmd | shift, 0));
  641. break;
  642. case JucerCommandIDs::editCompLayout:
  643. result.setInfo (TRANS("Edit sub-component layout"), TRANS("Switches to the sub-component editor view."), CommandCategories::view, 0);
  644. result.setTicked (currentLayout != nullptr);
  645. result.defaultKeypresses.add (KeyPress ('n', cmd, 0));
  646. break;
  647. case JucerCommandIDs::editCompGraphics:
  648. result.setInfo (TRANS("Edit background graphics"), TRANS("Switches to the background graphics editor view."), CommandCategories::view, 0);
  649. result.setTicked (currentPaintRoutine != nullptr);
  650. result.defaultKeypresses.add (KeyPress ('m', cmd, 0));
  651. break;
  652. case JucerCommandIDs::bringBackLostItems:
  653. result.setInfo (TRANS("Retrieve offscreen items"), TRANS("Moves any items that are lost beyond the edges of the screen back to the centre."), CommandCategories::editing, 0);
  654. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  655. result.defaultKeypresses.add (KeyPress ('m', cmd, 0));
  656. break;
  657. case JucerCommandIDs::zoomIn:
  658. result.setInfo (TRANS("Zoom in"), TRANS("Zooms in on the current component."), CommandCategories::editing, 0);
  659. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  660. result.defaultKeypresses.add (KeyPress (']', cmd, 0));
  661. break;
  662. case JucerCommandIDs::zoomOut:
  663. result.setInfo (TRANS("Zoom out"), TRANS("Zooms out on the current component."), CommandCategories::editing, 0);
  664. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  665. result.defaultKeypresses.add (KeyPress ('[', cmd, 0));
  666. break;
  667. case JucerCommandIDs::zoomNormal:
  668. result.setInfo (TRANS("Zoom to 100%"), TRANS("Restores the zoom level to normal."), CommandCategories::editing, 0);
  669. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  670. result.defaultKeypresses.add (KeyPress ('1', cmd, 0));
  671. break;
  672. case JucerCommandIDs::spaceBarDrag:
  673. result.setInfo (TRANS("Scroll while dragging mouse"), TRANS("When held down, this key lets you scroll around by dragging with the mouse."),
  674. CommandCategories::view, ApplicationCommandInfo::wantsKeyUpDownCallbacks);
  675. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  676. result.defaultKeypresses.add (KeyPress (KeyPress::spaceKey, 0, 0));
  677. break;
  678. case JucerCommandIDs::compOverlay0:
  679. case JucerCommandIDs::compOverlay33:
  680. case JucerCommandIDs::compOverlay66:
  681. case JucerCommandIDs::compOverlay100:
  682. {
  683. int amount = 0, num = 0;
  684. if (commandID == JucerCommandIDs::compOverlay33)
  685. {
  686. amount = 33;
  687. num = 1;
  688. }
  689. else if (commandID == JucerCommandIDs::compOverlay66)
  690. {
  691. amount = 66;
  692. num = 2;
  693. }
  694. else if (commandID == JucerCommandIDs::compOverlay100)
  695. {
  696. amount = 100;
  697. num = 3;
  698. }
  699. result.defaultKeypresses.add (KeyPress ('2' + num, cmd, 0));
  700. int currentAmount = 0;
  701. if (document != nullptr && document->getComponentOverlayOpacity() > 0.9f)
  702. currentAmount = 100;
  703. else if (document != nullptr && document->getComponentOverlayOpacity() > 0.6f)
  704. currentAmount = 66;
  705. else if (document != nullptr && document->getComponentOverlayOpacity() > 0.3f)
  706. currentAmount = 33;
  707. result.setInfo (commandID == JucerCommandIDs::compOverlay0
  708. ? TRANS("No component overlay")
  709. : TRANS("Overlay with opacity of 123%").replace ("123", String (amount)),
  710. TRANS("Changes the opacity of the components that are shown over the top of the graphics editor."),
  711. CommandCategories::view, 0);
  712. result.setActive (currentPaintRoutine != nullptr && document->getComponentLayout() != nullptr);
  713. result.setTicked (amount == currentAmount);
  714. }
  715. break;
  716. case JucerCommandIDs::alignTop:
  717. result.setInfo (TRANS ("Align top"),
  718. TRANS ("Aligns the top edges of all selected components to the first component that was selected."),
  719. CommandCategories::editing, 0);
  720. result.setActive (areMultipleThingsSelected());
  721. break;
  722. case JucerCommandIDs::alignRight:
  723. result.setInfo (TRANS ("Align right"),
  724. TRANS ("Aligns the right edges of all selected components to the first component that was selected."),
  725. CommandCategories::editing, 0);
  726. result.setActive (areMultipleThingsSelected());
  727. break;
  728. case JucerCommandIDs::alignBottom:
  729. result.setInfo (TRANS ("Align bottom"),
  730. TRANS ("Aligns the bottom edges of all selected components to the first component that was selected."),
  731. CommandCategories::editing, 0);
  732. result.setActive (areMultipleThingsSelected());
  733. break;
  734. case JucerCommandIDs::alignLeft:
  735. result.setInfo (TRANS ("Align left"),
  736. TRANS ("Aligns the left edges of all selected components to the first component that was selected."),
  737. CommandCategories::editing, 0);
  738. result.setActive (areMultipleThingsSelected());
  739. break;
  740. case StandardApplicationCommandIDs::undo:
  741. result.setInfo (TRANS ("Undo"), TRANS ("Undo"), "Editing", 0);
  742. result.setActive (document != nullptr && document->getUndoManager().canUndo());
  743. result.defaultKeypresses.add (KeyPress ('z', cmd, 0));
  744. break;
  745. case StandardApplicationCommandIDs::redo:
  746. result.setInfo (TRANS ("Redo"), TRANS ("Redo"), "Editing", 0);
  747. result.setActive (document != nullptr && document->getUndoManager().canRedo());
  748. result.defaultKeypresses.add (KeyPress ('z', cmd | shift, 0));
  749. break;
  750. case StandardApplicationCommandIDs::cut:
  751. result.setInfo (TRANS ("Cut"), String(), "Editing", 0);
  752. result.setActive (isSomethingSelected());
  753. result.defaultKeypresses.add (KeyPress ('x', cmd, 0));
  754. break;
  755. case StandardApplicationCommandIDs::copy:
  756. result.setInfo (TRANS ("Copy"), String(), "Editing", 0);
  757. result.setActive (isSomethingSelected());
  758. result.defaultKeypresses.add (KeyPress ('c', cmd, 0));
  759. break;
  760. case StandardApplicationCommandIDs::paste:
  761. {
  762. result.setInfo (TRANS ("Paste"), String(), "Editing", 0);
  763. result.defaultKeypresses.add (KeyPress ('v', cmd, 0));
  764. bool canPaste = false;
  765. ScopedPointer<XmlElement> doc (XmlDocument::parse (SystemClipboard::getTextFromClipboard()));
  766. if (doc != nullptr)
  767. {
  768. if (doc->hasTagName (ComponentLayout::clipboardXmlTag))
  769. canPaste = (currentLayout != nullptr);
  770. else if (doc->hasTagName (PaintRoutine::clipboardXmlTag))
  771. canPaste = (currentPaintRoutine != nullptr);
  772. }
  773. result.setActive (canPaste);
  774. }
  775. break;
  776. case StandardApplicationCommandIDs::del:
  777. result.setInfo (TRANS ("Delete"), String(), "Editing", 0);
  778. result.setActive (isSomethingSelected());
  779. break;
  780. case StandardApplicationCommandIDs::selectAll:
  781. result.setInfo (TRANS ("Select All"), String(), "Editing", 0);
  782. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  783. result.defaultKeypresses.add (KeyPress ('a', cmd, 0));
  784. break;
  785. case StandardApplicationCommandIDs::deselectAll:
  786. result.setInfo (TRANS ("Deselect All"), String(), "Editing", 0);
  787. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  788. result.defaultKeypresses.add (KeyPress ('d', cmd, 0));
  789. break;
  790. default:
  791. break;
  792. }
  793. }
  794. bool JucerDocumentEditor::perform (const InvocationInfo& info)
  795. {
  796. ComponentLayout* const currentLayout = getCurrentLayout();
  797. PaintRoutine* const currentPaintRoutine = getCurrentPaintRoutine();
  798. document->beginTransaction();
  799. if (info.commandID >= JucerCommandIDs::newComponentBase
  800. && info.commandID < JucerCommandIDs::newComponentBase + ObjectTypes::numComponentTypes)
  801. {
  802. addComponent (info.commandID - JucerCommandIDs::newComponentBase);
  803. return true;
  804. }
  805. if (info.commandID >= JucerCommandIDs::newElementBase
  806. && info.commandID < JucerCommandIDs::newElementBase + ObjectTypes::numElementTypes)
  807. {
  808. addElement (info.commandID - JucerCommandIDs::newElementBase);
  809. return true;
  810. }
  811. switch (info.commandID)
  812. {
  813. case StandardApplicationCommandIDs::undo:
  814. document->getUndoManager().undo();
  815. document->dispatchPendingMessages();
  816. break;
  817. case StandardApplicationCommandIDs::redo:
  818. document->getUndoManager().redo();
  819. document->dispatchPendingMessages();
  820. break;
  821. case JucerCommandIDs::test:
  822. TestComponent::showInDialogBox (*document);
  823. break;
  824. case JucerCommandIDs::enableSnapToGrid:
  825. document->setSnappingGrid (document->getSnappingGridSize(),
  826. ! document->isSnapActive (false),
  827. document->isSnapShown());
  828. break;
  829. case JucerCommandIDs::showGrid:
  830. document->setSnappingGrid (document->getSnappingGridSize(),
  831. document->isSnapActive (false),
  832. ! document->isSnapShown());
  833. break;
  834. case JucerCommandIDs::editCompLayout:
  835. showLayout();
  836. break;
  837. case JucerCommandIDs::editCompGraphics:
  838. showGraphics (0);
  839. break;
  840. case JucerCommandIDs::zoomIn: setZoom (snapToIntegerZoom (getZoom() * 2.0)); break;
  841. case JucerCommandIDs::zoomOut: setZoom (snapToIntegerZoom (getZoom() / 2.0)); break;
  842. case JucerCommandIDs::zoomNormal: setZoom (1.0); break;
  843. case JucerCommandIDs::spaceBarDrag:
  844. if (EditingPanelBase* panel = dynamic_cast<EditingPanelBase*> (tabbedComponent.getCurrentContentComponent()))
  845. panel->dragKeyHeldDown (info.isKeyDown);
  846. break;
  847. case JucerCommandIDs::compOverlay0:
  848. case JucerCommandIDs::compOverlay33:
  849. case JucerCommandIDs::compOverlay66:
  850. case JucerCommandIDs::compOverlay100:
  851. {
  852. int amount = 0;
  853. if (info.commandID == JucerCommandIDs::compOverlay33)
  854. amount = 33;
  855. else if (info.commandID == JucerCommandIDs::compOverlay66)
  856. amount = 66;
  857. else if (info.commandID == JucerCommandIDs::compOverlay100)
  858. amount = 100;
  859. document->setComponentOverlayOpacity (amount * 0.01f);
  860. }
  861. break;
  862. case JucerCommandIDs::bringBackLostItems:
  863. if (EditingPanelBase* panel = dynamic_cast<EditingPanelBase*> (tabbedComponent.getCurrentContentComponent()))
  864. {
  865. int w = panel->getComponentArea().getWidth();
  866. int h = panel->getComponentArea().getHeight();
  867. if (currentPaintRoutine != nullptr)
  868. currentPaintRoutine->bringLostItemsBackOnScreen (panel->getComponentArea());
  869. else if (currentLayout != nullptr)
  870. currentLayout->bringLostItemsBackOnScreen (w, h);
  871. }
  872. break;
  873. case JucerCommandIDs::toFront:
  874. if (currentLayout != nullptr)
  875. currentLayout->selectedToFront();
  876. else if (currentPaintRoutine != nullptr)
  877. currentPaintRoutine->selectedToFront();
  878. break;
  879. case JucerCommandIDs::toBack:
  880. if (currentLayout != nullptr)
  881. currentLayout->selectedToBack();
  882. else if (currentPaintRoutine != nullptr)
  883. currentPaintRoutine->selectedToBack();
  884. break;
  885. case JucerCommandIDs::group:
  886. if (currentPaintRoutine != nullptr)
  887. currentPaintRoutine->groupSelected();
  888. break;
  889. case JucerCommandIDs::ungroup:
  890. if (currentPaintRoutine != nullptr)
  891. currentPaintRoutine->ungroupSelected();
  892. break;
  893. case JucerCommandIDs::alignTop:
  894. if (currentLayout != nullptr)
  895. currentLayout->alignTop();
  896. else if (currentPaintRoutine != nullptr)
  897. currentPaintRoutine->alignTop();
  898. break;
  899. case JucerCommandIDs::alignRight:
  900. if (currentLayout != nullptr)
  901. currentLayout->alignRight();
  902. else if (currentPaintRoutine != nullptr)
  903. currentPaintRoutine->alignRight();
  904. break;
  905. case JucerCommandIDs::alignBottom:
  906. if (currentLayout != nullptr)
  907. currentLayout->alignBottom();
  908. else if (currentPaintRoutine != nullptr)
  909. currentPaintRoutine->alignBottom();
  910. break;
  911. case JucerCommandIDs::alignLeft:
  912. if (currentLayout != nullptr)
  913. currentLayout->alignLeft();
  914. else if (currentPaintRoutine != nullptr)
  915. currentPaintRoutine->alignLeft();
  916. break;
  917. case StandardApplicationCommandIDs::cut:
  918. if (currentLayout != nullptr)
  919. {
  920. currentLayout->copySelectedToClipboard();
  921. currentLayout->deleteSelected();
  922. }
  923. else if (currentPaintRoutine != nullptr)
  924. {
  925. currentPaintRoutine->copySelectedToClipboard();
  926. currentPaintRoutine->deleteSelected();
  927. }
  928. break;
  929. case StandardApplicationCommandIDs::copy:
  930. if (currentLayout != nullptr)
  931. currentLayout->copySelectedToClipboard();
  932. else if (currentPaintRoutine != nullptr)
  933. currentPaintRoutine->copySelectedToClipboard();
  934. break;
  935. case StandardApplicationCommandIDs::paste:
  936. {
  937. if (ScopedPointer<XmlElement> doc = XmlDocument::parse (SystemClipboard::getTextFromClipboard()))
  938. {
  939. if (doc->hasTagName (ComponentLayout::clipboardXmlTag))
  940. {
  941. if (currentLayout != nullptr)
  942. currentLayout->paste();
  943. }
  944. else if (doc->hasTagName (PaintRoutine::clipboardXmlTag))
  945. {
  946. if (currentPaintRoutine != nullptr)
  947. currentPaintRoutine->paste();
  948. }
  949. }
  950. }
  951. break;
  952. case StandardApplicationCommandIDs::del:
  953. if (currentLayout != nullptr)
  954. currentLayout->deleteSelected();
  955. else if (currentPaintRoutine != nullptr)
  956. currentPaintRoutine->deleteSelected();
  957. break;
  958. case StandardApplicationCommandIDs::selectAll:
  959. if (currentLayout != nullptr)
  960. currentLayout->selectAll();
  961. else if (currentPaintRoutine != nullptr)
  962. currentPaintRoutine->selectAll();
  963. break;
  964. case StandardApplicationCommandIDs::deselectAll:
  965. if (currentLayout != nullptr)
  966. {
  967. currentLayout->getSelectedSet().deselectAll();
  968. }
  969. else if (currentPaintRoutine != nullptr)
  970. {
  971. currentPaintRoutine->getSelectedElements().deselectAll();
  972. currentPaintRoutine->getSelectedPoints().deselectAll();
  973. }
  974. break;
  975. default:
  976. return false;
  977. }
  978. document->beginTransaction();
  979. return true;
  980. }
  981. bool JucerDocumentEditor::keyPressed (const KeyPress& key)
  982. {
  983. if (key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  984. {
  985. ProjucerApplication::getCommandManager().invokeDirectly (StandardApplicationCommandIDs::del, true);
  986. return true;
  987. }
  988. return false;
  989. }
  990. JucerDocumentEditor* JucerDocumentEditor::getActiveDocumentHolder()
  991. {
  992. ApplicationCommandInfo info (0);
  993. return dynamic_cast<JucerDocumentEditor*> (ProjucerApplication::getCommandManager()
  994. .getTargetForCommand (JucerCommandIDs::editCompLayout, info));
  995. }
  996. Image JucerDocumentEditor::createComponentLayerSnapshot() const
  997. {
  998. if (compLayoutPanel != nullptr)
  999. return compLayoutPanel->createComponentSnapshot();
  1000. return {};
  1001. }
  1002. const int gridSnapMenuItemBase = 0x8723620;
  1003. const int snapSizes[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32 };
  1004. void createGUIEditorMenu (PopupMenu& menu)
  1005. {
  1006. ApplicationCommandManager* commandManager = &ProjucerApplication::getCommandManager();
  1007. menu.addCommandItem (commandManager, JucerCommandIDs::editCompLayout);
  1008. menu.addCommandItem (commandManager, JucerCommandIDs::editCompGraphics);
  1009. menu.addSeparator();
  1010. PopupMenu newComps;
  1011. for (int i = 0; i < ObjectTypes::numComponentTypes; ++i)
  1012. newComps.addCommandItem (commandManager, JucerCommandIDs::newComponentBase + i);
  1013. menu.addSubMenu ("Add new component", newComps);
  1014. PopupMenu newElements;
  1015. for (int i = 0; i < ObjectTypes::numElementTypes; ++i)
  1016. newElements.addCommandItem (commandManager, JucerCommandIDs::newElementBase + i);
  1017. menu.addSubMenu ("Add new graphic element", newElements);
  1018. menu.addSeparator();
  1019. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut);
  1020. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy);
  1021. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste);
  1022. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del);
  1023. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll);
  1024. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll);
  1025. menu.addSeparator();
  1026. menu.addCommandItem (commandManager, JucerCommandIDs::toFront);
  1027. menu.addCommandItem (commandManager, JucerCommandIDs::toBack);
  1028. menu.addSeparator();
  1029. menu.addCommandItem (commandManager, JucerCommandIDs::group);
  1030. menu.addCommandItem (commandManager, JucerCommandIDs::ungroup);
  1031. menu.addSeparator();
  1032. menu.addCommandItem (commandManager, JucerCommandIDs::bringBackLostItems);
  1033. menu.addSeparator();
  1034. menu.addCommandItem (commandManager, JucerCommandIDs::showGrid);
  1035. menu.addCommandItem (commandManager, JucerCommandIDs::enableSnapToGrid);
  1036. JucerDocumentEditor* holder = JucerDocumentEditor::getActiveDocumentHolder();
  1037. {
  1038. const int currentSnapSize = holder != nullptr ? holder->getDocument()->getSnappingGridSize() : -1;
  1039. PopupMenu m;
  1040. for (int i = 0; i < numElementsInArray (snapSizes); ++i)
  1041. m.addItem (gridSnapMenuItemBase + i, String (snapSizes[i]) + " pixels",
  1042. true, snapSizes[i] == currentSnapSize);
  1043. menu.addSubMenu ("Grid size", m, currentSnapSize >= 0);
  1044. }
  1045. menu.addSeparator();
  1046. menu.addCommandItem (commandManager, JucerCommandIDs::zoomIn);
  1047. menu.addCommandItem (commandManager, JucerCommandIDs::zoomOut);
  1048. menu.addCommandItem (commandManager, JucerCommandIDs::zoomNormal);
  1049. menu.addSeparator();
  1050. menu.addCommandItem (commandManager, JucerCommandIDs::test);
  1051. menu.addSeparator();
  1052. {
  1053. PopupMenu overlays;
  1054. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay0);
  1055. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay33);
  1056. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay66);
  1057. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay100);
  1058. menu.addSubMenu ("Component Overlay", overlays, holder != nullptr);
  1059. }
  1060. }
  1061. void handleGUIEditorMenuCommand (int menuItemID)
  1062. {
  1063. if (auto* ed = JucerDocumentEditor::getActiveDocumentHolder())
  1064. {
  1065. int gridIndex = menuItemID - gridSnapMenuItemBase;
  1066. if (isPositiveAndBelow (gridIndex, numElementsInArray (snapSizes)))
  1067. {
  1068. auto& doc = *ed->getDocument();
  1069. doc.setSnappingGrid (snapSizes [gridIndex],
  1070. doc.isSnapActive (false),
  1071. doc.isSnapShown());
  1072. }
  1073. }
  1074. }
  1075. void registerGUIEditorCommands()
  1076. {
  1077. JucerDocumentEditor dh (nullptr);
  1078. ProjucerApplication::getCommandManager().registerAllCommandsForTarget (&dh);
  1079. }