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.

1009 lines
35KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. void createGUIEditorMenu (PopupMenu&);
  20. void handleGUIEditorMenuCommand (int);
  21. void registerGUIEditorCommands();
  22. //==============================================================================
  23. struct ProjucerApplication::MainMenuModel : public MenuBarModel
  24. {
  25. MainMenuModel()
  26. {
  27. setApplicationCommandManagerToWatch (&getCommandManager());
  28. }
  29. StringArray getMenuBarNames() override
  30. {
  31. return getApp().getMenuNames();
  32. }
  33. PopupMenu getMenuForIndex (int /*topLevelMenuIndex*/, const String& menuName) override
  34. {
  35. PopupMenu menu;
  36. getApp().createMenu (menu, menuName);
  37. return menu;
  38. }
  39. void menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/) override
  40. {
  41. getApp().handleMainMenuCommand (menuItemID);
  42. }
  43. };
  44. //==============================================================================
  45. ProjucerApplication::ProjucerApplication() : isRunningCommandLine (false)
  46. {
  47. }
  48. void ProjucerApplication::initialise (const String& commandLine)
  49. {
  50. if (commandLine.trimStart().startsWith ("--server"))
  51. {
  52. initialiseLogger ("Compiler_Log_");
  53. LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  54. #if JUCE_MAC
  55. Process::setDockIconVisible (false);
  56. #endif
  57. server = createClangServer (commandLine);
  58. }
  59. else
  60. {
  61. initialiseLogger ("IDE_Log_");
  62. Logger::writeToLog (SystemStats::getOperatingSystemName());
  63. Logger::writeToLog ("CPU: " + String (SystemStats::getCpuSpeedInMegaherz())
  64. + "MHz Cores: " + String (SystemStats::getNumCpus())
  65. + " " + String (SystemStats::getMemorySizeInMegabytes()) + "MB");
  66. initialiseBasics();
  67. isRunningCommandLine = commandLine.isNotEmpty();
  68. licenseController = new LicenseController;
  69. licenseController->addLicenseStatusChangedCallback (this);
  70. if (isRunningCommandLine)
  71. {
  72. const int appReturnCode = performCommandLine (commandLine);
  73. if (appReturnCode != commandLineNotPerformed)
  74. {
  75. setApplicationReturnValue (appReturnCode);
  76. quit();
  77. return;
  78. }
  79. isRunningCommandLine = false;
  80. }
  81. if (sendCommandLineToPreexistingInstance())
  82. {
  83. DBG ("Another instance is running - quitting...");
  84. quit();
  85. return;
  86. }
  87. openDocumentManager.registerType (new ProjucerAppClasses::LiveBuildCodeEditorDocument::Type(), 2);
  88. childProcessCache = new ChildProcessCache();
  89. initCommandManager();
  90. menuModel = new MainMenuModel();
  91. settings->appearance.refreshPresetSchemeList();
  92. setColourScheme (settings->getGlobalProperties().getIntValue ("COLOUR SCHEME"), false);
  93. setEditorColourScheme (settings->getGlobalProperties().getIntValue ("EDITOR COLOUR SCHEME"), false);
  94. updateEditorColourSchemeIfNeeded();
  95. // do further initialisation in a moment when the message loop has started
  96. triggerAsyncUpdate();
  97. }
  98. }
  99. void ProjucerApplication::initialiseBasics()
  100. {
  101. LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  102. settings = new StoredSettings();
  103. ImageCache::setCacheTimeout (30 * 1000);
  104. icons = new Icons();
  105. tooltipWindow.setMillisecondsBeforeTipAppears (1200);
  106. }
  107. bool ProjucerApplication::initialiseLogger (const char* filePrefix)
  108. {
  109. if (logger == nullptr)
  110. {
  111. #if JUCE_LINUX
  112. String folder = "~/.config/Projucer/Logs";
  113. #else
  114. String folder = "com.juce.projucer";
  115. #endif
  116. logger = FileLogger::createDateStampedLogger (folder, filePrefix, ".txt",
  117. getApplicationName() + " " + getApplicationVersion()
  118. + " --- Build date: " __DATE__);
  119. Logger::setCurrentLogger (logger);
  120. }
  121. return logger != nullptr;
  122. }
  123. void ProjucerApplication::handleAsyncUpdate()
  124. {
  125. if (licenseController != nullptr)
  126. licenseController->startWebviewIfNeeded();
  127. #if JUCE_MAC
  128. PopupMenu extraAppleMenuItems;
  129. createExtraAppleMenuItems (extraAppleMenuItems);
  130. // workaround broken "Open Recent" submenu: not passing the
  131. // submenu's title here avoids the defect in JuceMainMenuHandler::addMenuItem
  132. MenuBarModel::setMacMainMenu (menuModel, &extraAppleMenuItems); //, "Open Recent");
  133. #endif
  134. versionChecker = new LatestVersionChecker();
  135. }
  136. void ProjucerApplication::initialiseWindows (const String& commandLine)
  137. {
  138. const String commandLineWithoutNSDebug (commandLine.replace ("-NSDocumentRevisionsDebugMode YES", StringRef()));
  139. if (commandLineWithoutNSDebug.trim().isNotEmpty() && ! commandLineWithoutNSDebug.trim().startsWithChar ('-'))
  140. anotherInstanceStarted (commandLine);
  141. else
  142. mainWindowList.reopenLastProjects();
  143. mainWindowList.createWindowIfNoneAreOpen();
  144. if (licenseController->getState().applicationUsageDataState == LicenseState::ApplicationUsageData::notChosenYet)
  145. showApplicationUsageDataAgreementPopup();
  146. }
  147. void ProjucerApplication::shutdown()
  148. {
  149. if (server != nullptr)
  150. {
  151. destroyClangServer (server);
  152. Logger::writeToLog ("Server shutdown cleanly");
  153. }
  154. versionChecker.reset();
  155. utf8Window.reset();
  156. svgPathWindow.reset();
  157. aboutWindow.reset();
  158. pathsWindow.reset();
  159. editorColourSchemeWindow.reset();
  160. if (licenseController != nullptr)
  161. {
  162. licenseController->removeLicenseStatusChangedCallback (this);
  163. licenseController.reset();
  164. }
  165. mainWindowList.forceCloseAllWindows();
  166. openDocumentManager.clear();
  167. childProcessCache.reset();
  168. #if JUCE_MAC
  169. MenuBarModel::setMacMainMenu (nullptr);
  170. #endif
  171. menuModel.reset();
  172. commandManager.reset();
  173. settings.reset();
  174. LookAndFeel::setDefaultLookAndFeel (nullptr);
  175. if (! isRunningCommandLine)
  176. Logger::writeToLog ("Shutdown");
  177. deleteLogger();
  178. }
  179. struct AsyncQuitRetrier : private Timer
  180. {
  181. AsyncQuitRetrier() { startTimer (500); }
  182. void timerCallback() override
  183. {
  184. stopTimer();
  185. delete this;
  186. if (auto* app = JUCEApplicationBase::getInstance())
  187. app->systemRequestedQuit();
  188. }
  189. JUCE_DECLARE_NON_COPYABLE (AsyncQuitRetrier)
  190. };
  191. void ProjucerApplication::systemRequestedQuit()
  192. {
  193. if (server != nullptr)
  194. {
  195. sendQuitMessageToIDE (server);
  196. }
  197. else if (ModalComponentManager::getInstance()->cancelAllModalComponents())
  198. {
  199. new AsyncQuitRetrier();
  200. }
  201. else
  202. {
  203. if (closeAllMainWindows())
  204. quit();
  205. }
  206. }
  207. //==============================================================================
  208. void ProjucerApplication::licenseStateChanged (const LicenseState& state)
  209. {
  210. #if ! JUCER_ENABLE_GPL_MODE
  211. if (state.type != LicenseState::Type::notLoggedIn
  212. && state.type != LicenseState::Type::noLicenseChosenYet)
  213. #else
  214. ignoreUnused (state);
  215. #endif
  216. {
  217. initialiseWindows (getCommandLineParameters());
  218. }
  219. }
  220. void ProjucerApplication::doLogout()
  221. {
  222. if (licenseController != nullptr)
  223. {
  224. const LicenseState& state = licenseController->getState();
  225. if (state.type != LicenseState::Type::notLoggedIn && closeAllMainWindows())
  226. licenseController->logout();
  227. }
  228. }
  229. //==============================================================================
  230. String ProjucerApplication::getVersionDescription() const
  231. {
  232. String s;
  233. const Time buildDate (Time::getCompilationDate());
  234. s << "Projucer " << ProjectInfo::versionString
  235. << newLine
  236. << "Build date: " << buildDate.getDayOfMonth()
  237. << " " << Time::getMonthName (buildDate.getMonth(), true)
  238. << " " << buildDate.getYear();
  239. return s;
  240. }
  241. void ProjucerApplication::anotherInstanceStarted (const String& commandLine)
  242. {
  243. if (server == nullptr && ! commandLine.trim().startsWithChar ('-'))
  244. openFile (File (commandLine.unquoted()));
  245. }
  246. ProjucerApplication& ProjucerApplication::getApp()
  247. {
  248. ProjucerApplication* const app = dynamic_cast<ProjucerApplication*> (JUCEApplication::getInstance());
  249. jassert (app != nullptr);
  250. return *app;
  251. }
  252. ApplicationCommandManager& ProjucerApplication::getCommandManager()
  253. {
  254. ApplicationCommandManager* cm = ProjucerApplication::getApp().commandManager;
  255. jassert (cm != nullptr);
  256. return *cm;
  257. }
  258. //==============================================================================
  259. enum
  260. {
  261. recentProjectsBaseID = 100,
  262. activeDocumentsBaseID = 300,
  263. colourSchemeBaseID = 1000,
  264. codeEditorColourSchemeBaseID = 2000,
  265. };
  266. MenuBarModel* ProjucerApplication::getMenuModel()
  267. {
  268. return menuModel.get();
  269. }
  270. StringArray ProjucerApplication::getMenuNames()
  271. {
  272. return { "File", "Edit", "View", "Build", "Window", "GUI Editor", "Tools", "Help" };
  273. }
  274. void ProjucerApplication::createMenu (PopupMenu& menu, const String& menuName)
  275. {
  276. if (menuName == "File") createFileMenu (menu);
  277. else if (menuName == "Edit") createEditMenu (menu);
  278. else if (menuName == "View") createViewMenu (menu);
  279. else if (menuName == "Build") createBuildMenu (menu);
  280. else if (menuName == "Window") createWindowMenu (menu);
  281. else if (menuName == "Tools") createToolsMenu (menu);
  282. else if (menuName == "Help") createHelpMenu (menu);
  283. else if (menuName == "GUI Editor") createGUIEditorMenu (menu);
  284. else jassertfalse; // names have changed?
  285. }
  286. void ProjucerApplication::createFileMenu (PopupMenu& menu)
  287. {
  288. menu.addCommandItem (commandManager, CommandIDs::newProject);
  289. menu.addSeparator();
  290. menu.addCommandItem (commandManager, CommandIDs::open);
  291. PopupMenu recentFiles;
  292. settings->recentFiles.createPopupMenuItems (recentFiles, recentProjectsBaseID, true, true);
  293. menu.addSubMenu ("Open Recent", recentFiles);
  294. menu.addSeparator();
  295. menu.addCommandItem (commandManager, CommandIDs::closeDocument);
  296. menu.addCommandItem (commandManager, CommandIDs::saveDocument);
  297. menu.addCommandItem (commandManager, CommandIDs::saveDocumentAs);
  298. menu.addCommandItem (commandManager, CommandIDs::saveAll);
  299. menu.addSeparator();
  300. menu.addCommandItem (commandManager, CommandIDs::closeProject);
  301. menu.addCommandItem (commandManager, CommandIDs::saveProject);
  302. menu.addSeparator();
  303. menu.addCommandItem (commandManager, CommandIDs::openInIDE);
  304. menu.addCommandItem (commandManager, CommandIDs::saveAndOpenInIDE);
  305. menu.addSeparator();
  306. #if ! JUCER_ENABLE_GPL_MODE
  307. menu.addCommandItem (commandManager, CommandIDs::loginLogout);
  308. #endif
  309. #if ! JUCE_MAC
  310. menu.addCommandItem (commandManager, CommandIDs::showAboutWindow);
  311. menu.addCommandItem (commandManager, CommandIDs::showAppUsageWindow);
  312. menu.addCommandItem (commandManager, CommandIDs::showGlobalPathsWindow);
  313. menu.addSeparator();
  314. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
  315. #endif
  316. }
  317. void ProjucerApplication::createEditMenu (PopupMenu& menu)
  318. {
  319. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::undo);
  320. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::redo);
  321. menu.addSeparator();
  322. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut);
  323. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy);
  324. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste);
  325. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del);
  326. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll);
  327. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll);
  328. menu.addSeparator();
  329. menu.addCommandItem (commandManager, CommandIDs::showFindPanel);
  330. menu.addCommandItem (commandManager, CommandIDs::findSelection);
  331. menu.addCommandItem (commandManager, CommandIDs::findNext);
  332. menu.addCommandItem (commandManager, CommandIDs::findPrevious);
  333. }
  334. void ProjucerApplication::createViewMenu (PopupMenu& menu)
  335. {
  336. menu.addCommandItem (commandManager, CommandIDs::showProjectSettings);
  337. menu.addCommandItem (commandManager, CommandIDs::showProjectTab);
  338. menu.addCommandItem (commandManager, CommandIDs::showBuildTab);
  339. menu.addCommandItem (commandManager, CommandIDs::showFileExplorerPanel);
  340. menu.addCommandItem (commandManager, CommandIDs::showModulesPanel);
  341. menu.addCommandItem (commandManager, CommandIDs::showExportersPanel);
  342. menu.addCommandItem (commandManager, CommandIDs::showExporterSettings);
  343. menu.addSeparator();
  344. createColourSchemeItems (menu);
  345. }
  346. void ProjucerApplication::createBuildMenu (PopupMenu& menu)
  347. {
  348. menu.addCommandItem (commandManager, CommandIDs::toggleBuildEnabled);
  349. menu.addCommandItem (commandManager, CommandIDs::buildNow);
  350. menu.addCommandItem (commandManager, CommandIDs::toggleContinuousBuild);
  351. menu.addSeparator();
  352. menu.addCommandItem (commandManager, CommandIDs::launchApp);
  353. menu.addCommandItem (commandManager, CommandIDs::killApp);
  354. menu.addCommandItem (commandManager, CommandIDs::cleanAll);
  355. menu.addSeparator();
  356. menu.addCommandItem (commandManager, CommandIDs::reinstantiateComp);
  357. menu.addCommandItem (commandManager, CommandIDs::showWarnings);
  358. menu.addSeparator();
  359. menu.addCommandItem (commandManager, CommandIDs::nextError);
  360. menu.addCommandItem (commandManager, CommandIDs::prevError);
  361. }
  362. void ProjucerApplication::createColourSchemeItems (PopupMenu& menu)
  363. {
  364. PopupMenu colourSchemes;
  365. colourSchemes.addItem (colourSchemeBaseID + 0, "Dark", true, selectedColourSchemeIndex == 0);
  366. colourSchemes.addItem (colourSchemeBaseID + 1, "Grey", true, selectedColourSchemeIndex == 1);
  367. colourSchemes.addItem (colourSchemeBaseID + 2, "Light", true, selectedColourSchemeIndex == 2);
  368. menu.addSubMenu ("Colour Scheme", colourSchemes);
  369. //==========================================================================
  370. PopupMenu editorColourSchemes;
  371. auto& appearanceSettings = getAppSettings().appearance;
  372. appearanceSettings.refreshPresetSchemeList();
  373. auto schemes = appearanceSettings.getPresetSchemes();
  374. auto i = 0;
  375. for (auto s : schemes)
  376. {
  377. editorColourSchemes.addItem (codeEditorColourSchemeBaseID + i, s,
  378. editorColourSchemeWindow == nullptr,
  379. selectedEditorColourSchemeIndex == i);
  380. ++i;
  381. }
  382. numEditorColourSchemes = i;
  383. editorColourSchemes.addSeparator();
  384. editorColourSchemes.addItem (codeEditorColourSchemeBaseID + numEditorColourSchemes,
  385. "Create...", editorColourSchemeWindow == nullptr);
  386. menu.addSubMenu ("Editor Colour Scheme", editorColourSchemes);
  387. }
  388. void ProjucerApplication::createWindowMenu (PopupMenu& menu)
  389. {
  390. menu.addCommandItem (commandManager, CommandIDs::goToPreviousWindow);
  391. menu.addCommandItem (commandManager, CommandIDs::goToNextWindow);
  392. menu.addCommandItem (commandManager, CommandIDs::closeWindow);
  393. menu.addSeparator();
  394. menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc);
  395. menu.addCommandItem (commandManager, CommandIDs::goToNextDoc);
  396. menu.addCommandItem (commandManager, CommandIDs::goToCounterpart);
  397. menu.addSeparator();
  398. const int numDocs = jmin (50, openDocumentManager.getNumOpenDocuments());
  399. for (int i = 0; i < numDocs; ++i)
  400. {
  401. OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument(i);
  402. menu.addItem (activeDocumentsBaseID + i, doc->getName());
  403. }
  404. menu.addSeparator();
  405. menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments);
  406. }
  407. void ProjucerApplication::createToolsMenu (PopupMenu& menu)
  408. {
  409. menu.addCommandItem (commandManager, CommandIDs::showUTF8Tool);
  410. menu.addCommandItem (commandManager, CommandIDs::showSVGPathTool);
  411. menu.addCommandItem (commandManager, CommandIDs::showTranslationTool);
  412. }
  413. void ProjucerApplication::createHelpMenu (PopupMenu& menu)
  414. {
  415. menu.addCommandItem (commandManager, CommandIDs::showForum);
  416. menu.addSeparator();
  417. menu.addCommandItem (commandManager, CommandIDs::showAPIModules);
  418. menu.addCommandItem (commandManager, CommandIDs::showAPIClasses);
  419. menu.addCommandItem (commandManager, CommandIDs::showTutorials);
  420. }
  421. void ProjucerApplication::createExtraAppleMenuItems (PopupMenu& menu)
  422. {
  423. menu.addCommandItem (commandManager, CommandIDs::showAboutWindow);
  424. menu.addCommandItem (commandManager, CommandIDs::showAppUsageWindow);
  425. menu.addSeparator();
  426. menu.addCommandItem (commandManager, CommandIDs::showGlobalPathsWindow);
  427. }
  428. void ProjucerApplication::handleMainMenuCommand (int menuItemID)
  429. {
  430. if (menuItemID >= recentProjectsBaseID && menuItemID < (recentProjectsBaseID + 100))
  431. {
  432. // open a file from the "recent files" menu
  433. openFile (settings->recentFiles.getFile (menuItemID - recentProjectsBaseID));
  434. }
  435. else if (menuItemID >= activeDocumentsBaseID && menuItemID < (activeDocumentsBaseID + 200))
  436. {
  437. if (OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID))
  438. mainWindowList.openDocument (doc, true);
  439. else
  440. jassertfalse;
  441. }
  442. else if (menuItemID >= colourSchemeBaseID && menuItemID < (colourSchemeBaseID + 3))
  443. {
  444. setColourScheme (menuItemID - colourSchemeBaseID, true);
  445. updateEditorColourSchemeIfNeeded();
  446. }
  447. else if (menuItemID >= codeEditorColourSchemeBaseID && menuItemID < (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  448. {
  449. setEditorColourScheme (menuItemID - codeEditorColourSchemeBaseID, true);
  450. }
  451. else if (menuItemID == (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  452. {
  453. showEditorColourSchemeWindow();
  454. }
  455. else
  456. {
  457. handleGUIEditorMenuCommand (menuItemID);
  458. }
  459. }
  460. //==============================================================================
  461. void ProjucerApplication::getAllCommands (Array <CommandID>& commands)
  462. {
  463. JUCEApplication::getAllCommands (commands);
  464. const CommandID ids[] = { CommandIDs::newProject,
  465. CommandIDs::open,
  466. CommandIDs::closeAllDocuments,
  467. CommandIDs::saveAll,
  468. CommandIDs::showGlobalPathsWindow,
  469. CommandIDs::showUTF8Tool,
  470. CommandIDs::showSVGPathTool,
  471. CommandIDs::showAboutWindow,
  472. CommandIDs::showAppUsageWindow,
  473. CommandIDs::showForum,
  474. CommandIDs::showAPIModules,
  475. CommandIDs::showAPIClasses,
  476. CommandIDs::showTutorials,
  477. CommandIDs::loginLogout };
  478. commands.addArray (ids, numElementsInArray (ids));
  479. }
  480. void ProjucerApplication::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
  481. {
  482. switch (commandID)
  483. {
  484. case CommandIDs::newProject:
  485. result.setInfo ("New Project...", "Creates a new Jucer project", CommandCategories::general, 0);
  486. result.defaultKeypresses.add (KeyPress ('n', ModifierKeys::commandModifier, 0));
  487. break;
  488. case CommandIDs::open:
  489. result.setInfo ("Open...", "Opens a Jucer project", CommandCategories::general, 0);
  490. result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0));
  491. break;
  492. case CommandIDs::showGlobalPathsWindow:
  493. result.setInfo ("Global Search Paths...",
  494. "Shows the window to change the global search paths.",
  495. CommandCategories::general, 0);
  496. break;
  497. case CommandIDs::closeAllDocuments:
  498. result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0);
  499. result.setActive (openDocumentManager.getNumOpenDocuments() > 0);
  500. break;
  501. case CommandIDs::saveAll:
  502. result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0);
  503. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::altModifier, 0));
  504. break;
  505. case CommandIDs::showUTF8Tool:
  506. result.setInfo ("UTF-8 String-Literal Helper", "Shows the UTF-8 string literal utility", CommandCategories::general, 0);
  507. break;
  508. case CommandIDs::showSVGPathTool:
  509. result.setInfo ("SVG Path Converter", "Shows the SVG->Path data conversion utility", CommandCategories::general, 0);
  510. break;
  511. case CommandIDs::showAboutWindow:
  512. result.setInfo ("About Projucer", "Shows the Projucer's 'About' page.", CommandCategories::general, 0);
  513. break;
  514. case CommandIDs::showAppUsageWindow:
  515. result.setInfo ("Application Usage Data", "Shows the application usage data agreement window", CommandCategories::general, 0);
  516. break;
  517. case CommandIDs::showForum:
  518. result.setInfo ("JUCE Community Forum", "Shows the JUCE community forum in a browser", CommandCategories::general, 0);
  519. break;
  520. case CommandIDs::showAPIModules:
  521. result.setInfo ("API Modules", "Shows the API modules documentation in a browser", CommandCategories::general, 0);
  522. break;
  523. case CommandIDs::showAPIClasses:
  524. result.setInfo ("API Classes", "Shows the API classes documentation in a browser", CommandCategories::general, 0);
  525. break;
  526. case CommandIDs::showTutorials:
  527. result.setInfo ("JUCE Tutorials", "Shows the JUCE tutorials in a browser", CommandCategories::general, 0);
  528. break;
  529. case CommandIDs::loginLogout:
  530. {
  531. bool isLoggedIn = false;
  532. String username;
  533. if (licenseController != nullptr)
  534. {
  535. const LicenseState state = licenseController->getState();
  536. isLoggedIn = (state.type != LicenseState::Type::notLoggedIn && state.type != LicenseState::Type::GPL);
  537. username = state.username;
  538. }
  539. result.setInfo (isLoggedIn
  540. ? String ("Sign out ") + username + "..."
  541. : String ("Sign in..."),
  542. "Log out of your JUCE account", CommandCategories::general, 0);
  543. }
  544. break;
  545. default:
  546. JUCEApplication::getCommandInfo (commandID, result);
  547. break;
  548. }
  549. }
  550. bool ProjucerApplication::perform (const InvocationInfo& info)
  551. {
  552. switch (info.commandID)
  553. {
  554. case CommandIDs::newProject: createNewProject(); break;
  555. case CommandIDs::open: askUserToOpenFile(); break;
  556. case CommandIDs::saveAll: openDocumentManager.saveAll(); break;
  557. case CommandIDs::closeAllDocuments: closeAllDocuments (true); break;
  558. case CommandIDs::showUTF8Tool: showUTF8ToolWindow(); break;
  559. case CommandIDs::showSVGPathTool: showSVGPathDataToolWindow(); break;
  560. case CommandIDs::showGlobalPathsWindow: showPathsWindow(); break;
  561. case CommandIDs::showAboutWindow: showAboutWindow(); break;
  562. case CommandIDs::showAppUsageWindow: showApplicationUsageDataAgreementPopup(); break;
  563. case CommandIDs::showForum: launchForumBrowser(); break;
  564. case CommandIDs::showAPIModules: launchModulesBrowser(); break;
  565. case CommandIDs::showAPIClasses: launchClassesBrowser(); break;
  566. case CommandIDs::showTutorials: launchTutorialsBrowser(); break;
  567. case CommandIDs::loginLogout: doLogout(); break;
  568. default: return JUCEApplication::perform (info);
  569. }
  570. return true;
  571. }
  572. //==============================================================================
  573. void ProjucerApplication::createNewProject()
  574. {
  575. MainWindow* mw = mainWindowList.getOrCreateEmptyWindow();
  576. mw->showNewProjectWizard();
  577. mainWindowList.avoidSuperimposedWindows (mw);
  578. }
  579. void ProjucerApplication::updateNewlyOpenedProject (Project& p)
  580. {
  581. LiveBuildProjectSettings::updateNewlyOpenedProject (p);
  582. }
  583. void ProjucerApplication::askUserToOpenFile()
  584. {
  585. FileChooser fc ("Open File");
  586. if (fc.browseForFileToOpen())
  587. openFile (fc.getResult());
  588. }
  589. bool ProjucerApplication::openFile (const File& file)
  590. {
  591. return mainWindowList.openFile (file);
  592. }
  593. bool ProjucerApplication::closeAllDocuments (bool askUserToSave)
  594. {
  595. return openDocumentManager.closeAll (askUserToSave);
  596. }
  597. bool ProjucerApplication::closeAllMainWindows()
  598. {
  599. return server != nullptr || mainWindowList.askAllWindowsToClose();
  600. }
  601. //==============================================================================
  602. void ProjucerApplication::showUTF8ToolWindow()
  603. {
  604. if (utf8Window != nullptr)
  605. utf8Window->toFront (true);
  606. else
  607. new FloatingToolWindow ("UTF-8 String Literal Converter",
  608. "utf8WindowPos",
  609. new UTF8Component(), utf8Window, true,
  610. 500, 500, 300, 300, 1000, 1000);
  611. }
  612. void ProjucerApplication::showSVGPathDataToolWindow()
  613. {
  614. if (svgPathWindow != nullptr)
  615. svgPathWindow->toFront (true);
  616. else
  617. new FloatingToolWindow ("SVG Path Converter",
  618. "svgPathWindowPos",
  619. new SVGPathDataComponent(), svgPathWindow, true,
  620. 500, 500, 300, 300, 1000, 1000);
  621. }
  622. void ProjucerApplication::showAboutWindow()
  623. {
  624. if (aboutWindow != nullptr)
  625. aboutWindow->toFront (true);
  626. else
  627. new FloatingToolWindow ({}, {}, new AboutWindowComponent(),
  628. aboutWindow, false,
  629. 500, 300, 500, 300, 500, 300);
  630. }
  631. void ProjucerApplication::showApplicationUsageDataAgreementPopup()
  632. {
  633. if (applicationUsageDataWindow != nullptr)
  634. applicationUsageDataWindow->toFront (true);
  635. else
  636. new FloatingToolWindow ("Application Usage Analytics",
  637. {}, new ApplicationUsageDataWindowComponent (isPaidOrGPL()),
  638. applicationUsageDataWindow, false,
  639. 400, 300, 400, 300, 400, 300);
  640. }
  641. void ProjucerApplication::dismissApplicationUsageDataAgreementPopup()
  642. {
  643. if (applicationUsageDataWindow != nullptr)
  644. applicationUsageDataWindow.reset();
  645. }
  646. void ProjucerApplication::showPathsWindow()
  647. {
  648. if (pathsWindow != nullptr)
  649. pathsWindow->toFront (true);
  650. else
  651. new FloatingToolWindow ("Global Search Paths",
  652. "pathsWindowPos",
  653. new GlobalSearchPathsWindowComponent(), pathsWindow, false,
  654. 600, 500, 600, 500, 600, 500);
  655. }
  656. void ProjucerApplication::showEditorColourSchemeWindow()
  657. {
  658. if (editorColourSchemeWindow != nullptr)
  659. editorColourSchemeWindow->toFront (true);
  660. else
  661. {
  662. new FloatingToolWindow ("Editor Colour Scheme",
  663. "editorColourSchemeWindowPos",
  664. new EditorColourSchemeWindowComponent(),
  665. editorColourSchemeWindow,
  666. false,
  667. 500, 500, 500, 500, 500, 500);
  668. }
  669. }
  670. void ProjucerApplication::launchForumBrowser()
  671. {
  672. URL forumLink ("https://forum.juce.com/");
  673. if (forumLink.isWellFormed())
  674. forumLink.launchInDefaultBrowser();
  675. }
  676. void ProjucerApplication::launchModulesBrowser()
  677. {
  678. URL modulesLink ("https://juce.com/doc/modules");
  679. if (modulesLink.isWellFormed())
  680. modulesLink.launchInDefaultBrowser();
  681. }
  682. void ProjucerApplication::launchClassesBrowser()
  683. {
  684. URL classesLink ("https://juce.com/doc/classes");
  685. if (classesLink.isWellFormed())
  686. classesLink.launchInDefaultBrowser();
  687. }
  688. void ProjucerApplication::launchTutorialsBrowser()
  689. {
  690. URL tutorialsLink ("https://juce.com/tutorials");
  691. if (tutorialsLink.isWellFormed())
  692. tutorialsLink.launchInDefaultBrowser();
  693. }
  694. //==============================================================================
  695. struct FileWithTime
  696. {
  697. FileWithTime (const File& f) : file (f), time (f.getLastModificationTime()) {}
  698. FileWithTime() {}
  699. bool operator< (const FileWithTime& other) const { return time < other.time; }
  700. bool operator== (const FileWithTime& other) const { return time == other.time; }
  701. File file;
  702. Time time;
  703. };
  704. void ProjucerApplication::deleteLogger()
  705. {
  706. const int maxNumLogFilesToKeep = 50;
  707. Logger::setCurrentLogger (nullptr);
  708. if (logger != nullptr)
  709. {
  710. Array<File> logFiles;
  711. logger->getLogFile().getParentDirectory().findChildFiles (logFiles, File::findFiles, false);
  712. if (logFiles.size() > maxNumLogFilesToKeep)
  713. {
  714. Array <FileWithTime> files;
  715. for (int i = 0; i < logFiles.size(); ++i)
  716. files.addUsingDefaultSort (logFiles.getReference(i));
  717. for (int i = 0; i < files.size() - maxNumLogFilesToKeep; ++i)
  718. files.getReference(i).file.deleteFile();
  719. }
  720. }
  721. logger.reset();
  722. }
  723. PropertiesFile::Options ProjucerApplication::getPropertyFileOptionsFor (const String& filename, bool isProjectSettings)
  724. {
  725. PropertiesFile::Options options;
  726. options.applicationName = filename;
  727. options.filenameSuffix = "settings";
  728. options.osxLibrarySubFolder = "Application Support";
  729. #if JUCE_LINUX
  730. options.folderName = "~/.config/Projucer";
  731. #else
  732. options.folderName = "Projucer";
  733. #endif
  734. if (isProjectSettings)
  735. options.folderName += "/ProjectSettings";
  736. return options;
  737. }
  738. void ProjucerApplication::updateAllBuildTabs()
  739. {
  740. for (int i = 0; i < mainWindowList.windows.size(); ++i)
  741. if (ProjectContentComponent* p = mainWindowList.windows.getUnchecked(i)->getProjectContentComponent())
  742. p->rebuildProjectTabs();
  743. }
  744. void ProjucerApplication::initCommandManager()
  745. {
  746. commandManager = new ApplicationCommandManager();
  747. commandManager->registerAllCommandsForTarget (this);
  748. {
  749. CodeDocument doc;
  750. CppCodeEditorComponent ed (File(), doc);
  751. commandManager->registerAllCommandsForTarget (&ed);
  752. }
  753. registerGUIEditorCommands();
  754. }
  755. void ProjucerApplication::selectEditorColourSchemeWithName (const String& schemeName)
  756. {
  757. auto& appearanceSettings = getAppSettings().appearance;
  758. auto schemes = appearanceSettings.getPresetSchemes();
  759. auto schemeIndex = schemes.indexOf (schemeName);
  760. if (schemeIndex >= 0)
  761. setEditorColourScheme (schemeIndex, true);
  762. }
  763. void ProjucerApplication::setColourScheme (int index, bool saveSetting)
  764. {
  765. switch (index)
  766. {
  767. case 0: lookAndFeel.setColourScheme (LookAndFeel_V4::getDarkColourScheme()); break;
  768. case 1: lookAndFeel.setColourScheme (LookAndFeel_V4::getGreyColourScheme()); break;
  769. case 2: lookAndFeel.setColourScheme (LookAndFeel_V4::getLightColourScheme()); break;
  770. default: break;
  771. }
  772. lookAndFeel.setupColours();
  773. mainWindowList.sendLookAndFeelChange();
  774. if (utf8Window != nullptr) utf8Window->sendLookAndFeelChange();
  775. if (svgPathWindow != nullptr) svgPathWindow->sendLookAndFeelChange();
  776. if (aboutWindow != nullptr) aboutWindow->sendLookAndFeelChange();
  777. if (applicationUsageDataWindow != nullptr) applicationUsageDataWindow->sendLookAndFeelChange();
  778. if (pathsWindow != nullptr) pathsWindow->sendLookAndFeelChange();
  779. if (editorColourSchemeWindow != nullptr) editorColourSchemeWindow->sendLookAndFeelChange();
  780. auto* mcm = ModalComponentManager::getInstance();
  781. for (auto i = 0; i < mcm->getNumModalComponents(); ++i)
  782. mcm->getModalComponent (i)->sendLookAndFeelChange();
  783. if (saveSetting)
  784. {
  785. auto& properties = settings->getGlobalProperties();
  786. properties.setValue ("COLOUR SCHEME", index);
  787. }
  788. selectedColourSchemeIndex = index;
  789. getCommandManager().commandStatusChanged();
  790. }
  791. void ProjucerApplication::setEditorColourScheme (int index, bool saveSetting)
  792. {
  793. auto& appearanceSettings = getAppSettings().appearance;
  794. auto schemes = appearanceSettings.getPresetSchemes();
  795. index = jmin (index, schemes.size() - 1);
  796. appearanceSettings.selectPresetScheme (index);
  797. if (saveSetting)
  798. {
  799. auto& properties = settings->getGlobalProperties();
  800. properties.setValue ("EDITOR COLOUR SCHEME", index);
  801. }
  802. selectedEditorColourSchemeIndex = index;
  803. getCommandManager().commandStatusChanged();
  804. }
  805. bool ProjucerApplication::isEditorColourSchemeADefaultScheme (const StringArray& schemes, int editorColourSchemeIndex)
  806. {
  807. auto& schemeName = schemes[editorColourSchemeIndex];
  808. return (schemeName == "Default (Dark)" || schemeName == "Default (Light)");
  809. }
  810. int ProjucerApplication::getEditorColourSchemeForGUIColourScheme (const StringArray& schemes, int guiColourSchemeIndex)
  811. {
  812. auto defaultDarkEditorIndex = schemes.indexOf ("Default (Dark)");
  813. auto defaultLightEditorIndex = schemes.indexOf ("Default (Light)");
  814. // Can't find default code editor colour schemes!
  815. jassert (defaultDarkEditorIndex != -1 && defaultLightEditorIndex != -1);
  816. return (guiColourSchemeIndex == 2 ? defaultLightEditorIndex : defaultDarkEditorIndex);
  817. }
  818. void ProjucerApplication::updateEditorColourSchemeIfNeeded()
  819. {
  820. auto& appearanceSettings = getAppSettings().appearance;
  821. auto schemes = appearanceSettings.getPresetSchemes();
  822. if (isEditorColourSchemeADefaultScheme (schemes, selectedEditorColourSchemeIndex))
  823. setEditorColourScheme (getEditorColourSchemeForGUIColourScheme (schemes, selectedColourSchemeIndex), true);
  824. }