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.

1325 lines
49KB

  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. #include "../../Application/jucer_Headers.h"
  19. #include "../../Settings/jucer_AppearanceSettings.h"
  20. #include "../../Application/jucer_Application.h"
  21. #include "jucer_JucerDocumentEditor.h"
  22. #include "jucer_TestComponent.h"
  23. #include "../jucer_ObjectTypes.h"
  24. #include "jucer_ComponentLayoutPanel.h"
  25. #include "jucer_PaintRoutinePanel.h"
  26. #include "jucer_ResourceEditorPanel.h"
  27. #include "../Properties/jucer_ComponentTextProperty.h"
  28. #include "../Properties/jucer_ComponentChoiceProperty.h"
  29. #include "../UI/jucer_JucerCommandIDs.h"
  30. //==============================================================================
  31. class ExtraMethodsList : public PropertyComponent,
  32. public ListBoxModel,
  33. private ChangeListener
  34. {
  35. public:
  36. ExtraMethodsList (JucerDocument& doc)
  37. : PropertyComponent ("extra callbacks", 250),
  38. document (doc)
  39. {
  40. listBox.reset (new ListBox (String(), this));
  41. addAndMakeVisible (listBox.get());
  42. listBox->setRowHeight (22);
  43. document.addChangeListener (this);
  44. }
  45. ~ExtraMethodsList() override
  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 ((float) 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. private:
  99. void changeListenerCallback (ChangeBroadcaster*) override
  100. {
  101. refresh();
  102. }
  103. JucerDocument& document;
  104. std::unique_ptr<ListBox> listBox;
  105. StringArray baseClasses, returnValues, methods, initialContents;
  106. };
  107. //==============================================================================
  108. class ClassPropertiesPanel : public Component,
  109. private ChangeListener
  110. {
  111. public:
  112. explicit 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() override
  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. explicit ComponentClassNameProperty (JucerDocument& doc)
  161. : ComponentTextProperty<Component> ("Class name", 128, false, nullptr, 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. explicit ComponentCompNameProperty (JucerDocument& doc)
  171. : ComponentTextProperty<Component> ("Component name", 200, false, nullptr, 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. explicit ComponentParentClassesProperty (JucerDocument& doc)
  181. : ComponentTextProperty<Component> ("Parent classes", 512, false, nullptr, 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. explicit ComponentConstructorParamsProperty (JucerDocument& doc)
  191. : ComponentTextProperty<Component> ("Constructor params", 2048, false, nullptr, 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. explicit ComponentInitialisersProperty (JucerDocument& doc)
  201. : ComponentTextProperty <Component> ("Member initialisers", 16384, true, nullptr, 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, nullptr, 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. explicit FixedSizeProperty (JucerDocument& doc)
  238. : ComponentChoiceProperty<Component> ("Fixed size", nullptr, 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. explicit TemplateFileProperty (JucerDocument& doc)
  251. : ComponentTextProperty<Component> ("Template file", 2048, false, nullptr, 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)) != nullptr
  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 == nullptr)
  396. {
  397. for (int i = 0; i < tabbedComponent.getNumTabs(); ++i)
  398. {
  399. if (auto 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. auto root = projectProps.getXmlValue ("GUIComponentsLastTab");
  493. if (root == nullptr)
  494. root.reset (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. if (auto* project = document->getCppDocument().getProject())
  508. if (auto root = project->getStoredProperties().getXmlValue ("GUIComponentsLastTab"))
  509. if (auto child = root->getChildByName (document->getCppFile().getFileName()))
  510. tabbedComponent.setCurrentTabIndex (child->getIntAttribute ("tab"));
  511. }
  512. //==============================================================================
  513. bool JucerDocumentEditor::isSomethingSelected() const
  514. {
  515. if (auto* layout = getCurrentLayout())
  516. return layout->getSelectedSet().getNumSelected() > 0;
  517. if (auto* routine = getCurrentPaintRoutine())
  518. return routine->getSelectedElements().getNumSelected() > 0;
  519. return false;
  520. }
  521. bool JucerDocumentEditor::areMultipleThingsSelected() const
  522. {
  523. if (auto* layout = getCurrentLayout())
  524. return layout->getSelectedSet().getNumSelected() > 1;
  525. if (auto* routine = getCurrentPaintRoutine())
  526. return routine->getSelectedElements().getNumSelected() > 1;
  527. return false;
  528. }
  529. //==============================================================================
  530. void JucerDocumentEditor::getAllCommands (Array <CommandID>& commands)
  531. {
  532. const CommandID ids[] =
  533. {
  534. JucerCommandIDs::test,
  535. JucerCommandIDs::toFront,
  536. JucerCommandIDs::toBack,
  537. JucerCommandIDs::group,
  538. JucerCommandIDs::ungroup,
  539. JucerCommandIDs::bringBackLostItems,
  540. JucerCommandIDs::enableSnapToGrid,
  541. JucerCommandIDs::showGrid,
  542. JucerCommandIDs::editCompLayout,
  543. JucerCommandIDs::editCompGraphics,
  544. JucerCommandIDs::zoomIn,
  545. JucerCommandIDs::zoomOut,
  546. JucerCommandIDs::zoomNormal,
  547. JucerCommandIDs::spaceBarDrag,
  548. JucerCommandIDs::compOverlay0,
  549. JucerCommandIDs::compOverlay33,
  550. JucerCommandIDs::compOverlay66,
  551. JucerCommandIDs::compOverlay100,
  552. JucerCommandIDs::alignTop,
  553. JucerCommandIDs::alignRight,
  554. JucerCommandIDs::alignBottom,
  555. JucerCommandIDs::alignLeft,
  556. StandardApplicationCommandIDs::undo,
  557. StandardApplicationCommandIDs::redo,
  558. StandardApplicationCommandIDs::cut,
  559. StandardApplicationCommandIDs::copy,
  560. StandardApplicationCommandIDs::paste,
  561. StandardApplicationCommandIDs::del,
  562. StandardApplicationCommandIDs::selectAll,
  563. StandardApplicationCommandIDs::deselectAll
  564. };
  565. commands.addArray (ids, numElementsInArray (ids));
  566. for (int i = 0; i < ObjectTypes::numComponentTypes; ++i)
  567. commands.add (JucerCommandIDs::newComponentBase + i);
  568. for (int i = 0; i < ObjectTypes::numElementTypes; ++i)
  569. commands.add (JucerCommandIDs::newElementBase + i);
  570. }
  571. void JucerDocumentEditor::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  572. {
  573. ComponentLayout* const currentLayout = getCurrentLayout();
  574. PaintRoutine* const currentPaintRoutine = getCurrentPaintRoutine();
  575. const int cmd = ModifierKeys::commandModifier;
  576. const int shift = ModifierKeys::shiftModifier;
  577. if (commandID >= JucerCommandIDs::newComponentBase
  578. && commandID < JucerCommandIDs::newComponentBase + ObjectTypes::numComponentTypes)
  579. {
  580. const int index = commandID - JucerCommandIDs::newComponentBase;
  581. result.setInfo ("New " + ObjectTypes::componentTypeHandlers [index]->getTypeName(),
  582. "Creates a new " + ObjectTypes::componentTypeHandlers [index]->getTypeName(),
  583. CommandCategories::editing, 0);
  584. return;
  585. }
  586. if (commandID >= JucerCommandIDs::newElementBase
  587. && commandID < JucerCommandIDs::newElementBase + ObjectTypes::numElementTypes)
  588. {
  589. const int index = commandID - JucerCommandIDs::newElementBase;
  590. result.setInfo (String ("New ") + ObjectTypes::elementTypeNames [index],
  591. String ("Adds a new ") + ObjectTypes::elementTypeNames [index],
  592. CommandCategories::editing, 0);
  593. result.setActive (currentPaintRoutine != nullptr);
  594. return;
  595. }
  596. switch (commandID)
  597. {
  598. case JucerCommandIDs::toFront:
  599. result.setInfo (TRANS("Bring to front"), TRANS("Brings the currently selected component to the front."), CommandCategories::editing, 0);
  600. result.setActive (isSomethingSelected());
  601. result.defaultKeypresses.add (KeyPress ('f', cmd, 0));
  602. break;
  603. case JucerCommandIDs::toBack:
  604. result.setInfo (TRANS("Send to back"), TRANS("Sends the currently selected component to the back."), CommandCategories::editing, 0);
  605. result.setActive (isSomethingSelected());
  606. result.defaultKeypresses.add (KeyPress ('b', cmd, 0));
  607. break;
  608. case JucerCommandIDs::group:
  609. result.setInfo (TRANS("Group selected items"), TRANS("Turns the currently selected elements into a single group object."), CommandCategories::editing, 0);
  610. result.setActive (currentPaintRoutine != nullptr && currentPaintRoutine->getSelectedElements().getNumSelected() > 1);
  611. result.defaultKeypresses.add (KeyPress ('k', cmd, 0));
  612. break;
  613. case JucerCommandIDs::ungroup:
  614. result.setInfo (TRANS("Ungroup selected items"), TRANS("Turns the currently selected elements into a single group object."), CommandCategories::editing, 0);
  615. result.setActive (currentPaintRoutine != nullptr
  616. && currentPaintRoutine->getSelectedElements().getNumSelected() == 1
  617. && currentPaintRoutine->getSelectedElements().getSelectedItem (0)->getTypeName() == "Group");
  618. result.defaultKeypresses.add (KeyPress ('k', cmd | shift, 0));
  619. break;
  620. case JucerCommandIDs::test:
  621. result.setInfo (TRANS("Test component..."), TRANS("Runs the current component interactively."), CommandCategories::view, 0);
  622. result.defaultKeypresses.add (KeyPress ('t', cmd, 0));
  623. break;
  624. case JucerCommandIDs::enableSnapToGrid:
  625. result.setInfo (TRANS("Enable snap-to-grid"), TRANS("Toggles whether components' positions are aligned to a grid."), CommandCategories::view, 0);
  626. result.setTicked (document != nullptr && document->isSnapActive (false));
  627. result.defaultKeypresses.add (KeyPress ('g', cmd, 0));
  628. break;
  629. case JucerCommandIDs::showGrid:
  630. result.setInfo (TRANS("Show snap-to-grid"), TRANS("Toggles whether the snapping grid is displayed on-screen."), CommandCategories::view, 0);
  631. result.setTicked (document != nullptr && document->isSnapShown());
  632. result.defaultKeypresses.add (KeyPress ('g', cmd | shift, 0));
  633. break;
  634. case JucerCommandIDs::editCompLayout:
  635. result.setInfo (TRANS("Edit sub-component layout"), TRANS("Switches to the sub-component editor view."), CommandCategories::view, 0);
  636. result.setTicked (currentLayout != nullptr);
  637. result.defaultKeypresses.add (KeyPress ('n', cmd, 0));
  638. break;
  639. case JucerCommandIDs::editCompGraphics:
  640. result.setInfo (TRANS("Edit background graphics"), TRANS("Switches to the background graphics editor view."), CommandCategories::view, 0);
  641. result.setTicked (currentPaintRoutine != nullptr);
  642. result.defaultKeypresses.add (KeyPress ('m', cmd, 0));
  643. break;
  644. case JucerCommandIDs::bringBackLostItems:
  645. 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);
  646. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  647. result.defaultKeypresses.add (KeyPress ('m', cmd, 0));
  648. break;
  649. case JucerCommandIDs::zoomIn:
  650. result.setInfo (TRANS("Zoom in"), TRANS("Zooms in on the current component."), CommandCategories::editing, 0);
  651. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  652. result.defaultKeypresses.add (KeyPress (']', cmd, 0));
  653. break;
  654. case JucerCommandIDs::zoomOut:
  655. result.setInfo (TRANS("Zoom out"), TRANS("Zooms out on the current component."), CommandCategories::editing, 0);
  656. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  657. result.defaultKeypresses.add (KeyPress ('[', cmd, 0));
  658. break;
  659. case JucerCommandIDs::zoomNormal:
  660. result.setInfo (TRANS("Zoom to 100%"), TRANS("Restores the zoom level to normal."), CommandCategories::editing, 0);
  661. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  662. result.defaultKeypresses.add (KeyPress ('1', cmd, 0));
  663. break;
  664. case JucerCommandIDs::spaceBarDrag:
  665. result.setInfo (TRANS("Scroll while dragging mouse"), TRANS("When held down, this key lets you scroll around by dragging with the mouse."),
  666. CommandCategories::view, ApplicationCommandInfo::wantsKeyUpDownCallbacks);
  667. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  668. result.defaultKeypresses.add (KeyPress (KeyPress::spaceKey, 0, 0));
  669. break;
  670. case JucerCommandIDs::compOverlay0:
  671. case JucerCommandIDs::compOverlay33:
  672. case JucerCommandIDs::compOverlay66:
  673. case JucerCommandIDs::compOverlay100:
  674. {
  675. int amount = 0, num = 0;
  676. if (commandID == JucerCommandIDs::compOverlay33)
  677. {
  678. amount = 33;
  679. num = 1;
  680. }
  681. else if (commandID == JucerCommandIDs::compOverlay66)
  682. {
  683. amount = 66;
  684. num = 2;
  685. }
  686. else if (commandID == JucerCommandIDs::compOverlay100)
  687. {
  688. amount = 100;
  689. num = 3;
  690. }
  691. result.defaultKeypresses.add (KeyPress ('2' + num, cmd, 0));
  692. int currentAmount = 0;
  693. if (document != nullptr && document->getComponentOverlayOpacity() > 0.9f)
  694. currentAmount = 100;
  695. else if (document != nullptr && document->getComponentOverlayOpacity() > 0.6f)
  696. currentAmount = 66;
  697. else if (document != nullptr && document->getComponentOverlayOpacity() > 0.3f)
  698. currentAmount = 33;
  699. result.setInfo (commandID == JucerCommandIDs::compOverlay0
  700. ? TRANS("No component overlay")
  701. : TRANS("Overlay with opacity of 123%").replace ("123", String (amount)),
  702. TRANS("Changes the opacity of the components that are shown over the top of the graphics editor."),
  703. CommandCategories::view, 0);
  704. result.setActive (currentPaintRoutine != nullptr && document->getComponentLayout() != nullptr);
  705. result.setTicked (amount == currentAmount);
  706. }
  707. break;
  708. case JucerCommandIDs::alignTop:
  709. result.setInfo (TRANS ("Align top"),
  710. TRANS ("Aligns the top edges of all selected components to the first component that was selected."),
  711. CommandCategories::editing, 0);
  712. result.setActive (areMultipleThingsSelected());
  713. break;
  714. case JucerCommandIDs::alignRight:
  715. result.setInfo (TRANS ("Align right"),
  716. TRANS ("Aligns the right edges of all selected components to the first component that was selected."),
  717. CommandCategories::editing, 0);
  718. result.setActive (areMultipleThingsSelected());
  719. break;
  720. case JucerCommandIDs::alignBottom:
  721. result.setInfo (TRANS ("Align bottom"),
  722. TRANS ("Aligns the bottom edges of all selected components to the first component that was selected."),
  723. CommandCategories::editing, 0);
  724. result.setActive (areMultipleThingsSelected());
  725. break;
  726. case JucerCommandIDs::alignLeft:
  727. result.setInfo (TRANS ("Align left"),
  728. TRANS ("Aligns the left edges of all selected components to the first component that was selected."),
  729. CommandCategories::editing, 0);
  730. result.setActive (areMultipleThingsSelected());
  731. break;
  732. case StandardApplicationCommandIDs::undo:
  733. result.setInfo (TRANS ("Undo"), TRANS ("Undo"), "Editing", 0);
  734. result.setActive (document != nullptr && document->getUndoManager().canUndo());
  735. result.defaultKeypresses.add (KeyPress ('z', cmd, 0));
  736. break;
  737. case StandardApplicationCommandIDs::redo:
  738. result.setInfo (TRANS ("Redo"), TRANS ("Redo"), "Editing", 0);
  739. result.setActive (document != nullptr && document->getUndoManager().canRedo());
  740. result.defaultKeypresses.add (KeyPress ('z', cmd | shift, 0));
  741. break;
  742. case StandardApplicationCommandIDs::cut:
  743. result.setInfo (TRANS ("Cut"), String(), "Editing", 0);
  744. result.setActive (isSomethingSelected());
  745. result.defaultKeypresses.add (KeyPress ('x', cmd, 0));
  746. break;
  747. case StandardApplicationCommandIDs::copy:
  748. result.setInfo (TRANS ("Copy"), String(), "Editing", 0);
  749. result.setActive (isSomethingSelected());
  750. result.defaultKeypresses.add (KeyPress ('c', cmd, 0));
  751. break;
  752. case StandardApplicationCommandIDs::paste:
  753. {
  754. result.setInfo (TRANS ("Paste"), String(), "Editing", 0);
  755. result.defaultKeypresses.add (KeyPress ('v', cmd, 0));
  756. bool canPaste = false;
  757. if (auto doc = parseXML (SystemClipboard::getTextFromClipboard()))
  758. {
  759. if (doc->hasTagName (ComponentLayout::clipboardXmlTag))
  760. canPaste = (currentLayout != nullptr);
  761. else if (doc->hasTagName (PaintRoutine::clipboardXmlTag))
  762. canPaste = (currentPaintRoutine != nullptr);
  763. }
  764. result.setActive (canPaste);
  765. }
  766. break;
  767. case StandardApplicationCommandIDs::del:
  768. result.setInfo (TRANS ("Delete"), String(), "Editing", 0);
  769. result.setActive (isSomethingSelected());
  770. break;
  771. case StandardApplicationCommandIDs::selectAll:
  772. result.setInfo (TRANS ("Select All"), String(), "Editing", 0);
  773. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  774. result.defaultKeypresses.add (KeyPress ('a', cmd, 0));
  775. break;
  776. case StandardApplicationCommandIDs::deselectAll:
  777. result.setInfo (TRANS ("Deselect All"), String(), "Editing", 0);
  778. result.setActive (currentPaintRoutine != nullptr || currentLayout != nullptr);
  779. result.defaultKeypresses.add (KeyPress ('d', cmd, 0));
  780. break;
  781. default:
  782. break;
  783. }
  784. }
  785. bool JucerDocumentEditor::perform (const InvocationInfo& info)
  786. {
  787. ComponentLayout* const currentLayout = getCurrentLayout();
  788. PaintRoutine* const currentPaintRoutine = getCurrentPaintRoutine();
  789. document->beginTransaction();
  790. if (info.commandID >= JucerCommandIDs::newComponentBase
  791. && info.commandID < JucerCommandIDs::newComponentBase + ObjectTypes::numComponentTypes)
  792. {
  793. addComponent (info.commandID - JucerCommandIDs::newComponentBase);
  794. return true;
  795. }
  796. if (info.commandID >= JucerCommandIDs::newElementBase
  797. && info.commandID < JucerCommandIDs::newElementBase + ObjectTypes::numElementTypes)
  798. {
  799. addElement (info.commandID - JucerCommandIDs::newElementBase);
  800. return true;
  801. }
  802. switch (info.commandID)
  803. {
  804. case StandardApplicationCommandIDs::undo:
  805. document->getUndoManager().undo();
  806. document->dispatchPendingMessages();
  807. break;
  808. case StandardApplicationCommandIDs::redo:
  809. document->getUndoManager().redo();
  810. document->dispatchPendingMessages();
  811. break;
  812. case JucerCommandIDs::test:
  813. TestComponent::showInDialogBox (*document);
  814. break;
  815. case JucerCommandIDs::enableSnapToGrid:
  816. document->setSnappingGrid (document->getSnappingGridSize(),
  817. ! document->isSnapActive (false),
  818. document->isSnapShown());
  819. break;
  820. case JucerCommandIDs::showGrid:
  821. document->setSnappingGrid (document->getSnappingGridSize(),
  822. document->isSnapActive (false),
  823. ! document->isSnapShown());
  824. break;
  825. case JucerCommandIDs::editCompLayout:
  826. showLayout();
  827. break;
  828. case JucerCommandIDs::editCompGraphics:
  829. showGraphics (nullptr);
  830. break;
  831. case JucerCommandIDs::zoomIn: setZoom (snapToIntegerZoom (getZoom() * 2.0)); break;
  832. case JucerCommandIDs::zoomOut: setZoom (snapToIntegerZoom (getZoom() / 2.0)); break;
  833. case JucerCommandIDs::zoomNormal: setZoom (1.0); break;
  834. case JucerCommandIDs::spaceBarDrag:
  835. if (EditingPanelBase* panel = dynamic_cast<EditingPanelBase*> (tabbedComponent.getCurrentContentComponent()))
  836. panel->dragKeyHeldDown (info.isKeyDown);
  837. break;
  838. case JucerCommandIDs::compOverlay0:
  839. case JucerCommandIDs::compOverlay33:
  840. case JucerCommandIDs::compOverlay66:
  841. case JucerCommandIDs::compOverlay100:
  842. {
  843. int amount = 0;
  844. if (info.commandID == JucerCommandIDs::compOverlay33)
  845. amount = 33;
  846. else if (info.commandID == JucerCommandIDs::compOverlay66)
  847. amount = 66;
  848. else if (info.commandID == JucerCommandIDs::compOverlay100)
  849. amount = 100;
  850. document->setComponentOverlayOpacity ((float) amount * 0.01f);
  851. }
  852. break;
  853. case JucerCommandIDs::bringBackLostItems:
  854. if (EditingPanelBase* panel = dynamic_cast<EditingPanelBase*> (tabbedComponent.getCurrentContentComponent()))
  855. {
  856. int w = panel->getComponentArea().getWidth();
  857. int h = panel->getComponentArea().getHeight();
  858. if (currentPaintRoutine != nullptr)
  859. currentPaintRoutine->bringLostItemsBackOnScreen (panel->getComponentArea());
  860. else if (currentLayout != nullptr)
  861. currentLayout->bringLostItemsBackOnScreen (w, h);
  862. }
  863. break;
  864. case JucerCommandIDs::toFront:
  865. if (currentLayout != nullptr)
  866. currentLayout->selectedToFront();
  867. else if (currentPaintRoutine != nullptr)
  868. currentPaintRoutine->selectedToFront();
  869. break;
  870. case JucerCommandIDs::toBack:
  871. if (currentLayout != nullptr)
  872. currentLayout->selectedToBack();
  873. else if (currentPaintRoutine != nullptr)
  874. currentPaintRoutine->selectedToBack();
  875. break;
  876. case JucerCommandIDs::group:
  877. if (currentPaintRoutine != nullptr)
  878. currentPaintRoutine->groupSelected();
  879. break;
  880. case JucerCommandIDs::ungroup:
  881. if (currentPaintRoutine != nullptr)
  882. currentPaintRoutine->ungroupSelected();
  883. break;
  884. case JucerCommandIDs::alignTop:
  885. if (currentLayout != nullptr)
  886. currentLayout->alignTop();
  887. else if (currentPaintRoutine != nullptr)
  888. currentPaintRoutine->alignTop();
  889. break;
  890. case JucerCommandIDs::alignRight:
  891. if (currentLayout != nullptr)
  892. currentLayout->alignRight();
  893. else if (currentPaintRoutine != nullptr)
  894. currentPaintRoutine->alignRight();
  895. break;
  896. case JucerCommandIDs::alignBottom:
  897. if (currentLayout != nullptr)
  898. currentLayout->alignBottom();
  899. else if (currentPaintRoutine != nullptr)
  900. currentPaintRoutine->alignBottom();
  901. break;
  902. case JucerCommandIDs::alignLeft:
  903. if (currentLayout != nullptr)
  904. currentLayout->alignLeft();
  905. else if (currentPaintRoutine != nullptr)
  906. currentPaintRoutine->alignLeft();
  907. break;
  908. case StandardApplicationCommandIDs::cut:
  909. if (currentLayout != nullptr)
  910. {
  911. currentLayout->copySelectedToClipboard();
  912. currentLayout->deleteSelected();
  913. }
  914. else if (currentPaintRoutine != nullptr)
  915. {
  916. currentPaintRoutine->copySelectedToClipboard();
  917. currentPaintRoutine->deleteSelected();
  918. }
  919. break;
  920. case StandardApplicationCommandIDs::copy:
  921. if (currentLayout != nullptr)
  922. currentLayout->copySelectedToClipboard();
  923. else if (currentPaintRoutine != nullptr)
  924. currentPaintRoutine->copySelectedToClipboard();
  925. break;
  926. case StandardApplicationCommandIDs::paste:
  927. {
  928. if (auto doc = parseXML (SystemClipboard::getTextFromClipboard()))
  929. {
  930. if (doc->hasTagName (ComponentLayout::clipboardXmlTag))
  931. {
  932. if (currentLayout != nullptr)
  933. currentLayout->paste();
  934. }
  935. else if (doc->hasTagName (PaintRoutine::clipboardXmlTag))
  936. {
  937. if (currentPaintRoutine != nullptr)
  938. currentPaintRoutine->paste();
  939. }
  940. }
  941. }
  942. break;
  943. case StandardApplicationCommandIDs::del:
  944. if (currentLayout != nullptr)
  945. currentLayout->deleteSelected();
  946. else if (currentPaintRoutine != nullptr)
  947. currentPaintRoutine->deleteSelected();
  948. break;
  949. case StandardApplicationCommandIDs::selectAll:
  950. if (currentLayout != nullptr)
  951. currentLayout->selectAll();
  952. else if (currentPaintRoutine != nullptr)
  953. currentPaintRoutine->selectAll();
  954. break;
  955. case StandardApplicationCommandIDs::deselectAll:
  956. if (currentLayout != nullptr)
  957. {
  958. currentLayout->getSelectedSet().deselectAll();
  959. }
  960. else if (currentPaintRoutine != nullptr)
  961. {
  962. currentPaintRoutine->getSelectedElements().deselectAll();
  963. currentPaintRoutine->getSelectedPoints().deselectAll();
  964. }
  965. break;
  966. default:
  967. return false;
  968. }
  969. document->beginTransaction();
  970. return true;
  971. }
  972. bool JucerDocumentEditor::keyPressed (const KeyPress& key)
  973. {
  974. if (key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  975. {
  976. ProjucerApplication::getCommandManager().invokeDirectly (StandardApplicationCommandIDs::del, true);
  977. return true;
  978. }
  979. return false;
  980. }
  981. JucerDocumentEditor* JucerDocumentEditor::getActiveDocumentHolder()
  982. {
  983. ApplicationCommandInfo info (0);
  984. return dynamic_cast<JucerDocumentEditor*> (ProjucerApplication::getCommandManager()
  985. .getTargetForCommand (JucerCommandIDs::editCompLayout, info));
  986. }
  987. Image JucerDocumentEditor::createComponentLayerSnapshot() const
  988. {
  989. if (compLayoutPanel != nullptr)
  990. return compLayoutPanel->createComponentSnapshot();
  991. return {};
  992. }
  993. const int gridSnapMenuItemBase = 0x8723620;
  994. const int snapSizes[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32 };
  995. PopupMenu createGUIEditorMenu();
  996. PopupMenu createGUIEditorMenu()
  997. {
  998. PopupMenu menu;
  999. auto* commandManager = &ProjucerApplication::getCommandManager();
  1000. menu.addCommandItem (commandManager, CommandIDs::addNewGUIFile);
  1001. menu.addSeparator();
  1002. menu.addCommandItem (commandManager, JucerCommandIDs::editCompLayout);
  1003. menu.addCommandItem (commandManager, JucerCommandIDs::editCompGraphics);
  1004. menu.addSeparator();
  1005. PopupMenu newComps;
  1006. for (int i = 0; i < ObjectTypes::numComponentTypes; ++i)
  1007. newComps.addCommandItem (commandManager, JucerCommandIDs::newComponentBase + i);
  1008. menu.addSubMenu ("Add new component", newComps);
  1009. PopupMenu newElements;
  1010. for (int i = 0; i < ObjectTypes::numElementTypes; ++i)
  1011. newElements.addCommandItem (commandManager, JucerCommandIDs::newElementBase + i);
  1012. menu.addSubMenu ("Add new graphic element", newElements);
  1013. menu.addSeparator();
  1014. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut);
  1015. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy);
  1016. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste);
  1017. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del);
  1018. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll);
  1019. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll);
  1020. menu.addSeparator();
  1021. menu.addCommandItem (commandManager, JucerCommandIDs::toFront);
  1022. menu.addCommandItem (commandManager, JucerCommandIDs::toBack);
  1023. menu.addSeparator();
  1024. menu.addCommandItem (commandManager, JucerCommandIDs::group);
  1025. menu.addCommandItem (commandManager, JucerCommandIDs::ungroup);
  1026. menu.addSeparator();
  1027. menu.addCommandItem (commandManager, JucerCommandIDs::bringBackLostItems);
  1028. menu.addSeparator();
  1029. menu.addCommandItem (commandManager, JucerCommandIDs::showGrid);
  1030. menu.addCommandItem (commandManager, JucerCommandIDs::enableSnapToGrid);
  1031. auto* holder = JucerDocumentEditor::getActiveDocumentHolder();
  1032. {
  1033. auto currentSnapSize = holder != nullptr ? holder->getDocument()->getSnappingGridSize() : -1;
  1034. PopupMenu m;
  1035. for (int i = 0; i < numElementsInArray (snapSizes); ++i)
  1036. m.addItem (gridSnapMenuItemBase + i, String (snapSizes[i]) + " pixels",
  1037. true, snapSizes[i] == currentSnapSize);
  1038. menu.addSubMenu ("Grid size", m, currentSnapSize >= 0);
  1039. }
  1040. menu.addSeparator();
  1041. menu.addCommandItem (commandManager, JucerCommandIDs::zoomIn);
  1042. menu.addCommandItem (commandManager, JucerCommandIDs::zoomOut);
  1043. menu.addCommandItem (commandManager, JucerCommandIDs::zoomNormal);
  1044. menu.addSeparator();
  1045. menu.addCommandItem (commandManager, JucerCommandIDs::test);
  1046. menu.addSeparator();
  1047. {
  1048. PopupMenu overlays;
  1049. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay0);
  1050. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay33);
  1051. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay66);
  1052. overlays.addCommandItem (commandManager, JucerCommandIDs::compOverlay100);
  1053. menu.addSubMenu ("Component Overlay", overlays, holder != nullptr);
  1054. }
  1055. return menu;
  1056. }
  1057. void handleGUIEditorMenuCommand (int);
  1058. void handleGUIEditorMenuCommand (int menuItemID)
  1059. {
  1060. if (auto* ed = JucerDocumentEditor::getActiveDocumentHolder())
  1061. {
  1062. int gridIndex = menuItemID - gridSnapMenuItemBase;
  1063. if (isPositiveAndBelow (gridIndex, numElementsInArray (snapSizes)))
  1064. {
  1065. auto& doc = *ed->getDocument();
  1066. doc.setSnappingGrid (snapSizes [gridIndex],
  1067. doc.isSnapActive (false),
  1068. doc.isSnapShown());
  1069. }
  1070. }
  1071. }
  1072. void registerGUIEditorCommands();
  1073. void registerGUIEditorCommands()
  1074. {
  1075. JucerDocumentEditor dh (nullptr);
  1076. ProjucerApplication::getCommandManager().registerAllCommandsForTarget (&dh);
  1077. }