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.

1478 lines
52KB

  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::getCpuSpeedInMegaherz())
  64. + "MHz Cores: " + String (SystemStats::getNumCpus())
  65. + " " + String (SystemStats::getMemorySizeInMegabytes()) + "MB");
  66. initialiseBasics();
  67. isRunningCommandLine = commandLine.isNotEmpty();
  68. licenseController = 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 = new ChildProcessCache();
  89. initCommandManager();
  90. menuModel = 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 = new StoredSettings();
  103. ImageCache::setCacheTimeout (30 * 1000);
  104. icons = 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 = FileLogger::createDateStampedLogger (folder, filePrefix, ".txt",
  117. getApplicationName() + " " + getApplicationVersion()
  118. + " --- Build date: " __DATE__);
  119. Logger::setCurrentLogger (logger);
  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, &extraAppleMenuItems); //, "Open Recent");
  133. #endif
  134. versionChecker = 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. ApplicationCommandManager* cm = ProjucerApplication::getApp().commandManager;
  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, CommandIDs::newProject);
  304. menu.addCommandItem (commandManager, CommandIDs::newProjectFromClipboard);
  305. menu.addSeparator();
  306. menu.addCommandItem (commandManager, CommandIDs::open);
  307. {
  308. PopupMenu recentFiles;
  309. settings->recentFiles.createPopupMenuItems (recentFiles, recentProjectsBaseID, true, true);
  310. if (recentFiles.getNumItems() > 0)
  311. {
  312. recentFiles.addSeparator();
  313. recentFiles.addCommandItem (commandManager, CommandIDs::clearRecentFiles);
  314. }
  315. menu.addSubMenu ("Open Recent", recentFiles);
  316. }
  317. {
  318. PopupMenu examples;
  319. createExamplesPopupMenu (examples);
  320. menu.addSubMenu ("Open Example", examples);
  321. }
  322. menu.addSeparator();
  323. menu.addCommandItem (commandManager, CommandIDs::closeDocument);
  324. menu.addCommandItem (commandManager, CommandIDs::saveDocument);
  325. menu.addCommandItem (commandManager, CommandIDs::saveDocumentAs);
  326. menu.addCommandItem (commandManager, CommandIDs::saveAll);
  327. menu.addSeparator();
  328. menu.addCommandItem (commandManager, CommandIDs::closeProject);
  329. menu.addCommandItem (commandManager, CommandIDs::saveProject);
  330. menu.addSeparator();
  331. menu.addCommandItem (commandManager, CommandIDs::openInIDE);
  332. menu.addCommandItem (commandManager, CommandIDs::saveAndOpenInIDE);
  333. menu.addSeparator();
  334. #if ! JUCER_ENABLE_GPL_MODE
  335. menu.addCommandItem (commandManager, CommandIDs::loginLogout);
  336. #endif
  337. #if ! JUCE_MAC
  338. menu.addCommandItem (commandManager, CommandIDs::showAboutWindow);
  339. menu.addCommandItem (commandManager, CommandIDs::showAppUsageWindow);
  340. menu.addCommandItem (commandManager, CommandIDs::showGlobalPathsWindow);
  341. menu.addSeparator();
  342. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
  343. #endif
  344. }
  345. void ProjucerApplication::createEditMenu (PopupMenu& menu)
  346. {
  347. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::undo);
  348. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::redo);
  349. menu.addSeparator();
  350. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut);
  351. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy);
  352. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste);
  353. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del);
  354. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll);
  355. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll);
  356. menu.addSeparator();
  357. menu.addCommandItem (commandManager, CommandIDs::showFindPanel);
  358. menu.addCommandItem (commandManager, CommandIDs::findSelection);
  359. menu.addCommandItem (commandManager, CommandIDs::findNext);
  360. menu.addCommandItem (commandManager, CommandIDs::findPrevious);
  361. }
  362. void ProjucerApplication::createViewMenu (PopupMenu& menu)
  363. {
  364. menu.addCommandItem (commandManager, CommandIDs::showProjectSettings);
  365. menu.addCommandItem (commandManager, CommandIDs::showProjectTab);
  366. menu.addCommandItem (commandManager, CommandIDs::showBuildTab);
  367. menu.addCommandItem (commandManager, CommandIDs::showFileExplorerPanel);
  368. menu.addCommandItem (commandManager, CommandIDs::showModulesPanel);
  369. menu.addCommandItem (commandManager, CommandIDs::showExportersPanel);
  370. menu.addCommandItem (commandManager, CommandIDs::showExporterSettings);
  371. menu.addSeparator();
  372. createColourSchemeItems (menu);
  373. }
  374. void ProjucerApplication::createBuildMenu (PopupMenu& menu)
  375. {
  376. menu.addCommandItem (commandManager, CommandIDs::toggleBuildEnabled);
  377. menu.addCommandItem (commandManager, CommandIDs::buildNow);
  378. menu.addCommandItem (commandManager, CommandIDs::toggleContinuousBuild);
  379. menu.addSeparator();
  380. menu.addCommandItem (commandManager, CommandIDs::launchApp);
  381. menu.addCommandItem (commandManager, CommandIDs::killApp);
  382. menu.addCommandItem (commandManager, CommandIDs::cleanAll);
  383. menu.addSeparator();
  384. menu.addCommandItem (commandManager, CommandIDs::reinstantiateComp);
  385. menu.addCommandItem (commandManager, CommandIDs::showWarnings);
  386. menu.addSeparator();
  387. menu.addCommandItem (commandManager, CommandIDs::nextError);
  388. menu.addCommandItem (commandManager, CommandIDs::prevError);
  389. }
  390. void ProjucerApplication::createColourSchemeItems (PopupMenu& menu)
  391. {
  392. PopupMenu colourSchemes;
  393. colourSchemes.addItem (colourSchemeBaseID + 0, "Dark", true, selectedColourSchemeIndex == 0);
  394. colourSchemes.addItem (colourSchemeBaseID + 1, "Grey", true, selectedColourSchemeIndex == 1);
  395. colourSchemes.addItem (colourSchemeBaseID + 2, "Light", true, selectedColourSchemeIndex == 2);
  396. menu.addSubMenu ("Colour Scheme", colourSchemes);
  397. //==========================================================================
  398. PopupMenu editorColourSchemes;
  399. auto& appearanceSettings = getAppSettings().appearance;
  400. appearanceSettings.refreshPresetSchemeList();
  401. auto schemes = appearanceSettings.getPresetSchemes();
  402. auto i = 0;
  403. for (auto s : schemes)
  404. {
  405. editorColourSchemes.addItem (codeEditorColourSchemeBaseID + i, s,
  406. editorColourSchemeWindow == nullptr,
  407. selectedEditorColourSchemeIndex == i);
  408. ++i;
  409. }
  410. numEditorColourSchemes = i;
  411. editorColourSchemes.addSeparator();
  412. editorColourSchemes.addItem (codeEditorColourSchemeBaseID + numEditorColourSchemes,
  413. "Create...", editorColourSchemeWindow == nullptr);
  414. menu.addSubMenu ("Editor Colour Scheme", editorColourSchemes);
  415. }
  416. void ProjucerApplication::createWindowMenu (PopupMenu& menu)
  417. {
  418. menu.addCommandItem (commandManager, CommandIDs::goToPreviousWindow);
  419. menu.addCommandItem (commandManager, CommandIDs::goToNextWindow);
  420. menu.addCommandItem (commandManager, CommandIDs::closeWindow);
  421. menu.addSeparator();
  422. int counter = 0;
  423. for (auto* window : mainWindowList.windows)
  424. {
  425. if (window != nullptr)
  426. {
  427. if (auto* project = window->getProject())
  428. menu.addItem (openWindowsBaseID + counter++, project->getProjectNameString());
  429. }
  430. }
  431. menu.addSeparator();
  432. menu.addCommandItem (commandManager, CommandIDs::closeAllWindows);
  433. }
  434. void ProjucerApplication::createDocumentMenu (PopupMenu& menu)
  435. {
  436. menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc);
  437. menu.addCommandItem (commandManager, CommandIDs::goToNextDoc);
  438. menu.addCommandItem (commandManager, CommandIDs::goToCounterpart);
  439. menu.addSeparator();
  440. auto numDocs = jmin (50, openDocumentManager.getNumOpenDocuments());
  441. for (int i = 0; i < numDocs; ++i)
  442. {
  443. OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument(i);
  444. menu.addItem (activeDocumentsBaseID + i, doc->getName());
  445. }
  446. menu.addSeparator();
  447. menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments);
  448. }
  449. void ProjucerApplication::createToolsMenu (PopupMenu& menu)
  450. {
  451. menu.addCommandItem (commandManager, CommandIDs::showUTF8Tool);
  452. menu.addCommandItem (commandManager, CommandIDs::showSVGPathTool);
  453. menu.addCommandItem (commandManager, CommandIDs::showTranslationTool);
  454. }
  455. void ProjucerApplication::createHelpMenu (PopupMenu& menu)
  456. {
  457. menu.addCommandItem (commandManager, CommandIDs::showForum);
  458. menu.addSeparator();
  459. menu.addCommandItem (commandManager, CommandIDs::showAPIModules);
  460. menu.addCommandItem (commandManager, CommandIDs::showAPIClasses);
  461. menu.addCommandItem (commandManager, CommandIDs::showTutorials);
  462. }
  463. void ProjucerApplication::createExtraAppleMenuItems (PopupMenu& menu)
  464. {
  465. menu.addCommandItem (commandManager, CommandIDs::showAboutWindow);
  466. menu.addCommandItem (commandManager, CommandIDs::showAppUsageWindow);
  467. menu.addSeparator();
  468. menu.addCommandItem (commandManager, CommandIDs::showGlobalPathsWindow);
  469. }
  470. void ProjucerApplication::createExamplesPopupMenu (PopupMenu& menu) noexcept
  471. {
  472. numExamples = 0;
  473. for (auto& dir : getSortedExampleDirectories())
  474. {
  475. PopupMenu m;
  476. for (auto& f : getSortedExampleFilesInDirectory (dir))
  477. {
  478. m.addItem (examplesBaseID + numExamples, f.getFileNameWithoutExtension());
  479. ++numExamples;
  480. }
  481. menu.addSubMenu (dir.getFileName(), m);
  482. }
  483. if (numExamples == 0)
  484. {
  485. menu.addItem (showPathsID, "Set path to JUCE...");
  486. }
  487. else
  488. {
  489. menu.addSeparator();
  490. menu.addCommandItem (commandManager, CommandIDs::launchDemoRunner);
  491. }
  492. }
  493. Array<File> ProjucerApplication::getSortedExampleDirectories() const noexcept
  494. {
  495. Array<File> exampleDirectories;
  496. auto examplesPath = getJUCEExamplesDirectoryPathFromGlobal();
  497. if (! isValidJUCEExamplesDirectory (examplesPath))
  498. return {};
  499. DirectoryIterator iter (examplesPath, false, "*", File::findDirectories);
  500. while (iter.next())
  501. {
  502. auto exampleDirectory = iter.getFile();
  503. if (exampleDirectory.getFileName() != "DemoRunner" && exampleDirectory.getFileName() != "Assets")
  504. exampleDirectories.add (exampleDirectory);
  505. }
  506. exampleDirectories.sort();
  507. return exampleDirectories;
  508. }
  509. Array<File> ProjucerApplication::getSortedExampleFilesInDirectory (const File& directory) const noexcept
  510. {
  511. Array<File> exampleFiles;
  512. DirectoryIterator iter (directory, false, "*.h", File::findFiles);
  513. while (iter.next())
  514. exampleFiles.add (iter.getFile());
  515. exampleFiles.sort();
  516. return exampleFiles;
  517. }
  518. bool ProjucerApplication::findWindowAndOpenPIP (const File& pip)
  519. {
  520. auto* window = mainWindowList.getFrontmostWindow();
  521. bool shouldCloseWindow = false;
  522. if (window == nullptr)
  523. {
  524. window = mainWindowList.getOrCreateEmptyWindow();
  525. shouldCloseWindow = true;
  526. }
  527. if (window->tryToOpenPIP (pip))
  528. return true;
  529. if (shouldCloseWindow)
  530. mainWindowList.closeWindow (window);
  531. return false;
  532. }
  533. void ProjucerApplication::findAndLaunchExample (int selectedIndex)
  534. {
  535. File example;
  536. for (auto& dir : getSortedExampleDirectories())
  537. {
  538. auto exampleFiles = getSortedExampleFilesInDirectory (dir);
  539. if (selectedIndex < exampleFiles.size())
  540. {
  541. example = exampleFiles.getUnchecked (selectedIndex);
  542. break;
  543. }
  544. selectedIndex -= exampleFiles.size();
  545. }
  546. // example doesn't exist?
  547. jassert (example != File());
  548. findWindowAndOpenPIP (example);
  549. StringPairArray data;
  550. data.set ("label", example.getFileNameWithoutExtension());
  551. Analytics::getInstance()->logEvent ("Example Opened", data, ProjucerAnalyticsEvent::exampleEvent);
  552. }
  553. File ProjucerApplication::findDemoRunnerExecutable() const noexcept
  554. {
  555. auto buildsPath = getJUCEExamplesDirectoryPathFromGlobal().getChildFile ("DemoRunner").getChildFile ("Builds");
  556. if (! buildsPath.exists())
  557. return {};
  558. String extension;
  559. #if JUCE_MAC
  560. auto osxBuildFolder = buildsPath.getChildFile ("MacOSX").getChildFile ("build");
  561. auto demoRunnerExecutable = osxBuildFolder.getChildFile ("Release").getChildFile ("DemoRunner.app");
  562. if (demoRunnerExecutable.exists())
  563. return demoRunnerExecutable;
  564. demoRunnerExecutable = osxBuildFolder.getChildFile ("Debug").getChildFile ("DemoRunner.app");
  565. if (demoRunnerExecutable.exists())
  566. return demoRunnerExecutable;
  567. extension = ".app";
  568. #elif JUCE_WINDOWS
  569. auto windowsBuildFolder = buildsPath.getChildFile ("VisualStudio2017").getChildFile ("x64");
  570. auto demoRunnerExecutable = windowsBuildFolder.getChildFile ("Release").getChildFile ("App").getChildFile ("DemoRunner.exe");
  571. if (demoRunnerExecutable.existsAsFile())
  572. return demoRunnerExecutable;
  573. demoRunnerExecutable = windowsBuildFolder.getChildFile ("Debug").getChildFile ("App").getChildFile ("DemoRunner.exe");
  574. if (demoRunnerExecutable.existsAsFile())
  575. return demoRunnerExecutable;
  576. extension = ".exe";
  577. #elif JUCE_LINUX
  578. auto linuxBuildFolder = buildsPath.getChildFile ("LinuxMakefile").getChildFile ("build");
  579. auto demoRunnerExecutable = linuxBuildFolder.getChildFile ("DemoRunner");
  580. if (demoRunnerExecutable.existsAsFile())
  581. return demoRunnerExecutable;
  582. extension = {};
  583. #endif
  584. auto juceDir = getAppSettings().getStoredPath (Ids::jucePath).toString();
  585. if (juceDir.isNotEmpty())
  586. {
  587. auto precompiledFile = File (juceDir).getChildFile ("DemoRunner" + extension);
  588. #if JUCE_MAC
  589. if (precompiledFile.exists())
  590. #else
  591. if (precompiledFile.existsAsFile())
  592. #endif
  593. return precompiledFile;
  594. }
  595. return {};
  596. }
  597. File ProjucerApplication::findDemoRunnerProject() const noexcept
  598. {
  599. auto buildsPath = getJUCEExamplesDirectoryPathFromGlobal().getChildFile ("DemoRunner").getChildFile ("Builds");
  600. if (! buildsPath.exists())
  601. return {};
  602. #if JUCE_MAC
  603. auto file = buildsPath.getChildFile ("MacOSX").getChildFile ("DemoRunner.xcodeproj");
  604. if (file.exists())
  605. return file;
  606. #elif JUCE_WINDOW
  607. auto file = buildsPath.getChildFile ("VisualStudio2017").getChildFile ("DemoRunner.sln");
  608. if (file.existsAsFile())
  609. return file;
  610. #elif JUCE_LINUX
  611. auto file = buildsPath.getChildFile ("LinuxMakeFile").getChildFile ("Makefile");
  612. if (file.existsAsFile())
  613. return file;
  614. #endif
  615. return {};
  616. }
  617. void ProjucerApplication::launchDemoRunner()
  618. {
  619. if (findDemoRunnerExecutable() != File())
  620. {
  621. bool succeeded = true;
  622. if (! findDemoRunnerExecutable().startAsProcess())
  623. {
  624. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Error", "There was an error opening the Demo Runner file.");
  625. succeeded = false;
  626. }
  627. StringPairArray data;
  628. data.set ("label", succeeded ? "Success" : "Failure");
  629. Analytics::getInstance()->logEvent ("Launch DemoRunner", data, ProjucerAnalyticsEvent::exampleEvent);
  630. }
  631. else if (findDemoRunnerProject() != File())
  632. {
  633. auto& lf = Desktop::getInstance().getDefaultLookAndFeel();
  634. demoRunnerAlert = lf.createAlertWindow ("Open Project",
  635. "Couldn't find a compiled version of the Demo Runner."
  636. #if JUCE_LINUX
  637. " Do you want to build it now?", "Build project", "Cancel",
  638. #else
  639. " Do you want to open the project?", "Open project", "Cancel",
  640. #endif
  641. {},
  642. AlertWindow::QuestionIcon, 2,
  643. mainWindowList.getFrontmostWindow (false));
  644. demoRunnerAlert->enterModalState (true, ModalCallbackFunction::create ([this] (int retVal)
  645. {
  646. demoRunnerAlert.reset (nullptr);
  647. StringPairArray data;
  648. data.set ("label", retVal == 1 ? "Opened" : "Cancelled");
  649. Analytics::getInstance()->logEvent ("Open DemoRunner Project", data, ProjucerAnalyticsEvent::exampleEvent);
  650. if (retVal == 1)
  651. {
  652. auto projectFile = findDemoRunnerProject();
  653. #if JUCE_LINUX
  654. String command ("make -C " + projectFile.getParentDirectory().getFullPathName() + " CONFIG=Release -j3");
  655. if (! makeProcess.start (command))
  656. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Error", "Error building Demo Runner.");
  657. #else
  658. projectFile.startAsProcess();
  659. #endif
  660. }
  661. }), false);
  662. }
  663. else
  664. {
  665. jassertfalse;
  666. }
  667. }
  668. void ProjucerApplication::handleMainMenuCommand (int menuItemID)
  669. {
  670. if (menuItemID >= recentProjectsBaseID && menuItemID < (recentProjectsBaseID + 100))
  671. {
  672. // open a file from the "recent files" menu
  673. openFile (settings->recentFiles.getFile (menuItemID - recentProjectsBaseID));
  674. }
  675. else if (menuItemID >= openWindowsBaseID && menuItemID < (openWindowsBaseID + 100))
  676. {
  677. if (auto* window = mainWindowList.windows.getUnchecked (menuItemID - openWindowsBaseID))
  678. window->toFront (true);
  679. }
  680. else if (menuItemID >= activeDocumentsBaseID && menuItemID < (activeDocumentsBaseID + 200))
  681. {
  682. if (auto* doc = openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID))
  683. mainWindowList.openDocument (doc, true);
  684. else
  685. jassertfalse;
  686. }
  687. else if (menuItemID >= colourSchemeBaseID && menuItemID < (colourSchemeBaseID + 3))
  688. {
  689. setColourScheme (menuItemID - colourSchemeBaseID, true);
  690. updateEditorColourSchemeIfNeeded();
  691. }
  692. else if (menuItemID >= codeEditorColourSchemeBaseID && menuItemID < (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  693. {
  694. setEditorColourScheme (menuItemID - codeEditorColourSchemeBaseID, true);
  695. }
  696. else if (menuItemID == (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  697. {
  698. showEditorColourSchemeWindow();
  699. }
  700. else if (menuItemID == showPathsID)
  701. {
  702. showPathsWindow (true);
  703. }
  704. else if (menuItemID >= examplesBaseID && menuItemID < (examplesBaseID + numExamples))
  705. {
  706. findAndLaunchExample (menuItemID - examplesBaseID);
  707. }
  708. else
  709. {
  710. handleGUIEditorMenuCommand (menuItemID);
  711. }
  712. }
  713. //==============================================================================
  714. void ProjucerApplication::getAllCommands (Array <CommandID>& commands)
  715. {
  716. JUCEApplication::getAllCommands (commands);
  717. const CommandID ids[] = { CommandIDs::newProject,
  718. CommandIDs::newProjectFromClipboard,
  719. CommandIDs::open,
  720. CommandIDs::launchDemoRunner,
  721. CommandIDs::closeAllWindows,
  722. CommandIDs::closeAllDocuments,
  723. CommandIDs::clearRecentFiles,
  724. CommandIDs::saveAll,
  725. CommandIDs::showGlobalPathsWindow,
  726. CommandIDs::showUTF8Tool,
  727. CommandIDs::showSVGPathTool,
  728. CommandIDs::showAboutWindow,
  729. CommandIDs::showAppUsageWindow,
  730. CommandIDs::showForum,
  731. CommandIDs::showAPIModules,
  732. CommandIDs::showAPIClasses,
  733. CommandIDs::showTutorials,
  734. CommandIDs::loginLogout };
  735. commands.addArray (ids, numElementsInArray (ids));
  736. }
  737. void ProjucerApplication::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
  738. {
  739. switch (commandID)
  740. {
  741. case CommandIDs::newProject:
  742. result.setInfo ("New Project...", "Creates a new JUCE project", CommandCategories::general, 0);
  743. result.defaultKeypresses.add (KeyPress ('n', ModifierKeys::commandModifier, 0));
  744. break;
  745. case CommandIDs::newProjectFromClipboard:
  746. result.setInfo ("New Project From Clipboard...", "Creates a new JUCE project from the clipboard contents", CommandCategories::general, 0);
  747. result.defaultKeypresses.add (KeyPress ('n', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  748. break;
  749. case CommandIDs::launchDemoRunner:
  750. #if JUCE_LINUX
  751. if (makeProcess.isRunning())
  752. {
  753. result.setInfo ("Building Demo Runner...", "The Demo Runner project is currently building", CommandCategories::general, 0);
  754. result.setActive (false);
  755. }
  756. else
  757. #endif
  758. {
  759. result.setInfo ("Launch Demo Runner", "Launches the JUCE demo runner application, or the project if it can't be found", CommandCategories::general, 0);
  760. result.setActive (findDemoRunnerExecutable() != File() || findDemoRunnerProject() != File());
  761. }
  762. break;
  763. case CommandIDs::open:
  764. result.setInfo ("Open...", "Opens a JUCE project", CommandCategories::general, 0);
  765. result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0));
  766. break;
  767. case CommandIDs::showGlobalPathsWindow:
  768. result.setInfo ("Global Paths...",
  769. "Shows the window to change the stored global paths.",
  770. CommandCategories::general, 0);
  771. break;
  772. case CommandIDs::closeAllWindows:
  773. result.setInfo ("Close All Windows", "Closes all open windows", CommandCategories::general, 0);
  774. result.setActive (mainWindowList.windows.size() > 0);
  775. break;
  776. case CommandIDs::closeAllDocuments:
  777. result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0);
  778. result.setActive (openDocumentManager.getNumOpenDocuments() > 0);
  779. break;
  780. case CommandIDs::clearRecentFiles:
  781. result.setInfo ("Clear Recent Files", "Clears all recent files from the menu", CommandCategories::general, 0);
  782. result.setActive (settings->recentFiles.getNumFiles() > 0);
  783. break;
  784. case CommandIDs::saveAll:
  785. result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0);
  786. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::altModifier, 0));
  787. break;
  788. case CommandIDs::showUTF8Tool:
  789. result.setInfo ("UTF-8 String-Literal Helper", "Shows the UTF-8 string literal utility", CommandCategories::general, 0);
  790. break;
  791. case CommandIDs::showSVGPathTool:
  792. result.setInfo ("SVG Path Converter", "Shows the SVG->Path data conversion utility", CommandCategories::general, 0);
  793. break;
  794. case CommandIDs::showAboutWindow:
  795. result.setInfo ("About Projucer", "Shows the Projucer's 'About' page.", CommandCategories::general, 0);
  796. break;
  797. case CommandIDs::showAppUsageWindow:
  798. result.setInfo ("Application Usage Data", "Shows the application usage data agreement window", CommandCategories::general, 0);
  799. break;
  800. case CommandIDs::showForum:
  801. result.setInfo ("JUCE Community Forum", "Shows the JUCE community forum in a browser", CommandCategories::general, 0);
  802. break;
  803. case CommandIDs::showAPIModules:
  804. result.setInfo ("API Modules", "Shows the API modules documentation in a browser", CommandCategories::general, 0);
  805. break;
  806. case CommandIDs::showAPIClasses:
  807. result.setInfo ("API Classes", "Shows the API classes documentation in a browser", CommandCategories::general, 0);
  808. break;
  809. case CommandIDs::showTutorials:
  810. result.setInfo ("JUCE Tutorials", "Shows the JUCE tutorials in a browser", CommandCategories::general, 0);
  811. break;
  812. case CommandIDs::loginLogout:
  813. {
  814. bool isLoggedIn = false;
  815. String username;
  816. if (licenseController != nullptr)
  817. {
  818. const LicenseState state = licenseController->getState();
  819. isLoggedIn = (state.type != LicenseState::Type::notLoggedIn && state.type != LicenseState::Type::GPL);
  820. username = state.username;
  821. }
  822. result.setInfo (isLoggedIn
  823. ? String ("Sign out ") + username + "..."
  824. : String ("Sign in..."),
  825. "Log out of your JUCE account", CommandCategories::general, 0);
  826. }
  827. break;
  828. default:
  829. JUCEApplication::getCommandInfo (commandID, result);
  830. break;
  831. }
  832. }
  833. bool ProjucerApplication::perform (const InvocationInfo& info)
  834. {
  835. switch (info.commandID)
  836. {
  837. case CommandIDs::newProject: createNewProject(); break;
  838. case CommandIDs::newProjectFromClipboard: createNewProjectFromClipboard(); break;
  839. case CommandIDs::open: askUserToOpenFile(); break;
  840. case CommandIDs::launchDemoRunner: launchDemoRunner(); break;
  841. case CommandIDs::saveAll: openDocumentManager.saveAll(); break;
  842. case CommandIDs::closeAllWindows: closeAllMainWindowsAndQuitIfNeeded(); break;
  843. case CommandIDs::closeAllDocuments: closeAllDocuments (true); break;
  844. case CommandIDs::clearRecentFiles: clearRecentFiles(); break;
  845. case CommandIDs::showUTF8Tool: showUTF8ToolWindow(); break;
  846. case CommandIDs::showSVGPathTool: showSVGPathDataToolWindow(); break;
  847. case CommandIDs::showGlobalPathsWindow: showPathsWindow (false); break;
  848. case CommandIDs::showAboutWindow: showAboutWindow(); break;
  849. case CommandIDs::showAppUsageWindow: showApplicationUsageDataAgreementPopup(); break;
  850. case CommandIDs::showForum: launchForumBrowser(); break;
  851. case CommandIDs::showAPIModules: launchModulesBrowser(); break;
  852. case CommandIDs::showAPIClasses: launchClassesBrowser(); break;
  853. case CommandIDs::showTutorials: launchTutorialsBrowser(); break;
  854. case CommandIDs::loginLogout: doLogout(); break;
  855. default: return JUCEApplication::perform (info);
  856. }
  857. return true;
  858. }
  859. //==============================================================================
  860. void ProjucerApplication::createNewProject()
  861. {
  862. auto* mw = mainWindowList.getOrCreateEmptyWindow();
  863. mw->showStartPage();
  864. mainWindowList.avoidSuperimposedWindows (mw);
  865. }
  866. void ProjucerApplication::createNewProjectFromClipboard()
  867. {
  868. auto tempFile = File::getSpecialLocation (File::SpecialLocationType::tempDirectory).getChildFile ("PIPs").getChildFile ("Clipboard")
  869. .getChildFile ("PIPFile_" + String (std::abs (Random::getSystemRandom().nextInt())) + ".h");
  870. if (tempFile.existsAsFile())
  871. tempFile.deleteFile();
  872. tempFile.create();
  873. tempFile.appendText (SystemClipboard::getTextFromClipboard());
  874. if (! findWindowAndOpenPIP (tempFile))
  875. {
  876. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Error", "Couldn't create project from clipboard contents.");
  877. tempFile.deleteFile();
  878. }
  879. }
  880. void ProjucerApplication::updateNewlyOpenedProject (Project& p)
  881. {
  882. LiveBuildProjectSettings::updateNewlyOpenedProject (p);
  883. }
  884. void ProjucerApplication::askUserToOpenFile()
  885. {
  886. FileChooser fc ("Open File");
  887. if (fc.browseForFileToOpen())
  888. openFile (fc.getResult());
  889. }
  890. bool ProjucerApplication::openFile (const File& file)
  891. {
  892. return mainWindowList.openFile (file);
  893. }
  894. bool ProjucerApplication::closeAllDocuments (bool askUserToSave)
  895. {
  896. return openDocumentManager.closeAll (askUserToSave);
  897. }
  898. bool ProjucerApplication::closeAllMainWindows()
  899. {
  900. return server != nullptr || mainWindowList.askAllWindowsToClose();
  901. }
  902. void ProjucerApplication::closeAllMainWindowsAndQuitIfNeeded()
  903. {
  904. if (closeAllMainWindows())
  905. {
  906. #if ! JUCE_MAC
  907. if (mainWindowList.windows.size() == 0)
  908. systemRequestedQuit();
  909. #endif
  910. }
  911. }
  912. void ProjucerApplication::clearRecentFiles()
  913. {
  914. settings->recentFiles.clear();
  915. settings->recentFiles.clearRecentFilesNatively();
  916. settings->flush();
  917. menuModel->menuItemsChanged();
  918. }
  919. //==============================================================================
  920. void ProjucerApplication::showUTF8ToolWindow()
  921. {
  922. if (utf8Window != nullptr)
  923. utf8Window->toFront (true);
  924. else
  925. new FloatingToolWindow ("UTF-8 String Literal Converter",
  926. "utf8WindowPos",
  927. new UTF8Component(), utf8Window, true,
  928. 500, 500, 300, 300, 1000, 1000);
  929. }
  930. void ProjucerApplication::showSVGPathDataToolWindow()
  931. {
  932. if (svgPathWindow != nullptr)
  933. svgPathWindow->toFront (true);
  934. else
  935. new FloatingToolWindow ("SVG Path Converter",
  936. "svgPathWindowPos",
  937. new SVGPathDataComponent(), svgPathWindow, true,
  938. 500, 500, 300, 300, 1000, 1000);
  939. }
  940. void ProjucerApplication::showAboutWindow()
  941. {
  942. if (aboutWindow != nullptr)
  943. aboutWindow->toFront (true);
  944. else
  945. new FloatingToolWindow ({}, {}, new AboutWindowComponent(),
  946. aboutWindow, false,
  947. 500, 300, 500, 300, 500, 300);
  948. }
  949. void ProjucerApplication::showApplicationUsageDataAgreementPopup()
  950. {
  951. if (applicationUsageDataWindow != nullptr)
  952. applicationUsageDataWindow->toFront (true);
  953. else
  954. new FloatingToolWindow ("Application Usage Analytics",
  955. {}, new ApplicationUsageDataWindowComponent (isPaidOrGPL()),
  956. applicationUsageDataWindow, false,
  957. 400, 300, 400, 300, 400, 300);
  958. }
  959. void ProjucerApplication::dismissApplicationUsageDataAgreementPopup()
  960. {
  961. if (applicationUsageDataWindow != nullptr)
  962. applicationUsageDataWindow.reset();
  963. }
  964. void ProjucerApplication::showPathsWindow (bool highlightJUCEPath)
  965. {
  966. if (pathsWindow != nullptr)
  967. pathsWindow->toFront (true);
  968. else
  969. new FloatingToolWindow ("Global Paths",
  970. "pathsWindowPos",
  971. new GlobalPathsWindowComponent(), pathsWindow, false,
  972. 600, 650, 600, 650, 600, 650);
  973. if (highlightJUCEPath)
  974. if (auto* pathsComp = dynamic_cast<GlobalPathsWindowComponent*> (pathsWindow->getChildComponent (0)))
  975. pathsComp->highlightJUCEPath();
  976. }
  977. void ProjucerApplication::showEditorColourSchemeWindow()
  978. {
  979. if (editorColourSchemeWindow != nullptr)
  980. editorColourSchemeWindow->toFront (true);
  981. else
  982. {
  983. new FloatingToolWindow ("Editor Colour Scheme",
  984. "editorColourSchemeWindowPos",
  985. new EditorColourSchemeWindowComponent(),
  986. editorColourSchemeWindow,
  987. false,
  988. 500, 500, 500, 500, 500, 500);
  989. }
  990. }
  991. void ProjucerApplication::launchForumBrowser()
  992. {
  993. URL forumLink ("https://forum.juce.com/");
  994. if (forumLink.isWellFormed())
  995. forumLink.launchInDefaultBrowser();
  996. }
  997. void ProjucerApplication::launchModulesBrowser()
  998. {
  999. URL modulesLink ("https://docs.juce.com/master/modules.html");
  1000. if (modulesLink.isWellFormed())
  1001. modulesLink.launchInDefaultBrowser();
  1002. }
  1003. void ProjucerApplication::launchClassesBrowser()
  1004. {
  1005. URL classesLink ("https://docs.juce.com/master/classes.html");
  1006. if (classesLink.isWellFormed())
  1007. classesLink.launchInDefaultBrowser();
  1008. }
  1009. void ProjucerApplication::launchTutorialsBrowser()
  1010. {
  1011. URL tutorialsLink ("https://juce.com/learn/tutorials");
  1012. if (tutorialsLink.isWellFormed())
  1013. tutorialsLink.launchInDefaultBrowser();
  1014. }
  1015. //==============================================================================
  1016. struct FileWithTime
  1017. {
  1018. FileWithTime (const File& f) : file (f), time (f.getLastModificationTime()) {}
  1019. FileWithTime() {}
  1020. bool operator< (const FileWithTime& other) const { return time < other.time; }
  1021. bool operator== (const FileWithTime& other) const { return time == other.time; }
  1022. File file;
  1023. Time time;
  1024. };
  1025. void ProjucerApplication::deleteLogger()
  1026. {
  1027. const int maxNumLogFilesToKeep = 50;
  1028. Logger::setCurrentLogger (nullptr);
  1029. if (logger != nullptr)
  1030. {
  1031. auto logFiles = logger->getLogFile().getParentDirectory().findChildFiles (File::findFiles, false);
  1032. if (logFiles.size() > maxNumLogFilesToKeep)
  1033. {
  1034. Array<FileWithTime> files;
  1035. for (auto& f : logFiles)
  1036. files.addUsingDefaultSort (f);
  1037. for (int i = 0; i < files.size() - maxNumLogFilesToKeep; ++i)
  1038. files.getReference(i).file.deleteFile();
  1039. }
  1040. }
  1041. logger.reset();
  1042. }
  1043. PropertiesFile::Options ProjucerApplication::getPropertyFileOptionsFor (const String& filename, bool isProjectSettings)
  1044. {
  1045. PropertiesFile::Options options;
  1046. options.applicationName = filename;
  1047. options.filenameSuffix = "settings";
  1048. options.osxLibrarySubFolder = "Application Support";
  1049. #if JUCE_LINUX
  1050. options.folderName = "~/.config/Projucer";
  1051. #else
  1052. options.folderName = "Projucer";
  1053. #endif
  1054. if (isProjectSettings)
  1055. options.folderName += "/ProjectSettings";
  1056. return options;
  1057. }
  1058. void ProjucerApplication::updateAllBuildTabs()
  1059. {
  1060. for (int i = 0; i < mainWindowList.windows.size(); ++i)
  1061. if (ProjectContentComponent* p = mainWindowList.windows.getUnchecked(i)->getProjectContentComponent())
  1062. p->rebuildProjectTabs();
  1063. }
  1064. void ProjucerApplication::initCommandManager()
  1065. {
  1066. commandManager = new ApplicationCommandManager();
  1067. commandManager->registerAllCommandsForTarget (this);
  1068. {
  1069. CodeDocument doc;
  1070. CppCodeEditorComponent ed (File(), doc);
  1071. commandManager->registerAllCommandsForTarget (&ed);
  1072. }
  1073. registerGUIEditorCommands();
  1074. }
  1075. void ProjucerApplication::deleteTemporaryFiles() const noexcept
  1076. {
  1077. auto tempDirectory = File::getSpecialLocation (File::SpecialLocationType::tempDirectory).getChildFile ("PIPs");
  1078. if (tempDirectory.exists())
  1079. tempDirectory.deleteRecursively();
  1080. }
  1081. void ProjucerApplication::setAnalyticsEnabled (bool enabled)
  1082. {
  1083. resetAnalytics();
  1084. if (enabled)
  1085. setupAnalytics();
  1086. }
  1087. void ProjucerApplication::resetAnalytics() noexcept
  1088. {
  1089. auto analyticsInstance = Analytics::getInstance();
  1090. analyticsInstance->setUserId ({});
  1091. analyticsInstance->setUserProperties ({});
  1092. analyticsInstance->getDestinations().clear();
  1093. }
  1094. void ProjucerApplication::setupAnalytics()
  1095. {
  1096. Analytics::getInstance()->addDestination (new ProjucerAnalyticsDestination());
  1097. auto deviceString = SystemStats::getDeviceIdentifiers().joinIntoString (":");
  1098. auto deviceIdentifier = String::toHexString (deviceString.hashCode64());
  1099. Analytics::getInstance()->setUserId (deviceIdentifier);
  1100. StringPairArray userData;
  1101. userData.set ("cd1", getApplicationName());
  1102. userData.set ("cd2", getApplicationVersion());
  1103. userData.set ("cd3", SystemStats::getDeviceDescription());
  1104. userData.set ("cd4", deviceString);
  1105. userData.set ("cd5", SystemStats::getOperatingSystemName());
  1106. Analytics::getInstance()->setUserProperties (userData);
  1107. }
  1108. void ProjucerApplication::showSetJUCEPathAlert()
  1109. {
  1110. auto& lf = Desktop::getInstance().getDefaultLookAndFeel();
  1111. pathAlert = lf.createAlertWindow ("Set JUCE Path", "Your global JUCE path is invalid. This path is used to access the JUCE examples and demo project - "
  1112. "would you like to set it now?",
  1113. "Set path", "Cancel", "Don't ask again",
  1114. AlertWindow::WarningIcon, 3,
  1115. mainWindowList.getFrontmostWindow (false));
  1116. pathAlert->enterModalState (true, ModalCallbackFunction::create ([this] (int retVal)
  1117. {
  1118. pathAlert.reset (nullptr);
  1119. if (retVal == 1)
  1120. showPathsWindow (true);
  1121. else if (retVal == 0)
  1122. settings->setDontAskAboutJUCEPathAgain();
  1123. }));
  1124. }
  1125. void ProjucerApplication::selectEditorColourSchemeWithName (const String& schemeName)
  1126. {
  1127. auto& appearanceSettings = getAppSettings().appearance;
  1128. auto schemes = appearanceSettings.getPresetSchemes();
  1129. auto schemeIndex = schemes.indexOf (schemeName);
  1130. if (schemeIndex >= 0)
  1131. setEditorColourScheme (schemeIndex, true);
  1132. }
  1133. void ProjucerApplication::setColourScheme (int index, bool saveSetting)
  1134. {
  1135. switch (index)
  1136. {
  1137. case 0: lookAndFeel.setColourScheme (LookAndFeel_V4::getDarkColourScheme()); break;
  1138. case 1: lookAndFeel.setColourScheme (LookAndFeel_V4::getGreyColourScheme()); break;
  1139. case 2: lookAndFeel.setColourScheme (LookAndFeel_V4::getLightColourScheme()); break;
  1140. default: break;
  1141. }
  1142. lookAndFeel.setupColours();
  1143. mainWindowList.sendLookAndFeelChange();
  1144. if (utf8Window != nullptr) utf8Window->sendLookAndFeelChange();
  1145. if (svgPathWindow != nullptr) svgPathWindow->sendLookAndFeelChange();
  1146. if (aboutWindow != nullptr) aboutWindow->sendLookAndFeelChange();
  1147. if (applicationUsageDataWindow != nullptr) applicationUsageDataWindow->sendLookAndFeelChange();
  1148. if (pathsWindow != nullptr) pathsWindow->sendLookAndFeelChange();
  1149. if (editorColourSchemeWindow != nullptr) editorColourSchemeWindow->sendLookAndFeelChange();
  1150. auto* mcm = ModalComponentManager::getInstance();
  1151. for (auto i = 0; i < mcm->getNumModalComponents(); ++i)
  1152. mcm->getModalComponent (i)->sendLookAndFeelChange();
  1153. if (saveSetting)
  1154. {
  1155. auto& properties = settings->getGlobalProperties();
  1156. properties.setValue ("COLOUR SCHEME", index);
  1157. }
  1158. selectedColourSchemeIndex = index;
  1159. getCommandManager().commandStatusChanged();
  1160. }
  1161. void ProjucerApplication::setEditorColourScheme (int index, bool saveSetting)
  1162. {
  1163. auto& appearanceSettings = getAppSettings().appearance;
  1164. auto schemes = appearanceSettings.getPresetSchemes();
  1165. index = jmin (index, schemes.size() - 1);
  1166. appearanceSettings.selectPresetScheme (index);
  1167. if (saveSetting)
  1168. {
  1169. auto& properties = settings->getGlobalProperties();
  1170. properties.setValue ("EDITOR COLOUR SCHEME", index);
  1171. }
  1172. selectedEditorColourSchemeIndex = index;
  1173. getCommandManager().commandStatusChanged();
  1174. }
  1175. bool ProjucerApplication::isEditorColourSchemeADefaultScheme (const StringArray& schemes, int editorColourSchemeIndex)
  1176. {
  1177. auto& schemeName = schemes[editorColourSchemeIndex];
  1178. return (schemeName == "Default (Dark)" || schemeName == "Default (Light)");
  1179. }
  1180. int ProjucerApplication::getEditorColourSchemeForGUIColourScheme (const StringArray& schemes, int guiColourSchemeIndex)
  1181. {
  1182. auto defaultDarkEditorIndex = schemes.indexOf ("Default (Dark)");
  1183. auto defaultLightEditorIndex = schemes.indexOf ("Default (Light)");
  1184. // Can't find default code editor colour schemes!
  1185. jassert (defaultDarkEditorIndex != -1 && defaultLightEditorIndex != -1);
  1186. return (guiColourSchemeIndex == 2 ? defaultLightEditorIndex : defaultDarkEditorIndex);
  1187. }
  1188. void ProjucerApplication::updateEditorColourSchemeIfNeeded()
  1189. {
  1190. auto& appearanceSettings = getAppSettings().appearance;
  1191. auto schemes = appearanceSettings.getPresetSchemes();
  1192. if (isEditorColourSchemeADefaultScheme (schemes, selectedEditorColourSchemeIndex))
  1193. setEditorColourScheme (getEditorColourSchemeForGUIColourScheme (schemes, selectedColourSchemeIndex), true);
  1194. }