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.

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