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.

1508 lines
54KB

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