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.

853 lines
24KB

  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 "jucer_Application.h"
  21. #include "jucer_MainWindow.h"
  22. #include "../Wizards/jucer_NewProjectWizardClasses.h"
  23. #include "../Utility/UI/jucer_JucerTreeViewBase.h"
  24. #include "../ProjectSaving/jucer_ProjectSaver.h"
  25. //==============================================================================
  26. MainWindow::MainWindow()
  27. : DocumentWindow (ProjucerApplication::getApp().getApplicationName(),
  28. ProjucerApplication::getApp().lookAndFeel.getCurrentColourScheme()
  29. .getUIColour (LookAndFeel_V4::ColourScheme::UIColour::windowBackground),
  30. DocumentWindow::allButtons,
  31. false)
  32. {
  33. setUsingNativeTitleBar (true);
  34. #if ! JUCE_MAC
  35. setMenuBar (ProjucerApplication::getApp().getMenuModel());
  36. #endif
  37. createProjectContentCompIfNeeded();
  38. setResizable (true, false);
  39. centreWithSize (800, 600);
  40. ApplicationCommandManager& commandManager = ProjucerApplication::getCommandManager();
  41. // Register all the app commands..
  42. commandManager.registerAllCommandsForTarget (this);
  43. commandManager.registerAllCommandsForTarget (getProjectContentComponent());
  44. // update key mappings..
  45. {
  46. commandManager.getKeyMappings()->resetToDefaultMappings();
  47. std::unique_ptr<XmlElement> keys (getGlobalProperties().getXmlValue ("keyMappings"));
  48. if (keys != nullptr)
  49. commandManager.getKeyMappings()->restoreFromXml (*keys);
  50. addKeyListener (commandManager.getKeyMappings());
  51. }
  52. // don't want the window to take focus when the title-bar is clicked..
  53. setWantsKeyboardFocus (false);
  54. getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  55. projectNameValue.addListener (this);
  56. setResizeLimits (600, 500, 32000, 32000);
  57. }
  58. MainWindow::~MainWindow()
  59. {
  60. #if ! JUCE_MAC
  61. setMenuBar (nullptr);
  62. #endif
  63. removeKeyListener (ProjucerApplication::getCommandManager().getKeyMappings());
  64. // save the current size and position to our settings file..
  65. getGlobalProperties().setValue ("lastMainWindowPos", getWindowStateAsString());
  66. clearContentComponent();
  67. currentProject.reset();
  68. }
  69. void MainWindow::createProjectContentCompIfNeeded()
  70. {
  71. if (getProjectContentComponent() == nullptr)
  72. {
  73. clearContentComponent();
  74. setContentOwned (new ProjectContentComponent(), false);
  75. jassert (getProjectContentComponent() != nullptr);
  76. }
  77. }
  78. void MainWindow::setTitleBarIcon()
  79. {
  80. if (auto* peer = getPeer())
  81. {
  82. if (currentProject != nullptr)
  83. {
  84. peer->setRepresentedFile (currentProject->getFile());
  85. peer->setIcon (ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize));
  86. }
  87. else
  88. {
  89. peer->setRepresentedFile ({});
  90. }
  91. }
  92. }
  93. void MainWindow::makeVisible()
  94. {
  95. restoreWindowPosition();
  96. setVisible (true);
  97. addToDesktop(); // (must add before restoring size so that fullscreen will work)
  98. restoreWindowPosition();
  99. setTitleBarIcon();
  100. getContentComponent()->grabKeyboardFocus();
  101. }
  102. ProjectContentComponent* MainWindow::getProjectContentComponent() const
  103. {
  104. return dynamic_cast<ProjectContentComponent*> (getContentComponent());
  105. }
  106. void MainWindow::closeButtonPressed()
  107. {
  108. ProjucerApplication::getApp().mainWindowList.closeWindow (this);
  109. }
  110. bool MainWindow::closeProject (Project* project, bool askUserToSave)
  111. {
  112. jassert (project == currentProject.get() && project != nullptr);
  113. if (project == nullptr)
  114. return true;
  115. project->getStoredProperties().setValue (getProjectWindowPosName(), getWindowStateAsString());
  116. if (auto* pcc = getProjectContentComponent())
  117. {
  118. pcc->saveTreeViewState();
  119. pcc->saveOpenDocumentList();
  120. pcc->hideEditor();
  121. }
  122. if (! ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*project, askUserToSave))
  123. return false;
  124. if (! askUserToSave || (project->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk))
  125. {
  126. setProject (nullptr);
  127. return true;
  128. }
  129. return false;
  130. }
  131. bool MainWindow::closeCurrentProject()
  132. {
  133. return currentProject == nullptr || closeProject (currentProject.get());
  134. }
  135. void MainWindow::moveProject (File newProjectFileToOpen)
  136. {
  137. auto openInIDE = currentProject->shouldOpenInIDEAfterSaving();
  138. closeProject (currentProject.get(), false);
  139. openFile (newProjectFileToOpen);
  140. if (currentProject != nullptr)
  141. {
  142. ProjucerApplication::getApp().getCommandManager().invokeDirectly (openInIDE ? CommandIDs::saveAndOpenInIDE
  143. : CommandIDs::saveProject,
  144. false);
  145. }
  146. }
  147. void MainWindow::setProject (Project* newProject)
  148. {
  149. createProjectContentCompIfNeeded();
  150. getProjectContentComponent()->setProject (newProject);
  151. currentProject.reset (newProject);
  152. if (currentProject != nullptr)
  153. projectNameValue.referTo (currentProject->getProjectValue (Ids::name));
  154. else
  155. projectNameValue.referTo (Value());
  156. if (newProject != nullptr)
  157. {
  158. if (auto* peer = getPeer())
  159. peer->setRepresentedFile (newProject->getFile());
  160. }
  161. ProjucerApplication::getCommandManager().commandStatusChanged();
  162. }
  163. void MainWindow::restoreWindowPosition()
  164. {
  165. String windowState;
  166. if (currentProject != nullptr)
  167. windowState = currentProject->getStoredProperties().getValue (getProjectWindowPosName());
  168. if (windowState.isEmpty())
  169. windowState = getGlobalProperties().getValue ("lastMainWindowPos");
  170. restoreWindowStateFromString (windowState);
  171. }
  172. bool MainWindow::canOpenFile (const File& file) const
  173. {
  174. return (! file.isDirectory())
  175. && (file.hasFileExtension (Project::projectFileExtension)
  176. || ProjucerApplication::getApp().openDocumentManager.canOpenFile (file));
  177. }
  178. bool MainWindow::openFile (const File& file)
  179. {
  180. createProjectContentCompIfNeeded();
  181. if (file.hasFileExtension (Project::projectFileExtension))
  182. {
  183. std::unique_ptr<Project> newDoc (new Project (file));
  184. auto result = newDoc->loadFrom (file, true);
  185. if (result.wasOk() && closeCurrentProject())
  186. {
  187. setProject (newDoc.get());
  188. newDoc.release()->setChangedFlag (false);
  189. jassert (getProjectContentComponent() != nullptr);
  190. getProjectContentComponent()->reloadLastOpenDocuments();
  191. if (auto* p = getProject())
  192. p->updateDeprecatedProjectSettingsInteractively();
  193. return true;
  194. }
  195. }
  196. else if (file.exists())
  197. {
  198. return getProjectContentComponent()->showEditorForFile (file, true);
  199. }
  200. return false;
  201. }
  202. bool MainWindow::tryToOpenPIP (const File& pipFile)
  203. {
  204. PIPGenerator generator (pipFile);
  205. if (! generator.hasValidPIP())
  206. return false;
  207. auto generatorResult = generator.createJucerFile();
  208. if (generatorResult != Result::ok())
  209. {
  210. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  211. "PIP Error.",
  212. generatorResult.getErrorMessage());
  213. return false;
  214. }
  215. if (! generator.createMainCpp())
  216. {
  217. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  218. "PIP Error.",
  219. "Failed to create Main.cpp.");
  220. return false;
  221. }
  222. if (! ProjucerApplication::getApp().mainWindowList.openFile (generator.getJucerFile()))
  223. return false;
  224. openPIP (generator);
  225. return true;
  226. }
  227. static bool isDivider (const String& line)
  228. {
  229. auto afterIndent = line.trim();
  230. if (afterIndent.startsWith ("//") && afterIndent.length() > 20)
  231. {
  232. afterIndent = afterIndent.substring (2);
  233. if (afterIndent.containsOnly ("=")
  234. || afterIndent.containsOnly ("/")
  235. || afterIndent.containsOnly ("-"))
  236. {
  237. return true;
  238. }
  239. }
  240. return false;
  241. }
  242. static bool isEndOfCommentBlock (const String& line)
  243. {
  244. if (line.contains ("*/"))
  245. return true;
  246. return false;
  247. }
  248. static int getIndexOfCommentBlockStart (const StringArray& lines, int blockEndIndex)
  249. {
  250. for (int i = blockEndIndex; i >= 0; --i)
  251. {
  252. if (lines[i].contains ("/*"))
  253. return i;
  254. }
  255. return 0;
  256. }
  257. static int findBestLineToScrollTo (StringArray lines, StringRef className)
  258. {
  259. for (auto line : lines)
  260. {
  261. if (line.contains ("struct " + className) || line.contains ("class " + className))
  262. {
  263. auto index = lines.indexOf (line);
  264. if (isDivider (lines[index - 1]))
  265. return index - 1;
  266. if (isEndOfCommentBlock (lines[index - 1]))
  267. {
  268. auto blockStartIndex = getIndexOfCommentBlockStart (lines, index - 1);
  269. if (blockStartIndex > 0 && isDivider (lines [blockStartIndex - 1]))
  270. return blockStartIndex - 1;
  271. return blockStartIndex;
  272. }
  273. return lines.indexOf (line);
  274. }
  275. }
  276. return 0;
  277. }
  278. void MainWindow::openPIP (PIPGenerator& generator)
  279. {
  280. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (generator.getJucerFile()))
  281. {
  282. if (auto* project = window->getProject())
  283. {
  284. project->setTemporaryDirectory (generator.getOutputDirectory());
  285. ProjectSaver liveBuildSaver (*project, project->getFile());
  286. liveBuildSaver.saveContentNeededForLiveBuild();
  287. if (auto* pcc = window->getProjectContentComponent())
  288. {
  289. pcc->invokeDirectly (CommandIDs::toggleBuildEnabled, true);
  290. pcc->invokeDirectly (CommandIDs::buildNow, true);
  291. pcc->invokeDirectly (CommandIDs::toggleContinuousBuild, true);
  292. auto fileToDisplay = generator.getPIPFile();
  293. if (fileToDisplay != File())
  294. {
  295. pcc->showEditorForFile (fileToDisplay, true);
  296. if (auto* sourceCodeEditor = dynamic_cast <SourceCodeEditor*> (pcc->getEditorComponent()))
  297. {
  298. sourceCodeEditor->editor->scrollToLine (findBestLineToScrollTo (StringArray::fromLines (fileToDisplay.loadFileAsString()),
  299. generator.getMainClassName()));
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. bool MainWindow::isInterestedInFileDrag (const StringArray& filenames)
  307. {
  308. for (auto& filename : filenames)
  309. if (canOpenFile (File (filename)))
  310. return true;
  311. return false;
  312. }
  313. void MainWindow::filesDropped (const StringArray& filenames, int /*mouseX*/, int /*mouseY*/)
  314. {
  315. for (auto& filename : filenames)
  316. {
  317. const File f (filename);
  318. if (tryToOpenPIP (f))
  319. continue;
  320. if (! isPIPFile (f) && (canOpenFile (f) && openFile (f)))
  321. break;
  322. }
  323. }
  324. bool MainWindow::shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails,
  325. StringArray& files, bool& canMoveFiles)
  326. {
  327. if (auto* tv = dynamic_cast<TreeView*> (sourceDetails.sourceComponent.get()))
  328. {
  329. Array<JucerTreeViewBase*> selected;
  330. for (int i = tv->getNumSelectedItems(); --i >= 0;)
  331. if (auto* b = dynamic_cast<JucerTreeViewBase*> (tv->getSelectedItem(i)))
  332. selected.add (b);
  333. if (! selected.isEmpty())
  334. {
  335. for (int i = selected.size(); --i >= 0;)
  336. {
  337. if (auto* jtvb = selected.getUnchecked(i))
  338. {
  339. auto f = jtvb->getDraggableFile();
  340. if (f.existsAsFile())
  341. files.add (f.getFullPathName());
  342. }
  343. }
  344. canMoveFiles = false;
  345. return ! files.isEmpty();
  346. }
  347. }
  348. return false;
  349. }
  350. void MainWindow::activeWindowStatusChanged()
  351. {
  352. DocumentWindow::activeWindowStatusChanged();
  353. if (auto* pcc = getProjectContentComponent())
  354. pcc->updateMissingFileStatuses();
  355. ProjucerApplication::getApp().openDocumentManager.reloadModifiedFiles();
  356. if (auto* p = getProject())
  357. {
  358. if (p->hasProjectBeenModified())
  359. {
  360. Component::SafePointer<Component> safePointer (this);
  361. MessageManager::callAsync ([=] ()
  362. {
  363. if (safePointer == nullptr)
  364. return; // bail out if the window has been deleted
  365. auto result = AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  366. TRANS ("The .jucer file has been modified since the last save."),
  367. TRANS ("Do you want to keep the current project or re-load from disk?"),
  368. TRANS ("Keep"),
  369. TRANS ("Re-load from disk"));
  370. if (safePointer == nullptr)
  371. return;
  372. if (result == 0)
  373. {
  374. if (auto* project = getProject())
  375. {
  376. auto oldTemporaryDirectory = project->getTemporaryDirectory();
  377. auto projectFile = project->getFile();
  378. setProject (nullptr);
  379. openFile (projectFile);
  380. if (oldTemporaryDirectory != File())
  381. if (auto* newProject = getProject())
  382. newProject->setTemporaryDirectory (oldTemporaryDirectory);
  383. }
  384. }
  385. else
  386. {
  387. ProjucerApplication::getApp().getCommandManager().invokeDirectly (CommandIDs::saveProject, true);
  388. }
  389. });
  390. }
  391. }
  392. }
  393. void MainWindow::showStartPage()
  394. {
  395. jassert (currentProject == nullptr);
  396. setContentOwned (createNewProjectWizardComponent(), true);
  397. centreWithSize (900, 630);
  398. setVisible (true);
  399. addToDesktop();
  400. getContentComponent()->grabKeyboardFocus();
  401. }
  402. //==============================================================================
  403. ApplicationCommandTarget* MainWindow::getNextCommandTarget()
  404. {
  405. return nullptr;
  406. }
  407. void MainWindow::getAllCommands (Array <CommandID>& commands)
  408. {
  409. const CommandID ids[] =
  410. {
  411. CommandIDs::closeWindow,
  412. CommandIDs::goToPreviousWindow,
  413. CommandIDs::goToNextWindow
  414. };
  415. commands.addArray (ids, numElementsInArray (ids));
  416. }
  417. void MainWindow::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  418. {
  419. switch (commandID)
  420. {
  421. case CommandIDs::closeWindow:
  422. result.setInfo ("Close Window", "Closes the current window", CommandCategories::general, 0);
  423. result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier, 0));
  424. break;
  425. case CommandIDs::goToPreviousWindow:
  426. result.setInfo ("Previous Window", "Activates the previous window", CommandCategories::general, 0);
  427. result.setActive (ProjucerApplication::getApp().mainWindowList.windows.size() > 1);
  428. result.defaultKeypresses.add (KeyPress (KeyPress::tabKey, ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier, 0));
  429. break;
  430. case CommandIDs::goToNextWindow:
  431. result.setInfo ("Next Window", "Activates the next window", CommandCategories::general, 0);
  432. result.setActive (ProjucerApplication::getApp().mainWindowList.windows.size() > 1);
  433. result.defaultKeypresses.add (KeyPress (KeyPress::tabKey, ModifierKeys::ctrlModifier, 0));
  434. break;
  435. default:
  436. break;
  437. }
  438. }
  439. bool MainWindow::perform (const InvocationInfo& info)
  440. {
  441. switch (info.commandID)
  442. {
  443. case CommandIDs::closeWindow:
  444. closeButtonPressed();
  445. break;
  446. case CommandIDs::goToPreviousWindow:
  447. ProjucerApplication::getApp().mainWindowList.goToSiblingWindow (this, -1);
  448. break;
  449. case CommandIDs::goToNextWindow:
  450. ProjucerApplication::getApp().mainWindowList.goToSiblingWindow (this, 1);
  451. break;
  452. default:
  453. return false;
  454. }
  455. return true;
  456. }
  457. void MainWindow::valueChanged (Value&)
  458. {
  459. if (currentProject != nullptr)
  460. setName (currentProject->getProjectNameString() + " - Projucer");
  461. else
  462. setName ("Projucer");
  463. }
  464. //==============================================================================
  465. MainWindowList::MainWindowList()
  466. {
  467. }
  468. void MainWindowList::forceCloseAllWindows()
  469. {
  470. windows.clear();
  471. }
  472. bool MainWindowList::askAllWindowsToClose()
  473. {
  474. saveCurrentlyOpenProjectList();
  475. while (windows.size() > 0)
  476. {
  477. if (! windows[0]->closeCurrentProject())
  478. return false;
  479. windows.remove (0);
  480. }
  481. return true;
  482. }
  483. void MainWindowList::createWindowIfNoneAreOpen()
  484. {
  485. if (windows.size() == 0)
  486. createNewMainWindow()->showStartPage();
  487. }
  488. void MainWindowList::closeWindow (MainWindow* w)
  489. {
  490. jassert (windows.contains (w));
  491. #if ! JUCE_MAC
  492. if (windows.size() == 1)
  493. {
  494. JUCEApplicationBase::getInstance()->systemRequestedQuit();
  495. }
  496. else
  497. #endif
  498. {
  499. if (w->closeCurrentProject())
  500. {
  501. windows.removeObject (w);
  502. saveCurrentlyOpenProjectList();
  503. }
  504. }
  505. }
  506. void MainWindowList::goToSiblingWindow (MainWindow* w, int delta)
  507. {
  508. auto index = windows.indexOf (w);
  509. if (index >= 0)
  510. if (auto* next = windows[(index + delta + windows.size()) % windows.size()])
  511. next->toFront (true);
  512. }
  513. void MainWindowList::openDocument (OpenDocumentManager::Document* doc, bool grabFocus)
  514. {
  515. auto& desktop = Desktop::getInstance();
  516. for (int i = desktop.getNumComponents(); --i >= 0;)
  517. {
  518. if (auto* mw = dynamic_cast<MainWindow*> (desktop.getComponent(i)))
  519. {
  520. if (auto* pcc = mw->getProjectContentComponent())
  521. {
  522. if (pcc->hasFileInRecentList (doc->getFile()))
  523. {
  524. mw->toFront (true);
  525. mw->getProjectContentComponent()->showDocument (doc, grabFocus);
  526. return;
  527. }
  528. }
  529. }
  530. }
  531. getFrontmostWindow()->getProjectContentComponent()->showDocument (doc, grabFocus);
  532. }
  533. bool MainWindowList::openFile (const File& file, bool openInBackground)
  534. {
  535. for (auto* w : windows)
  536. {
  537. if (w->getProject() != nullptr && w->getProject()->getFile() == file)
  538. {
  539. w->toFront (true);
  540. return true;
  541. }
  542. }
  543. if (file.hasFileExtension (Project::projectFileExtension))
  544. {
  545. auto previousFrontWindow = getFrontmostWindow();
  546. auto* w = getOrCreateEmptyWindow();
  547. bool ok = w->openFile (file);
  548. if (ok)
  549. {
  550. w->makeVisible();
  551. avoidSuperimposedWindows (w);
  552. }
  553. else
  554. {
  555. closeWindow (w);
  556. }
  557. if (openInBackground && (previousFrontWindow != nullptr))
  558. previousFrontWindow->toFront (true);
  559. return ok;
  560. }
  561. if (getFrontmostWindow()->tryToOpenPIP (file))
  562. return true;
  563. if (! isPIPFile (file) && file.exists())
  564. return getFrontmostWindow()->openFile (file);
  565. return false;
  566. }
  567. MainWindow* MainWindowList::createNewMainWindow()
  568. {
  569. auto w = new MainWindow();
  570. windows.add (w);
  571. w->restoreWindowPosition();
  572. avoidSuperimposedWindows (w);
  573. return w;
  574. }
  575. MainWindow* MainWindowList::getFrontmostWindow (bool createIfNotFound)
  576. {
  577. if (windows.isEmpty())
  578. {
  579. if (createIfNotFound)
  580. {
  581. auto* w = createNewMainWindow();
  582. avoidSuperimposedWindows (w);
  583. w->makeVisible();
  584. return w;
  585. }
  586. return nullptr;
  587. }
  588. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  589. {
  590. auto* mw = dynamic_cast<MainWindow*> (Desktop::getInstance().getComponent (i));
  591. if (windows.contains (mw))
  592. return mw;
  593. }
  594. return windows.getLast();
  595. }
  596. MainWindow* MainWindowList::getOrCreateEmptyWindow()
  597. {
  598. if (windows.size() == 0)
  599. return createNewMainWindow();
  600. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  601. {
  602. auto* mw = dynamic_cast<MainWindow*> (Desktop::getInstance().getComponent (i));
  603. if (windows.contains (mw) && mw->getProject() == nullptr)
  604. return mw;
  605. }
  606. return createNewMainWindow();
  607. }
  608. MainWindow* MainWindowList::getMainWindowForFile (const File& file)
  609. {
  610. if (windows.size() > 0)
  611. {
  612. for (auto* window : windows)
  613. {
  614. if (auto* project = window->getProject())
  615. {
  616. if (project->getFile() == file)
  617. return window;
  618. }
  619. }
  620. }
  621. return nullptr;
  622. }
  623. void MainWindowList::avoidSuperimposedWindows (MainWindow* const mw)
  624. {
  625. for (int i = windows.size(); --i >= 0;)
  626. {
  627. auto* other = windows.getUnchecked(i);
  628. auto b1 = mw->getBounds();
  629. auto b2 = other->getBounds();
  630. if (mw != other
  631. && std::abs (b1.getX() - b2.getX()) < 3
  632. && std::abs (b1.getY() - b2.getY()) < 3
  633. && std::abs (b1.getRight() - b2.getRight()) < 3
  634. && std::abs (b1.getBottom() - b2.getBottom()) < 3)
  635. {
  636. int dx = 40, dy = 30;
  637. if (b1.getCentreX() >= mw->getScreenBounds().getCentreX()) dx = -dx;
  638. if (b1.getCentreY() >= mw->getScreenBounds().getCentreY()) dy = -dy;
  639. mw->setBounds (b1.translated (dx, dy));
  640. }
  641. }
  642. }
  643. void MainWindowList::saveCurrentlyOpenProjectList()
  644. {
  645. Array<File> projects;
  646. auto& desktop = Desktop::getInstance();
  647. for (int i = 0; i < desktop.getNumComponents(); ++i)
  648. {
  649. if (auto* mw = dynamic_cast<MainWindow*> (desktop.getComponent(i)))
  650. if (auto* p = mw->getProject())
  651. if (! p->isTemporaryProject())
  652. projects.add (p->getFile());
  653. }
  654. getAppSettings().setLastProjects (projects);
  655. }
  656. void MainWindowList::reopenLastProjects()
  657. {
  658. for (auto& p : getAppSettings().getLastProjects())
  659. openFile (p, true);
  660. }
  661. void MainWindowList::sendLookAndFeelChange()
  662. {
  663. for (auto* w : windows)
  664. w->sendLookAndFeelChange();
  665. }
  666. Project* MainWindowList::getFrontmostProject()
  667. {
  668. auto& desktop = Desktop::getInstance();
  669. for (int i = desktop.getNumComponents(); --i >= 0;)
  670. if (auto* mw = dynamic_cast<MainWindow*> (desktop.getComponent(i)))
  671. if (auto* p = mw->getProject())
  672. return p;
  673. return nullptr;
  674. }