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.

1499 lines
52KB

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