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.

1574 lines
55KB

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