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.

1597 lines
57KB

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