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.

1505 lines
53KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. void createGUIEditorMenu (PopupMenu&);
  14. void handleGUIEditorMenuCommand (int);
  15. void registerGUIEditorCommands();
  16. //==============================================================================
  17. struct ProjucerApplication::MainMenuModel : public MenuBarModel
  18. {
  19. MainMenuModel()
  20. {
  21. setApplicationCommandManagerToWatch (&getCommandManager());
  22. }
  23. StringArray getMenuBarNames() override
  24. {
  25. return getApp().getMenuNames();
  26. }
  27. PopupMenu getMenuForIndex (int /*topLevelMenuIndex*/, const String& menuName) override
  28. {
  29. PopupMenu menu;
  30. getApp().createMenu (menu, menuName);
  31. return menu;
  32. }
  33. void menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/) override
  34. {
  35. getApp().handleMainMenuCommand (menuItemID);
  36. }
  37. };
  38. //==============================================================================
  39. ProjucerApplication::ProjucerApplication() : isRunningCommandLine (false)
  40. {
  41. }
  42. void ProjucerApplication::initialise (const String& commandLine)
  43. {
  44. if (commandLine.trimStart().startsWith ("--server"))
  45. {
  46. initialiseLogger ("Compiler_Log_");
  47. LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  48. #if JUCE_MAC
  49. Process::setDockIconVisible (false);
  50. #endif
  51. server = createClangServer (commandLine);
  52. }
  53. else
  54. {
  55. initialiseLogger ("IDE_Log_");
  56. Logger::writeToLog (SystemStats::getOperatingSystemName());
  57. Logger::writeToLog ("CPU: " + String (SystemStats::getCpuSpeedInMegahertz())
  58. + "MHz Cores: " + String (SystemStats::getNumCpus())
  59. + " " + String (SystemStats::getMemorySizeInMegabytes()) + "MB");
  60. isRunningCommandLine = commandLine.isNotEmpty()
  61. && ! commandLine.startsWith ("-NSDocumentRevisionsDebugMode");
  62. initialiseBasics();
  63. if (isRunningCommandLine)
  64. {
  65. auto appReturnCode = performCommandLine (ArgumentList ("Projucer", commandLine));
  66. if (appReturnCode != commandLineNotPerformed)
  67. {
  68. setApplicationReturnValue (appReturnCode);
  69. quit();
  70. return;
  71. }
  72. isRunningCommandLine = false;
  73. }
  74. if (sendCommandLineToPreexistingInstance())
  75. {
  76. DBG ("Another instance is running - quitting...");
  77. quit();
  78. return;
  79. }
  80. rescanJUCEPathModules();
  81. rescanUserPathModules();
  82. openDocumentManager.registerType (new ProjucerAppClasses::LiveBuildCodeEditorDocument::Type(), 2);
  83. childProcessCache.reset (new ChildProcessCache());
  84. initCommandManager();
  85. menuModel.reset (new MainMenuModel());
  86. settings->appearance.refreshPresetSchemeList();
  87. setColourScheme (settings->getGlobalProperties().getIntValue ("COLOUR SCHEME"), false);
  88. setEditorColourScheme (settings->getGlobalProperties().getIntValue ("EDITOR COLOUR SCHEME"), false);
  89. updateEditorColourSchemeIfNeeded();
  90. // do further initialisation in a moment when the message loop has started
  91. triggerAsyncUpdate();
  92. }
  93. }
  94. void ProjucerApplication::initialiseBasics()
  95. {
  96. settings = std::make_unique<StoredSettings>();
  97. licenseController.reset (new LicenseController);
  98. licenseController->addLicenseStatusChangedCallback (this);
  99. }
  100. bool ProjucerApplication::initialiseLogger (const char* filePrefix)
  101. {
  102. if (logger == nullptr)
  103. {
  104. #if JUCE_LINUX
  105. String folder = "~/.config/Projucer/Logs";
  106. #else
  107. String folder = "com.juce.projucer";
  108. #endif
  109. logger.reset (FileLogger::createDateStampedLogger (folder, filePrefix, ".txt",
  110. getApplicationName() + " " + getApplicationVersion()
  111. + " --- Build date: " __DATE__));
  112. Logger::setCurrentLogger (logger.get());
  113. }
  114. return logger != nullptr;
  115. }
  116. void ProjucerApplication::handleAsyncUpdate()
  117. {
  118. LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  119. ImageCache::setCacheTimeout (30 * 1000);
  120. icons = std::make_unique<Icons>();
  121. tooltipWindow = std::make_unique<TooltipWindow> (nullptr, 1200);
  122. if (licenseController != nullptr)
  123. licenseController->startWebviewIfNeeded();
  124. #if JUCE_MAC
  125. PopupMenu extraAppleMenuItems;
  126. createExtraAppleMenuItems (extraAppleMenuItems);
  127. // workaround broken "Open Recent" submenu: not passing the
  128. // submenu's title here avoids the defect in JuceMainMenuHandler::addMenuItem
  129. MenuBarModel::setMacMainMenu (menuModel.get(), &extraAppleMenuItems); //, "Open Recent");
  130. #endif
  131. if (getGlobalProperties().getValue (Ids::dontQueryForUpdate, {}).isEmpty())
  132. LatestVersionCheckerAndUpdater::getInstance()->checkForNewVersion (false);
  133. if (! isRunningCommandLine && settings->shouldAskUserToSetJUCEPath())
  134. showSetJUCEPathAlert();
  135. }
  136. void ProjucerApplication::initialiseWindows (const String& commandLine)
  137. {
  138. const String commandLineWithoutNSDebug (commandLine.replace ("-NSDocumentRevisionsDebugMode YES", StringRef()));
  139. if (commandLineWithoutNSDebug.trim().isNotEmpty() && ! commandLineWithoutNSDebug.trim().startsWithChar ('-'))
  140. anotherInstanceStarted (commandLine);
  141. else
  142. mainWindowList.reopenLastProjects();
  143. mainWindowList.createWindowIfNoneAreOpen();
  144. }
  145. static void deleteTemporaryFiles()
  146. {
  147. auto tempDirectory = File::getSpecialLocation (File::SpecialLocationType::tempDirectory).getChildFile ("PIPs");
  148. if (tempDirectory.exists())
  149. tempDirectory.deleteRecursively();
  150. }
  151. void ProjucerApplication::shutdown()
  152. {
  153. if (server != nullptr)
  154. {
  155. destroyClangServer (server);
  156. Logger::writeToLog ("Server shutdown cleanly");
  157. }
  158. utf8Window.reset();
  159. svgPathWindow.reset();
  160. aboutWindow.reset();
  161. pathsWindow.reset();
  162. editorColourSchemeWindow.reset();
  163. pipCreatorWindow.reset();
  164. if (licenseController != nullptr)
  165. {
  166. licenseController->removeLicenseStatusChangedCallback (this);
  167. licenseController.reset();
  168. }
  169. mainWindowList.forceCloseAllWindows();
  170. openDocumentManager.clear();
  171. childProcessCache.reset();
  172. #if JUCE_MAC
  173. MenuBarModel::setMacMainMenu (nullptr);
  174. #endif
  175. menuModel.reset();
  176. commandManager.reset();
  177. settings.reset();
  178. if (! isRunningCommandLine)
  179. LookAndFeel::setDefaultLookAndFeel (nullptr);
  180. // clean up after ourselves and delete any temp project files that may have
  181. // been created from PIPs
  182. deleteTemporaryFiles();
  183. if (! isRunningCommandLine)
  184. Logger::writeToLog ("Shutdown");
  185. deleteLogger();
  186. }
  187. struct AsyncQuitRetrier : private Timer
  188. {
  189. AsyncQuitRetrier() { startTimer (500); }
  190. void timerCallback() override
  191. {
  192. stopTimer();
  193. delete this;
  194. if (auto* app = JUCEApplicationBase::getInstance())
  195. app->systemRequestedQuit();
  196. }
  197. JUCE_DECLARE_NON_COPYABLE (AsyncQuitRetrier)
  198. };
  199. void ProjucerApplication::systemRequestedQuit()
  200. {
  201. if (server != nullptr)
  202. {
  203. sendQuitMessageToIDE (server);
  204. }
  205. else if (ModalComponentManager::getInstance()->cancelAllModalComponents())
  206. {
  207. new AsyncQuitRetrier();
  208. }
  209. else
  210. {
  211. if (closeAllMainWindows())
  212. quit();
  213. }
  214. }
  215. //==============================================================================
  216. void ProjucerApplication::licenseStateChanged (const LicenseState& state)
  217. {
  218. #if ! JUCER_ENABLE_GPL_MODE
  219. if (state.type != LicenseState::Type::notLoggedIn
  220. && state.type != LicenseState::Type::noLicenseChosenYet)
  221. #else
  222. ignoreUnused (state);
  223. #endif
  224. {
  225. initialiseWindows (getCommandLineParameters());
  226. }
  227. }
  228. void ProjucerApplication::doLogout()
  229. {
  230. if (licenseController != nullptr)
  231. {
  232. const LicenseState& state = licenseController->getState();
  233. if (state.type != LicenseState::Type::notLoggedIn && closeAllMainWindows())
  234. licenseController->logout();
  235. }
  236. }
  237. //==============================================================================
  238. String ProjucerApplication::getVersionDescription() const
  239. {
  240. String s;
  241. const Time buildDate (Time::getCompilationDate());
  242. s << "Projucer " << ProjectInfo::versionString
  243. << newLine
  244. << "Build date: " << buildDate.getDayOfMonth()
  245. << " " << Time::getMonthName (buildDate.getMonth(), true)
  246. << " " << buildDate.getYear();
  247. return s;
  248. }
  249. void ProjucerApplication::anotherInstanceStarted (const String& commandLine)
  250. {
  251. if (server == nullptr && ! commandLine.trim().startsWithChar ('-'))
  252. openFile (File (commandLine.unquoted()));
  253. }
  254. ProjucerApplication& ProjucerApplication::getApp()
  255. {
  256. ProjucerApplication* const app = dynamic_cast<ProjucerApplication*> (JUCEApplication::getInstance());
  257. jassert (app != nullptr);
  258. return *app;
  259. }
  260. ApplicationCommandManager& ProjucerApplication::getCommandManager()
  261. {
  262. auto* cm = ProjucerApplication::getApp().commandManager.get();
  263. jassert (cm != nullptr);
  264. return *cm;
  265. }
  266. //==============================================================================
  267. enum
  268. {
  269. recentProjectsBaseID = 100,
  270. openWindowsBaseID = 300,
  271. activeDocumentsBaseID = 400,
  272. showPathsID = 1999,
  273. examplesBaseID = 2000
  274. };
  275. MenuBarModel* ProjucerApplication::getMenuModel()
  276. {
  277. return menuModel.get();
  278. }
  279. StringArray ProjucerApplication::getMenuNames()
  280. {
  281. return { "File", "Edit", "View", "Build", "Window", "Document", "GUI Editor", "Tools", "Help" };
  282. }
  283. void ProjucerApplication::createMenu (PopupMenu& menu, const String& menuName)
  284. {
  285. if (menuName == "File") createFileMenu (menu);
  286. else if (menuName == "Edit") createEditMenu (menu);
  287. else if (menuName == "View") createViewMenu (menu);
  288. else if (menuName == "Build") createBuildMenu (menu);
  289. else if (menuName == "Window") createWindowMenu (menu);
  290. else if (menuName == "Document") createDocumentMenu (menu);
  291. else if (menuName == "Tools") createToolsMenu (menu);
  292. else if (menuName == "Help") createHelpMenu (menu);
  293. else if (menuName == "GUI Editor") createGUIEditorMenu (menu);
  294. else jassertfalse; // names have changed?
  295. }
  296. void ProjucerApplication::createFileMenu (PopupMenu& menu)
  297. {
  298. menu.addCommandItem (commandManager.get(), CommandIDs::newProject);
  299. menu.addCommandItem (commandManager.get(), CommandIDs::newProjectFromClipboard);
  300. menu.addCommandItem (commandManager.get(), CommandIDs::newPIP);
  301. menu.addSeparator();
  302. menu.addCommandItem (commandManager.get(), CommandIDs::open);
  303. {
  304. PopupMenu recentFiles;
  305. settings->recentFiles.createPopupMenuItems (recentFiles, recentProjectsBaseID, true, true);
  306. if (recentFiles.getNumItems() > 0)
  307. {
  308. recentFiles.addSeparator();
  309. recentFiles.addCommandItem (commandManager.get(), CommandIDs::clearRecentFiles);
  310. }
  311. menu.addSubMenu ("Open Recent", recentFiles);
  312. }
  313. {
  314. PopupMenu examples;
  315. createExamplesPopupMenu (examples);
  316. menu.addSubMenu ("Open Example", examples);
  317. }
  318. menu.addSeparator();
  319. menu.addCommandItem (commandManager.get(), CommandIDs::closeDocument);
  320. menu.addCommandItem (commandManager.get(), CommandIDs::saveDocument);
  321. menu.addCommandItem (commandManager.get(), CommandIDs::saveDocumentAs);
  322. menu.addCommandItem (commandManager.get(), CommandIDs::saveAll);
  323. menu.addSeparator();
  324. menu.addCommandItem (commandManager.get(), CommandIDs::closeProject);
  325. menu.addCommandItem (commandManager.get(), CommandIDs::saveProject);
  326. menu.addSeparator();
  327. menu.addCommandItem (commandManager.get(), CommandIDs::openInIDE);
  328. menu.addCommandItem (commandManager.get(), CommandIDs::saveAndOpenInIDE);
  329. menu.addSeparator();
  330. #if ! JUCER_ENABLE_GPL_MODE
  331. menu.addCommandItem (commandManager.get(), CommandIDs::loginLogout);
  332. #endif
  333. #if ! JUCE_MAC
  334. menu.addCommandItem (commandManager.get(), CommandIDs::showAboutWindow);
  335. menu.addCommandItem (commandManager.get(), CommandIDs::checkForNewVersion);
  336. menu.addCommandItem (commandManager.get(), CommandIDs::showGlobalPathsWindow);
  337. menu.addSeparator();
  338. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::quit);
  339. #endif
  340. }
  341. void ProjucerApplication::createEditMenu (PopupMenu& menu)
  342. {
  343. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::undo);
  344. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::redo);
  345. menu.addSeparator();
  346. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::cut);
  347. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::copy);
  348. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::paste);
  349. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::del);
  350. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::selectAll);
  351. menu.addCommandItem (commandManager.get(), StandardApplicationCommandIDs::deselectAll);
  352. menu.addSeparator();
  353. menu.addCommandItem (commandManager.get(), CommandIDs::showFindPanel);
  354. menu.addCommandItem (commandManager.get(), CommandIDs::findSelection);
  355. menu.addCommandItem (commandManager.get(), CommandIDs::findNext);
  356. menu.addCommandItem (commandManager.get(), CommandIDs::findPrevious);
  357. }
  358. void ProjucerApplication::createViewMenu (PopupMenu& menu)
  359. {
  360. menu.addCommandItem (commandManager.get(), CommandIDs::showProjectSettings);
  361. menu.addCommandItem (commandManager.get(), CommandIDs::showProjectTab);
  362. menu.addCommandItem (commandManager.get(), CommandIDs::showBuildTab);
  363. menu.addCommandItem (commandManager.get(), CommandIDs::showFileExplorerPanel);
  364. menu.addCommandItem (commandManager.get(), CommandIDs::showModulesPanel);
  365. menu.addCommandItem (commandManager.get(), CommandIDs::showExportersPanel);
  366. menu.addCommandItem (commandManager.get(), CommandIDs::showExporterSettings);
  367. menu.addSeparator();
  368. createColourSchemeItems (menu);
  369. }
  370. void ProjucerApplication::createBuildMenu (PopupMenu& menu)
  371. {
  372. menu.addCommandItem (commandManager.get(), CommandIDs::toggleBuildEnabled);
  373. menu.addCommandItem (commandManager.get(), CommandIDs::buildNow);
  374. menu.addCommandItem (commandManager.get(), CommandIDs::toggleContinuousBuild);
  375. menu.addSeparator();
  376. menu.addCommandItem (commandManager.get(), CommandIDs::launchApp);
  377. menu.addCommandItem (commandManager.get(), CommandIDs::killApp);
  378. menu.addCommandItem (commandManager.get(), CommandIDs::cleanAll);
  379. menu.addSeparator();
  380. menu.addCommandItem (commandManager.get(), CommandIDs::reinstantiateComp);
  381. menu.addCommandItem (commandManager.get(), CommandIDs::showWarnings);
  382. menu.addSeparator();
  383. menu.addCommandItem (commandManager.get(), CommandIDs::nextError);
  384. menu.addCommandItem (commandManager.get(), CommandIDs::prevError);
  385. }
  386. void ProjucerApplication::createColourSchemeItems (PopupMenu& menu)
  387. {
  388. PopupMenu colourSchemeMenu;
  389. colourSchemeMenu.addItem (PopupMenu::Item ("Dark")
  390. .setTicked (selectedColourSchemeIndex == 0)
  391. .setAction ([this] { setColourScheme (0, true); updateEditorColourSchemeIfNeeded(); }));
  392. colourSchemeMenu.addItem (PopupMenu::Item ("Grey")
  393. .setTicked (selectedColourSchemeIndex == 1)
  394. .setAction ([this] { setColourScheme (1, true); updateEditorColourSchemeIfNeeded(); }));
  395. colourSchemeMenu.addItem (PopupMenu::Item ("Light")
  396. .setTicked (selectedColourSchemeIndex == 2)
  397. .setAction ([this] { setColourScheme (2, true); updateEditorColourSchemeIfNeeded(); }));
  398. menu.addSubMenu ("Colour Scheme", colourSchemeMenu);
  399. //==============================================================================
  400. PopupMenu editorColourSchemeMenu;
  401. auto& appearanceSettings = getAppSettings().appearance;
  402. appearanceSettings.refreshPresetSchemeList();
  403. auto schemes = appearanceSettings.getPresetSchemes();
  404. auto i = 0;
  405. for (auto& s : schemes)
  406. {
  407. editorColourSchemeMenu.addItem (PopupMenu::Item (s)
  408. .setEnabled (editorColourSchemeWindow == nullptr)
  409. .setTicked (selectedEditorColourSchemeIndex == i)
  410. .setAction ([this, i] { setEditorColourScheme (i, true); }));
  411. ++i;
  412. }
  413. editorColourSchemeMenu.addSeparator();
  414. editorColourSchemeMenu.addItem (PopupMenu::Item ("Create...")
  415. .setEnabled (editorColourSchemeWindow == nullptr)
  416. .setAction ([this] { showEditorColourSchemeWindow(); }));
  417. menu.addSubMenu ("Editor Colour Scheme", editorColourSchemeMenu);
  418. }
  419. void ProjucerApplication::createWindowMenu (PopupMenu& menu)
  420. {
  421. menu.addCommandItem (commandManager.get(), CommandIDs::goToPreviousWindow);
  422. menu.addCommandItem (commandManager.get(), CommandIDs::goToNextWindow);
  423. menu.addCommandItem (commandManager.get(), CommandIDs::closeWindow);
  424. menu.addSeparator();
  425. int counter = 0;
  426. for (auto* window : mainWindowList.windows)
  427. if (window != nullptr)
  428. if (auto* project = window->getProject())
  429. menu.addItem (openWindowsBaseID + counter++, project->getProjectNameString());
  430. menu.addSeparator();
  431. menu.addCommandItem (commandManager.get(), CommandIDs::closeAllWindows);
  432. }
  433. void ProjucerApplication::createDocumentMenu (PopupMenu& menu)
  434. {
  435. menu.addCommandItem (commandManager.get(), CommandIDs::goToPreviousDoc);
  436. menu.addCommandItem (commandManager.get(), CommandIDs::goToNextDoc);
  437. menu.addCommandItem (commandManager.get(), CommandIDs::goToCounterpart);
  438. menu.addSeparator();
  439. auto numDocs = jmin (50, openDocumentManager.getNumOpenDocuments());
  440. for (int i = 0; i < numDocs; ++i)
  441. {
  442. OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument(i);
  443. menu.addItem (activeDocumentsBaseID + i, doc->getName());
  444. }
  445. menu.addSeparator();
  446. menu.addCommandItem (commandManager.get(), CommandIDs::closeAllDocuments);
  447. }
  448. void ProjucerApplication::createToolsMenu (PopupMenu& menu)
  449. {
  450. menu.addCommandItem (commandManager.get(), CommandIDs::showUTF8Tool);
  451. menu.addCommandItem (commandManager.get(), CommandIDs::showSVGPathTool);
  452. menu.addCommandItem (commandManager.get(), CommandIDs::showTranslationTool);
  453. }
  454. void ProjucerApplication::createHelpMenu (PopupMenu& menu)
  455. {
  456. menu.addCommandItem (commandManager.get(), CommandIDs::showForum);
  457. menu.addSeparator();
  458. menu.addCommandItem (commandManager.get(), CommandIDs::showAPIModules);
  459. menu.addCommandItem (commandManager.get(), CommandIDs::showAPIClasses);
  460. menu.addCommandItem (commandManager.get(), CommandIDs::showTutorials);
  461. }
  462. void ProjucerApplication::createExtraAppleMenuItems (PopupMenu& menu)
  463. {
  464. menu.addCommandItem (commandManager.get(), CommandIDs::showAboutWindow);
  465. menu.addCommandItem (commandManager.get(), CommandIDs::checkForNewVersion);
  466. menu.addSeparator();
  467. menu.addCommandItem (commandManager.get(), CommandIDs::showGlobalPathsWindow);
  468. }
  469. void ProjucerApplication::createExamplesPopupMenu (PopupMenu& menu) noexcept
  470. {
  471. numExamples = 0;
  472. for (auto& dir : getSortedExampleDirectories())
  473. {
  474. PopupMenu m;
  475. for (auto& f : getSortedExampleFilesInDirectory (dir))
  476. {
  477. m.addItem (examplesBaseID + numExamples, f.getFileNameWithoutExtension());
  478. ++numExamples;
  479. }
  480. menu.addSubMenu (dir.getFileName(), m);
  481. }
  482. if (numExamples == 0)
  483. {
  484. menu.addItem (showPathsID, "Set path to JUCE...");
  485. }
  486. else
  487. {
  488. menu.addSeparator();
  489. menu.addCommandItem (commandManager.get(), CommandIDs::launchDemoRunner);
  490. }
  491. }
  492. //==============================================================================
  493. static File getJUCEExamplesDirectoryPathFromGlobal()
  494. {
  495. auto globalPath = File::createFileWithoutCheckingPath (getAppSettings().getStoredPath (Ids::jucePath, TargetOS::getThisOS()).get().toString()
  496. .replace ("~", File::getSpecialLocation (File::userHomeDirectory).getFullPathName()));
  497. if (globalPath.exists())
  498. return File (globalPath).getChildFile ("examples");
  499. return {};
  500. }
  501. Array<File> ProjucerApplication::getSortedExampleDirectories() noexcept
  502. {
  503. Array<File> exampleDirectories;
  504. auto examplesPath = getJUCEExamplesDirectoryPathFromGlobal();
  505. if (! isValidJUCEExamplesDirectory (examplesPath))
  506. return {};
  507. for (const auto& iter : RangedDirectoryIterator (examplesPath, false, "*", File::findDirectories))
  508. {
  509. auto exampleDirectory = iter.getFile();
  510. if (exampleDirectory.getNumberOfChildFiles (File::findFiles | File::ignoreHiddenFiles) > 0
  511. && exampleDirectory.getFileName() != "DemoRunner" && exampleDirectory.getFileName() != "Assets")
  512. exampleDirectories.add (exampleDirectory);
  513. }
  514. exampleDirectories.sort();
  515. return exampleDirectories;
  516. }
  517. Array<File> ProjucerApplication::getSortedExampleFilesInDirectory (const File& directory) const noexcept
  518. {
  519. Array<File> exampleFiles;
  520. for (const auto& iter : RangedDirectoryIterator (directory, false, "*.h", File::findFiles))
  521. exampleFiles.add (iter.getFile());
  522. exampleFiles.sort();
  523. return exampleFiles;
  524. }
  525. bool ProjucerApplication::findWindowAndOpenPIP (const File& pip)
  526. {
  527. auto* window = mainWindowList.getFrontmostWindow();
  528. bool shouldCloseWindow = false;
  529. if (window == nullptr)
  530. {
  531. window = mainWindowList.getOrCreateEmptyWindow();
  532. shouldCloseWindow = true;
  533. }
  534. if (window->tryToOpenPIP (pip))
  535. return true;
  536. if (shouldCloseWindow)
  537. mainWindowList.closeWindow (window);
  538. return false;
  539. }
  540. void ProjucerApplication::findAndLaunchExample (int selectedIndex)
  541. {
  542. File example;
  543. for (auto& dir : getSortedExampleDirectories())
  544. {
  545. auto exampleFiles = getSortedExampleFilesInDirectory (dir);
  546. if (selectedIndex < exampleFiles.size())
  547. {
  548. example = exampleFiles.getUnchecked (selectedIndex);
  549. break;
  550. }
  551. selectedIndex -= exampleFiles.size();
  552. }
  553. // example doesn't exist?
  554. jassert (example != File());
  555. findWindowAndOpenPIP (example);
  556. }
  557. //==============================================================================
  558. static String getPlatformSpecificFileExtension()
  559. {
  560. #if JUCE_MAC
  561. return ".app";
  562. #elif JUCE_WINDOWS
  563. return ".exe";
  564. #elif JUCE_LINUX
  565. return {};
  566. #else
  567. jassertfalse;
  568. return {};
  569. #endif
  570. }
  571. static File getPlatformSpecificProjectFolder()
  572. {
  573. auto examplesDir = getJUCEExamplesDirectoryPathFromGlobal();
  574. if (examplesDir == File())
  575. return {};
  576. auto buildsFolder = examplesDir.getChildFile ("DemoRunner").getChildFile ("Builds");
  577. #if JUCE_MAC
  578. return buildsFolder.getChildFile ("MacOSX");
  579. #elif JUCE_WINDOWS
  580. return buildsFolder.getChildFile ("VisualStudio2017");
  581. #elif JUCE_LINUX
  582. return buildsFolder.getChildFile ("LinuxMakefile");
  583. #else
  584. jassertfalse;
  585. return {};
  586. #endif
  587. }
  588. static File tryToFindDemoRunnerExecutableInBuilds()
  589. {
  590. auto projectFolder = getPlatformSpecificProjectFolder();
  591. if (projectFolder == File())
  592. return {};
  593. #if JUCE_MAC
  594. projectFolder = projectFolder.getChildFile ("build");
  595. auto demoRunnerExecutable = projectFolder.getChildFile ("Release").getChildFile ("DemoRunner.app");
  596. if (demoRunnerExecutable.exists())
  597. return demoRunnerExecutable;
  598. demoRunnerExecutable = projectFolder.getChildFile ("Debug").getChildFile ("DemoRunner.app");
  599. if (demoRunnerExecutable.exists())
  600. return demoRunnerExecutable;
  601. #elif JUCE_WINDOWS
  602. projectFolder = projectFolder.getChildFile ("x64");
  603. auto demoRunnerExecutable = projectFolder.getChildFile ("Release").getChildFile ("App").getChildFile ("DemoRunner.exe");
  604. if (demoRunnerExecutable.existsAsFile())
  605. return demoRunnerExecutable;
  606. demoRunnerExecutable = projectFolder.getChildFile ("Debug").getChildFile ("App").getChildFile ("DemoRunner.exe");
  607. if (demoRunnerExecutable.existsAsFile())
  608. return demoRunnerExecutable;
  609. #elif JUCE_LINUX
  610. projectFolder = projectFolder.getChildFile ("LinuxMakefile").getChildFile ("build");
  611. auto demoRunnerExecutable = projectFolder.getChildFile ("DemoRunner");
  612. if (demoRunnerExecutable.existsAsFile())
  613. return demoRunnerExecutable;
  614. #endif
  615. return {};
  616. }
  617. static File tryToFindPrebuiltDemoRunnerExecutable()
  618. {
  619. auto prebuiltFile = File (getAppSettings().getStoredPath (Ids::jucePath, TargetOS::getThisOS()).get().toString())
  620. .getChildFile ("DemoRunner" + getPlatformSpecificFileExtension());
  621. #if JUCE_MAC
  622. if (prebuiltFile.exists())
  623. #else
  624. if (prebuiltFile.existsAsFile())
  625. #endif
  626. return prebuiltFile;
  627. return {};
  628. }
  629. void ProjucerApplication::checkIfGlobalJUCEPathHasChanged()
  630. {
  631. auto globalJUCEPath = File (getAppSettings().getStoredPath (Ids::jucePath, TargetOS::getThisOS()).get());
  632. if (lastJUCEPath != globalJUCEPath)
  633. {
  634. hasScannedForDemoRunnerProject = false;
  635. hasScannedForDemoRunnerExecutable = false;
  636. lastJUCEPath = globalJUCEPath;
  637. }
  638. }
  639. File ProjucerApplication::tryToFindDemoRunnerExecutable()
  640. {
  641. checkIfGlobalJUCEPathHasChanged();
  642. if (hasScannedForDemoRunnerExecutable)
  643. return lastDemoRunnerExectuableFile;
  644. hasScannedForDemoRunnerExecutable = true;
  645. auto demoRunnerExecutable = tryToFindDemoRunnerExecutableInBuilds();
  646. if (demoRunnerExecutable == File())
  647. demoRunnerExecutable = tryToFindPrebuiltDemoRunnerExecutable();
  648. lastDemoRunnerExectuableFile = demoRunnerExecutable;
  649. return demoRunnerExecutable;
  650. }
  651. File ProjucerApplication::tryToFindDemoRunnerProject()
  652. {
  653. checkIfGlobalJUCEPathHasChanged();
  654. if (hasScannedForDemoRunnerProject)
  655. return lastDemoRunnerProjectFile;
  656. hasScannedForDemoRunnerProject = true;
  657. auto projectFolder = getPlatformSpecificProjectFolder();
  658. if (projectFolder == File())
  659. {
  660. lastDemoRunnerProjectFile = File();
  661. return {};
  662. }
  663. #if JUCE_MAC
  664. auto demoRunnerProjectFile = projectFolder.getChildFile ("DemoRunner.xcodeproj");
  665. #elif JUCE_WINDOWS
  666. auto demoRunnerProjectFile = projectFolder.getChildFile ("DemoRunner.sln");
  667. #elif JUCE_LINUX
  668. auto demoRunnerProjectFile = projectFolder.getChildFile ("Makefile");
  669. #endif
  670. #if JUCE_MAC
  671. if (! demoRunnerProjectFile.exists())
  672. #else
  673. if (! demoRunnerProjectFile.existsAsFile())
  674. #endif
  675. demoRunnerProjectFile = File();
  676. lastDemoRunnerProjectFile = demoRunnerProjectFile;
  677. return demoRunnerProjectFile;
  678. }
  679. void ProjucerApplication::launchDemoRunner()
  680. {
  681. auto demoRunnerFile = tryToFindDemoRunnerExecutable();
  682. if (demoRunnerFile != File() && demoRunnerFile.startAsProcess())
  683. return;
  684. demoRunnerFile = tryToFindDemoRunnerProject();
  685. if (demoRunnerFile != File())
  686. {
  687. auto& lf = Desktop::getInstance().getDefaultLookAndFeel();
  688. demoRunnerAlert.reset (lf.createAlertWindow ("Open Project",
  689. "Couldn't find a compiled version of the Demo Runner."
  690. #if JUCE_LINUX
  691. " Do you want to build it now?", "Build project", "Cancel",
  692. #else
  693. " Do you want to open the project?", "Open project", "Cancel",
  694. #endif
  695. {},
  696. AlertWindow::QuestionIcon, 2,
  697. mainWindowList.getFrontmostWindow (false)));
  698. demoRunnerAlert->enterModalState (true, ModalCallbackFunction::create ([this, demoRunnerFile] (int retVal)
  699. {
  700. demoRunnerAlert.reset (nullptr);
  701. if (retVal == 1)
  702. {
  703. #if JUCE_LINUX
  704. String command ("make -C " + demoRunnerFile.getParentDirectory().getFullPathName() + " CONFIG=Release -j3");
  705. if (! makeProcess.start (command))
  706. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Error", "Error building Demo Runner.");
  707. #else
  708. demoRunnerFile.startAsProcess();
  709. #endif
  710. }
  711. }), false);
  712. }
  713. }
  714. //==============================================================================
  715. void ProjucerApplication::handleMainMenuCommand (int menuItemID)
  716. {
  717. if (menuItemID >= recentProjectsBaseID && menuItemID < (recentProjectsBaseID + 100))
  718. {
  719. // open a file from the "recent files" menu
  720. openFile (settings->recentFiles.getFile (menuItemID - recentProjectsBaseID));
  721. }
  722. else if (menuItemID >= openWindowsBaseID && menuItemID < (openWindowsBaseID + 100))
  723. {
  724. if (auto* window = mainWindowList.windows.getUnchecked (menuItemID - openWindowsBaseID))
  725. window->toFront (true);
  726. }
  727. else if (menuItemID >= activeDocumentsBaseID && menuItemID < (activeDocumentsBaseID + 200))
  728. {
  729. if (auto* doc = openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID))
  730. mainWindowList.openDocument (doc, true);
  731. else
  732. jassertfalse;
  733. }
  734. else if (menuItemID == showPathsID)
  735. {
  736. showPathsWindow (true);
  737. }
  738. else if (menuItemID >= examplesBaseID && menuItemID < (examplesBaseID + numExamples))
  739. {
  740. findAndLaunchExample (menuItemID - examplesBaseID);
  741. }
  742. else
  743. {
  744. handleGUIEditorMenuCommand (menuItemID);
  745. }
  746. }
  747. //==============================================================================
  748. void ProjucerApplication::getAllCommands (Array <CommandID>& commands)
  749. {
  750. JUCEApplication::getAllCommands (commands);
  751. const CommandID ids[] = { CommandIDs::newProject,
  752. CommandIDs::newProjectFromClipboard,
  753. CommandIDs::newPIP,
  754. CommandIDs::open,
  755. CommandIDs::launchDemoRunner,
  756. CommandIDs::closeAllWindows,
  757. CommandIDs::closeAllDocuments,
  758. CommandIDs::clearRecentFiles,
  759. CommandIDs::saveAll,
  760. CommandIDs::showGlobalPathsWindow,
  761. CommandIDs::showUTF8Tool,
  762. CommandIDs::showSVGPathTool,
  763. CommandIDs::showAboutWindow,
  764. CommandIDs::checkForNewVersion,
  765. CommandIDs::showForum,
  766. CommandIDs::showAPIModules,
  767. CommandIDs::showAPIClasses,
  768. CommandIDs::showTutorials,
  769. CommandIDs::loginLogout };
  770. commands.addArray (ids, numElementsInArray (ids));
  771. }
  772. void ProjucerApplication::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
  773. {
  774. switch (commandID)
  775. {
  776. case CommandIDs::newProject:
  777. result.setInfo ("New Project...", "Creates a new JUCE project", CommandCategories::general, 0);
  778. result.defaultKeypresses.add (KeyPress ('n', ModifierKeys::commandModifier, 0));
  779. break;
  780. case CommandIDs::newProjectFromClipboard:
  781. result.setInfo ("New Project From Clipboard...", "Creates a new JUCE project from the clipboard contents", CommandCategories::general, 0);
  782. result.defaultKeypresses.add (KeyPress ('n', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  783. break;
  784. case CommandIDs::newPIP:
  785. result.setInfo ("New PIP...", "Opens the PIP Creator utility for creating a new PIP", CommandCategories::general, 0);
  786. result.defaultKeypresses.add (KeyPress ('p', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  787. break;
  788. case CommandIDs::launchDemoRunner:
  789. #if JUCE_LINUX
  790. if (makeProcess.isRunning())
  791. {
  792. result.setInfo ("Building Demo Runner...", "The Demo Runner project is currently building", CommandCategories::general, 0);
  793. result.setActive (false);
  794. }
  795. else
  796. #endif
  797. {
  798. result.setInfo ("Launch Demo Runner", "Launches the JUCE demo runner application, or the project if it can't be found", CommandCategories::general, 0);
  799. result.setActive (tryToFindDemoRunnerExecutable() != File() || tryToFindDemoRunnerProject() != File());
  800. }
  801. break;
  802. case CommandIDs::open:
  803. result.setInfo ("Open...", "Opens a JUCE project", CommandCategories::general, 0);
  804. result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0));
  805. break;
  806. case CommandIDs::showGlobalPathsWindow:
  807. result.setInfo ("Global Paths...",
  808. "Shows the window to change the stored global paths.",
  809. CommandCategories::general, 0);
  810. break;
  811. case CommandIDs::closeAllWindows:
  812. result.setInfo ("Close All Windows", "Closes all open windows", CommandCategories::general, 0);
  813. result.setActive (mainWindowList.windows.size() > 0);
  814. break;
  815. case CommandIDs::closeAllDocuments:
  816. result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0);
  817. result.setActive (openDocumentManager.getNumOpenDocuments() > 0);
  818. break;
  819. case CommandIDs::clearRecentFiles:
  820. result.setInfo ("Clear Recent Files", "Clears all recent files from the menu", CommandCategories::general, 0);
  821. result.setActive (settings->recentFiles.getNumFiles() > 0);
  822. break;
  823. case CommandIDs::saveAll:
  824. result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0);
  825. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::altModifier, 0));
  826. break;
  827. case CommandIDs::showUTF8Tool:
  828. result.setInfo ("UTF-8 String-Literal Helper", "Shows the UTF-8 string literal utility", CommandCategories::general, 0);
  829. break;
  830. case CommandIDs::showSVGPathTool:
  831. result.setInfo ("SVG Path Converter", "Shows the SVG->Path data conversion utility", CommandCategories::general, 0);
  832. break;
  833. case CommandIDs::showAboutWindow:
  834. result.setInfo ("About Projucer", "Shows the Projucer's 'About' page.", CommandCategories::general, 0);
  835. break;
  836. case CommandIDs::checkForNewVersion:
  837. result.setInfo ("Check for New Version...", "Checks the web server for a new version of JUCE", CommandCategories::general, 0);
  838. break;
  839. case CommandIDs::showForum:
  840. result.setInfo ("JUCE Community Forum", "Shows the JUCE community forum in a browser", CommandCategories::general, 0);
  841. break;
  842. case CommandIDs::showAPIModules:
  843. result.setInfo ("API Modules", "Shows the API modules documentation in a browser", CommandCategories::general, 0);
  844. break;
  845. case CommandIDs::showAPIClasses:
  846. result.setInfo ("API Classes", "Shows the API classes documentation in a browser", CommandCategories::general, 0);
  847. break;
  848. case CommandIDs::showTutorials:
  849. result.setInfo ("JUCE Tutorials", "Shows the JUCE tutorials in a browser", CommandCategories::general, 0);
  850. break;
  851. case CommandIDs::loginLogout:
  852. {
  853. bool isLoggedIn = false;
  854. String username;
  855. if (licenseController != nullptr)
  856. {
  857. const LicenseState state = licenseController->getState();
  858. isLoggedIn = (state.type != LicenseState::Type::notLoggedIn && state.type != LicenseState::Type::GPL);
  859. username = state.username;
  860. }
  861. result.setInfo (isLoggedIn
  862. ? String ("Sign out ") + username + "..."
  863. : String ("Sign in..."),
  864. "Log out of your JUCE account", CommandCategories::general, 0);
  865. }
  866. break;
  867. default:
  868. JUCEApplication::getCommandInfo (commandID, result);
  869. break;
  870. }
  871. }
  872. bool ProjucerApplication::perform (const InvocationInfo& info)
  873. {
  874. switch (info.commandID)
  875. {
  876. case CommandIDs::newProject: createNewProject(); break;
  877. case CommandIDs::newProjectFromClipboard: createNewProjectFromClipboard(); break;
  878. case CommandIDs::newPIP: createNewPIP(); break;
  879. case CommandIDs::open: askUserToOpenFile(); break;
  880. case CommandIDs::launchDemoRunner: launchDemoRunner(); break;
  881. case CommandIDs::saveAll: saveAllDocuments(); break;
  882. case CommandIDs::closeAllWindows: closeAllMainWindowsAndQuitIfNeeded(); break;
  883. case CommandIDs::closeAllDocuments: closeAllDocuments (true); break;
  884. case CommandIDs::clearRecentFiles: clearRecentFiles(); break;
  885. case CommandIDs::showUTF8Tool: showUTF8ToolWindow(); break;
  886. case CommandIDs::showSVGPathTool: showSVGPathDataToolWindow(); break;
  887. case CommandIDs::showGlobalPathsWindow: showPathsWindow (false); break;
  888. case CommandIDs::showAboutWindow: showAboutWindow(); break;
  889. case CommandIDs::checkForNewVersion: LatestVersionCheckerAndUpdater::getInstance()->checkForNewVersion (true); break;
  890. case CommandIDs::showForum: launchForumBrowser(); break;
  891. case CommandIDs::showAPIModules: launchModulesBrowser(); break;
  892. case CommandIDs::showAPIClasses: launchClassesBrowser(); break;
  893. case CommandIDs::showTutorials: launchTutorialsBrowser(); break;
  894. case CommandIDs::loginLogout: doLogout(); break;
  895. default: return JUCEApplication::perform (info);
  896. }
  897. return true;
  898. }
  899. //==============================================================================
  900. void ProjucerApplication::createNewProject()
  901. {
  902. auto* mw = mainWindowList.getOrCreateEmptyWindow();
  903. jassert (mw != nullptr);
  904. mw->showStartPage();
  905. mainWindowList.checkWindowBounds (*mw);
  906. }
  907. void ProjucerApplication::createNewProjectFromClipboard()
  908. {
  909. auto tempFile = File::getSpecialLocation (File::SpecialLocationType::tempDirectory).getChildFile ("PIPs").getChildFile ("Clipboard")
  910. .getChildFile ("PIPFile_" + String (std::abs (Random::getSystemRandom().nextInt())) + ".h");
  911. if (tempFile.existsAsFile())
  912. tempFile.deleteFile();
  913. tempFile.create();
  914. tempFile.appendText (SystemClipboard::getTextFromClipboard());
  915. if (! findWindowAndOpenPIP (tempFile))
  916. {
  917. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Error", "Couldn't create project from clipboard contents.");
  918. tempFile.deleteFile();
  919. }
  920. }
  921. void ProjucerApplication::createNewPIP()
  922. {
  923. showPIPCreatorWindow();
  924. }
  925. void ProjucerApplication::askUserToOpenFile()
  926. {
  927. FileChooser fc ("Open File");
  928. if (fc.browseForFileToOpen())
  929. openFile (fc.getResult());
  930. }
  931. bool ProjucerApplication::openFile (const File& file)
  932. {
  933. return mainWindowList.openFile (file);
  934. }
  935. void ProjucerApplication::saveAllDocuments()
  936. {
  937. openDocumentManager.saveAll();
  938. for (int i = 0; i < mainWindowList.windows.size(); ++i)
  939. if (auto* pcc = mainWindowList.windows.getUnchecked(i)->getProjectContentComponent())
  940. pcc->refreshProjectTreeFileStatuses();
  941. }
  942. bool ProjucerApplication::closeAllDocuments (bool askUserToSave)
  943. {
  944. return openDocumentManager.closeAll (askUserToSave);
  945. }
  946. bool ProjucerApplication::closeAllMainWindows()
  947. {
  948. return server != nullptr || mainWindowList.askAllWindowsToClose();
  949. }
  950. void ProjucerApplication::closeAllMainWindowsAndQuitIfNeeded()
  951. {
  952. if (closeAllMainWindows())
  953. {
  954. #if ! JUCE_MAC
  955. if (mainWindowList.windows.size() == 0)
  956. systemRequestedQuit();
  957. #endif
  958. }
  959. }
  960. void ProjucerApplication::clearRecentFiles()
  961. {
  962. settings->recentFiles.clear();
  963. settings->recentFiles.clearRecentFilesNatively();
  964. settings->flush();
  965. menuModel->menuItemsChanged();
  966. }
  967. //==============================================================================
  968. void ProjucerApplication::showUTF8ToolWindow()
  969. {
  970. if (utf8Window != nullptr)
  971. utf8Window->toFront (true);
  972. else
  973. new FloatingToolWindow ("UTF-8 String Literal Converter", "utf8WindowPos",
  974. new UTF8Component(), utf8Window, true,
  975. 500, 500, 300, 300, 1000, 1000);
  976. }
  977. void ProjucerApplication::showSVGPathDataToolWindow()
  978. {
  979. if (svgPathWindow != nullptr)
  980. svgPathWindow->toFront (true);
  981. else
  982. new FloatingToolWindow ("SVG Path Converter", "svgPathWindowPos",
  983. new SVGPathDataComponent(), svgPathWindow, true,
  984. 500, 500, 300, 300, 1000, 1000);
  985. }
  986. void ProjucerApplication::showAboutWindow()
  987. {
  988. if (aboutWindow != nullptr)
  989. aboutWindow->toFront (true);
  990. else
  991. new FloatingToolWindow ({}, {}, new AboutWindowComponent(),
  992. aboutWindow, false,
  993. 500, 300, 500, 300, 500, 300);
  994. }
  995. void ProjucerApplication::showPathsWindow (bool highlightJUCEPath)
  996. {
  997. if (pathsWindow != nullptr)
  998. pathsWindow->toFront (true);
  999. else
  1000. new FloatingToolWindow ("Global Paths", "pathsWindowPos",
  1001. new GlobalPathsWindowComponent(), pathsWindow, false,
  1002. 600, 700, 600, 700, 600, 700);
  1003. if (highlightJUCEPath)
  1004. if (auto* pathsComp = dynamic_cast<GlobalPathsWindowComponent*> (pathsWindow->getChildComponent (0)))
  1005. pathsComp->highlightJUCEPath();
  1006. }
  1007. void ProjucerApplication::showEditorColourSchemeWindow()
  1008. {
  1009. if (editorColourSchemeWindow != nullptr)
  1010. editorColourSchemeWindow->toFront (true);
  1011. else
  1012. new FloatingToolWindow ("Editor Colour Scheme", "editorColourSchemeWindowPos",
  1013. new EditorColourSchemeWindowComponent(), editorColourSchemeWindow, false,
  1014. 500, 500, 500, 500, 500, 500);
  1015. }
  1016. void ProjucerApplication::showPIPCreatorWindow()
  1017. {
  1018. if (pipCreatorWindow != nullptr)
  1019. pipCreatorWindow->toFront (true);
  1020. else
  1021. new FloatingToolWindow ("PIP Creator", "pipCreatorWindowPos",
  1022. new PIPCreatorWindowComponent(), pipCreatorWindow, false,
  1023. 600, 750, 600, 750, 600, 750);
  1024. }
  1025. void ProjucerApplication::launchForumBrowser()
  1026. {
  1027. URL forumLink ("https://forum.juce.com/");
  1028. if (forumLink.isWellFormed())
  1029. forumLink.launchInDefaultBrowser();
  1030. }
  1031. void ProjucerApplication::launchModulesBrowser()
  1032. {
  1033. URL modulesLink ("https://docs.juce.com/master/modules.html");
  1034. if (modulesLink.isWellFormed())
  1035. modulesLink.launchInDefaultBrowser();
  1036. }
  1037. void ProjucerApplication::launchClassesBrowser()
  1038. {
  1039. URL classesLink ("https://docs.juce.com/master/classes.html");
  1040. if (classesLink.isWellFormed())
  1041. classesLink.launchInDefaultBrowser();
  1042. }
  1043. void ProjucerApplication::launchTutorialsBrowser()
  1044. {
  1045. URL tutorialsLink ("https://juce.com/learn/tutorials");
  1046. if (tutorialsLink.isWellFormed())
  1047. tutorialsLink.launchInDefaultBrowser();
  1048. }
  1049. //==============================================================================
  1050. struct FileWithTime
  1051. {
  1052. FileWithTime (const File& f) : file (f), time (f.getLastModificationTime()) {}
  1053. FileWithTime() {}
  1054. bool operator< (const FileWithTime& other) const { return time < other.time; }
  1055. bool operator== (const FileWithTime& other) const { return time == other.time; }
  1056. File file;
  1057. Time time;
  1058. };
  1059. void ProjucerApplication::deleteLogger()
  1060. {
  1061. const int maxNumLogFilesToKeep = 50;
  1062. Logger::setCurrentLogger (nullptr);
  1063. if (logger != nullptr)
  1064. {
  1065. auto logFiles = logger->getLogFile().getParentDirectory().findChildFiles (File::findFiles, false);
  1066. if (logFiles.size() > maxNumLogFilesToKeep)
  1067. {
  1068. Array<FileWithTime> files;
  1069. for (auto& f : logFiles)
  1070. files.addUsingDefaultSort (f);
  1071. for (int i = 0; i < files.size() - maxNumLogFilesToKeep; ++i)
  1072. files.getReference(i).file.deleteFile();
  1073. }
  1074. }
  1075. logger.reset();
  1076. }
  1077. PropertiesFile::Options ProjucerApplication::getPropertyFileOptionsFor (const String& filename, bool isProjectSettings)
  1078. {
  1079. PropertiesFile::Options options;
  1080. options.applicationName = filename;
  1081. options.filenameSuffix = "settings";
  1082. options.osxLibrarySubFolder = "Application Support";
  1083. #if JUCE_LINUX
  1084. options.folderName = "~/.config/Projucer";
  1085. #else
  1086. options.folderName = "Projucer";
  1087. #endif
  1088. if (isProjectSettings)
  1089. options.folderName += "/ProjectSettings";
  1090. return options;
  1091. }
  1092. void ProjucerApplication::updateAllBuildTabs()
  1093. {
  1094. for (int i = 0; i < mainWindowList.windows.size(); ++i)
  1095. if (ProjectContentComponent* p = mainWindowList.windows.getUnchecked(i)->getProjectContentComponent())
  1096. p->rebuildProjectTabs();
  1097. }
  1098. void ProjucerApplication::initCommandManager()
  1099. {
  1100. commandManager.reset (new ApplicationCommandManager());
  1101. commandManager->registerAllCommandsForTarget (this);
  1102. {
  1103. CodeDocument doc;
  1104. CppCodeEditorComponent ed (File(), doc);
  1105. commandManager->registerAllCommandsForTarget (&ed);
  1106. }
  1107. registerGUIEditorCommands();
  1108. }
  1109. void ProjucerApplication::showSetJUCEPathAlert()
  1110. {
  1111. auto& lf = Desktop::getInstance().getDefaultLookAndFeel();
  1112. pathAlert.reset (lf.createAlertWindow ("Set JUCE Path", "Your global JUCE path is invalid. This path is used to access the JUCE examples and demo project - "
  1113. "would you like to set it now?",
  1114. "Set path", "Cancel", "Don't ask again",
  1115. AlertWindow::WarningIcon, 3,
  1116. mainWindowList.getFrontmostWindow (false)));
  1117. pathAlert->enterModalState (true, ModalCallbackFunction::create ([this] (int retVal)
  1118. {
  1119. pathAlert.reset (nullptr);
  1120. if (retVal == 1)
  1121. showPathsWindow (true);
  1122. else if (retVal == 0)
  1123. settings->setDontAskAboutJUCEPathAgain();
  1124. }));
  1125. }
  1126. void rescanModules (AvailableModuleList& list, const Array<File>& paths, bool async)
  1127. {
  1128. if (async)
  1129. list.scanPathsAsync (paths);
  1130. else
  1131. list.scanPaths (paths);
  1132. }
  1133. void ProjucerApplication::rescanJUCEPathModules()
  1134. {
  1135. rescanModules (jucePathModuleList, { getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get().toString() }, ! isRunningCommandLine);
  1136. }
  1137. void ProjucerApplication::rescanUserPathModules()
  1138. {
  1139. rescanModules (userPathsModuleList, { getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS()).get().toString() }, ! isRunningCommandLine);
  1140. }
  1141. void ProjucerApplication::selectEditorColourSchemeWithName (const String& schemeName)
  1142. {
  1143. auto& appearanceSettings = getAppSettings().appearance;
  1144. auto schemes = appearanceSettings.getPresetSchemes();
  1145. auto schemeIndex = schemes.indexOf (schemeName);
  1146. if (schemeIndex >= 0)
  1147. setEditorColourScheme (schemeIndex, true);
  1148. }
  1149. void ProjucerApplication::setColourScheme (int index, bool saveSetting)
  1150. {
  1151. switch (index)
  1152. {
  1153. case 0: lookAndFeel.setColourScheme (LookAndFeel_V4::getDarkColourScheme()); break;
  1154. case 1: lookAndFeel.setColourScheme (LookAndFeel_V4::getGreyColourScheme()); break;
  1155. case 2: lookAndFeel.setColourScheme (LookAndFeel_V4::getLightColourScheme()); break;
  1156. default: break;
  1157. }
  1158. lookAndFeel.setupColours();
  1159. mainWindowList.sendLookAndFeelChange();
  1160. if (utf8Window != nullptr) utf8Window->sendLookAndFeelChange();
  1161. if (svgPathWindow != nullptr) svgPathWindow->sendLookAndFeelChange();
  1162. if (aboutWindow != nullptr) aboutWindow->sendLookAndFeelChange();
  1163. if (pathsWindow != nullptr) pathsWindow->sendLookAndFeelChange();
  1164. if (editorColourSchemeWindow != nullptr) editorColourSchemeWindow->sendLookAndFeelChange();
  1165. if (pipCreatorWindow != nullptr) pipCreatorWindow->sendLookAndFeelChange();
  1166. auto* mcm = ModalComponentManager::getInstance();
  1167. for (auto i = 0; i < mcm->getNumModalComponents(); ++i)
  1168. mcm->getModalComponent (i)->sendLookAndFeelChange();
  1169. if (saveSetting)
  1170. {
  1171. auto& properties = settings->getGlobalProperties();
  1172. properties.setValue ("COLOUR SCHEME", index);
  1173. }
  1174. selectedColourSchemeIndex = index;
  1175. getCommandManager().commandStatusChanged();
  1176. }
  1177. void ProjucerApplication::setEditorColourScheme (int index, bool saveSetting)
  1178. {
  1179. auto& appearanceSettings = getAppSettings().appearance;
  1180. auto schemes = appearanceSettings.getPresetSchemes();
  1181. index = jmin (index, schemes.size() - 1);
  1182. appearanceSettings.selectPresetScheme (index);
  1183. if (saveSetting)
  1184. {
  1185. auto& properties = settings->getGlobalProperties();
  1186. properties.setValue ("EDITOR COLOUR SCHEME", index);
  1187. }
  1188. selectedEditorColourSchemeIndex = index;
  1189. getCommandManager().commandStatusChanged();
  1190. }
  1191. bool ProjucerApplication::isEditorColourSchemeADefaultScheme (const StringArray& schemes, int editorColourSchemeIndex)
  1192. {
  1193. auto& schemeName = schemes[editorColourSchemeIndex];
  1194. return (schemeName == "Default (Dark)" || schemeName == "Default (Light)");
  1195. }
  1196. int ProjucerApplication::getEditorColourSchemeForGUIColourScheme (const StringArray& schemes, int guiColourSchemeIndex)
  1197. {
  1198. auto defaultDarkEditorIndex = schemes.indexOf ("Default (Dark)");
  1199. auto defaultLightEditorIndex = schemes.indexOf ("Default (Light)");
  1200. // Can't find default code editor colour schemes!
  1201. jassert (defaultDarkEditorIndex != -1 && defaultLightEditorIndex != -1);
  1202. return (guiColourSchemeIndex == 2 ? defaultLightEditorIndex : defaultDarkEditorIndex);
  1203. }
  1204. void ProjucerApplication::updateEditorColourSchemeIfNeeded()
  1205. {
  1206. auto& appearanceSettings = getAppSettings().appearance;
  1207. auto schemes = appearanceSettings.getPresetSchemes();
  1208. if (isEditorColourSchemeADefaultScheme (schemes, selectedEditorColourSchemeIndex))
  1209. setEditorColourScheme (getEditorColourSchemeForGUIColourScheme (schemes, selectedColourSchemeIndex), true);
  1210. }