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.

1440 lines
51KB

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