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.

1576 lines
55KB

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