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.

943 lines
33KB

  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" };
  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 == "GUI Editor") createGUIEditorMenu (menu);
  283. else jassertfalse; // names have changed?
  284. }
  285. void ProjucerApplication::createFileMenu (PopupMenu& menu)
  286. {
  287. menu.addCommandItem (commandManager, CommandIDs::newProject);
  288. menu.addSeparator();
  289. menu.addCommandItem (commandManager, CommandIDs::open);
  290. PopupMenu recentFiles;
  291. settings->recentFiles.createPopupMenuItems (recentFiles, recentProjectsBaseID, true, true);
  292. menu.addSubMenu ("Open Recent", recentFiles);
  293. menu.addSeparator();
  294. menu.addCommandItem (commandManager, CommandIDs::closeDocument);
  295. menu.addCommandItem (commandManager, CommandIDs::saveDocument);
  296. menu.addCommandItem (commandManager, CommandIDs::saveDocumentAs);
  297. menu.addCommandItem (commandManager, CommandIDs::saveAll);
  298. menu.addSeparator();
  299. menu.addCommandItem (commandManager, CommandIDs::closeProject);
  300. menu.addCommandItem (commandManager, CommandIDs::saveProject);
  301. menu.addSeparator();
  302. menu.addCommandItem (commandManager, CommandIDs::openInIDE);
  303. menu.addCommandItem (commandManager, CommandIDs::saveAndOpenInIDE);
  304. menu.addSeparator();
  305. #if ! JUCER_ENABLE_GPL_MODE
  306. menu.addCommandItem (commandManager, CommandIDs::loginLogout);
  307. #endif
  308. #if ! JUCE_MAC
  309. menu.addCommandItem (commandManager, CommandIDs::showAboutWindow);
  310. menu.addCommandItem (commandManager, CommandIDs::showAppUsageWindow);
  311. menu.addCommandItem (commandManager, CommandIDs::showGlobalPathsWindow);
  312. menu.addSeparator();
  313. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
  314. #endif
  315. }
  316. void ProjucerApplication::createEditMenu (PopupMenu& menu)
  317. {
  318. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::undo);
  319. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::redo);
  320. menu.addSeparator();
  321. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut);
  322. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy);
  323. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste);
  324. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del);
  325. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll);
  326. menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll);
  327. menu.addSeparator();
  328. menu.addCommandItem (commandManager, CommandIDs::showFindPanel);
  329. menu.addCommandItem (commandManager, CommandIDs::findSelection);
  330. menu.addCommandItem (commandManager, CommandIDs::findNext);
  331. menu.addCommandItem (commandManager, CommandIDs::findPrevious);
  332. }
  333. void ProjucerApplication::createViewMenu (PopupMenu& menu)
  334. {
  335. menu.addCommandItem (commandManager, CommandIDs::showProjectSettings);
  336. menu.addCommandItem (commandManager, CommandIDs::showProjectTab);
  337. menu.addCommandItem (commandManager, CommandIDs::showBuildTab);
  338. menu.addCommandItem (commandManager, CommandIDs::showFileExplorerPanel);
  339. menu.addCommandItem (commandManager, CommandIDs::showModulesPanel);
  340. menu.addCommandItem (commandManager, CommandIDs::showExportersPanel);
  341. menu.addCommandItem (commandManager, CommandIDs::showExporterSettings);
  342. menu.addSeparator();
  343. createColourSchemeItems (menu);
  344. }
  345. void ProjucerApplication::createBuildMenu (PopupMenu& menu)
  346. {
  347. menu.addCommandItem (commandManager, CommandIDs::toggleBuildEnabled);
  348. menu.addCommandItem (commandManager, CommandIDs::buildNow);
  349. menu.addCommandItem (commandManager, CommandIDs::toggleContinuousBuild);
  350. menu.addSeparator();
  351. menu.addCommandItem (commandManager, CommandIDs::launchApp);
  352. menu.addCommandItem (commandManager, CommandIDs::killApp);
  353. menu.addCommandItem (commandManager, CommandIDs::cleanAll);
  354. menu.addSeparator();
  355. menu.addCommandItem (commandManager, CommandIDs::reinstantiateComp);
  356. menu.addCommandItem (commandManager, CommandIDs::showWarnings);
  357. menu.addSeparator();
  358. menu.addCommandItem (commandManager, CommandIDs::nextError);
  359. menu.addCommandItem (commandManager, CommandIDs::prevError);
  360. }
  361. void ProjucerApplication::createColourSchemeItems (PopupMenu& menu)
  362. {
  363. PopupMenu colourSchemes;
  364. colourSchemes.addItem (colourSchemeBaseID + 0, "Dark", true, selectedColourSchemeIndex == 0);
  365. colourSchemes.addItem (colourSchemeBaseID + 1, "Grey", true, selectedColourSchemeIndex == 1);
  366. colourSchemes.addItem (colourSchemeBaseID + 2, "Light", true, selectedColourSchemeIndex == 2);
  367. menu.addSubMenu ("Colour Scheme", colourSchemes);
  368. //==========================================================================
  369. PopupMenu editorColourSchemes;
  370. auto& appearanceSettings = getAppSettings().appearance;
  371. appearanceSettings.refreshPresetSchemeList();
  372. auto schemes = appearanceSettings.getPresetSchemes();
  373. auto i = 0;
  374. for (auto s : schemes)
  375. {
  376. editorColourSchemes.addItem (codeEditorColourSchemeBaseID + i, s,
  377. editorColourSchemeWindow == nullptr,
  378. selectedEditorColourSchemeIndex == i);
  379. ++i;
  380. }
  381. numEditorColourSchemes = i;
  382. editorColourSchemes.addSeparator();
  383. editorColourSchemes.addItem (codeEditorColourSchemeBaseID + numEditorColourSchemes,
  384. "Create...", editorColourSchemeWindow == nullptr);
  385. menu.addSubMenu ("Editor Colour Scheme", editorColourSchemes);
  386. }
  387. void ProjucerApplication::createWindowMenu (PopupMenu& menu)
  388. {
  389. menu.addCommandItem (commandManager, CommandIDs::goToPreviousWindow);
  390. menu.addCommandItem (commandManager, CommandIDs::goToNextWindow);
  391. menu.addCommandItem (commandManager, CommandIDs::closeWindow);
  392. menu.addSeparator();
  393. menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc);
  394. menu.addCommandItem (commandManager, CommandIDs::goToNextDoc);
  395. menu.addCommandItem (commandManager, CommandIDs::goToCounterpart);
  396. menu.addSeparator();
  397. const int numDocs = jmin (50, openDocumentManager.getNumOpenDocuments());
  398. for (int i = 0; i < numDocs; ++i)
  399. {
  400. OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument(i);
  401. menu.addItem (activeDocumentsBaseID + i, doc->getName());
  402. }
  403. menu.addSeparator();
  404. menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments);
  405. }
  406. void ProjucerApplication::createToolsMenu (PopupMenu& menu)
  407. {
  408. menu.addCommandItem (commandManager, CommandIDs::showUTF8Tool);
  409. menu.addCommandItem (commandManager, CommandIDs::showSVGPathTool);
  410. menu.addCommandItem (commandManager, CommandIDs::showTranslationTool);
  411. }
  412. void ProjucerApplication::createExtraAppleMenuItems (PopupMenu& menu)
  413. {
  414. menu.addCommandItem (commandManager, CommandIDs::showAboutWindow);
  415. menu.addCommandItem (commandManager, CommandIDs::showAppUsageWindow);
  416. menu.addSeparator();
  417. menu.addCommandItem (commandManager, CommandIDs::showGlobalPathsWindow);
  418. }
  419. void ProjucerApplication::handleMainMenuCommand (int menuItemID)
  420. {
  421. if (menuItemID >= recentProjectsBaseID && menuItemID < (recentProjectsBaseID + 100))
  422. {
  423. // open a file from the "recent files" menu
  424. openFile (settings->recentFiles.getFile (menuItemID - recentProjectsBaseID));
  425. }
  426. else if (menuItemID >= activeDocumentsBaseID && menuItemID < (activeDocumentsBaseID + 200))
  427. {
  428. if (OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID))
  429. mainWindowList.openDocument (doc, true);
  430. else
  431. jassertfalse;
  432. }
  433. else if (menuItemID >= colourSchemeBaseID && menuItemID < (colourSchemeBaseID + 3))
  434. {
  435. setColourScheme (menuItemID - colourSchemeBaseID, true);
  436. updateEditorColourSchemeIfNeeded();
  437. }
  438. else if (menuItemID >= codeEditorColourSchemeBaseID && menuItemID < (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  439. {
  440. setEditorColourScheme (menuItemID - codeEditorColourSchemeBaseID, true);
  441. }
  442. else if (menuItemID == (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  443. {
  444. showEditorColourSchemeWindow();
  445. }
  446. else
  447. {
  448. handleGUIEditorMenuCommand (menuItemID);
  449. }
  450. }
  451. //==============================================================================
  452. void ProjucerApplication::getAllCommands (Array <CommandID>& commands)
  453. {
  454. JUCEApplication::getAllCommands (commands);
  455. const CommandID ids[] = { CommandIDs::newProject,
  456. CommandIDs::open,
  457. CommandIDs::closeAllDocuments,
  458. CommandIDs::saveAll,
  459. CommandIDs::showGlobalPathsWindow,
  460. CommandIDs::showUTF8Tool,
  461. CommandIDs::showSVGPathTool,
  462. CommandIDs::showAboutWindow,
  463. CommandIDs::showAppUsageWindow,
  464. CommandIDs::loginLogout };
  465. commands.addArray (ids, numElementsInArray (ids));
  466. }
  467. void ProjucerApplication::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
  468. {
  469. switch (commandID)
  470. {
  471. case CommandIDs::newProject:
  472. result.setInfo ("New Project...", "Creates a new Jucer project", CommandCategories::general, 0);
  473. result.defaultKeypresses.add (KeyPress ('n', ModifierKeys::commandModifier, 0));
  474. break;
  475. case CommandIDs::open:
  476. result.setInfo ("Open...", "Opens a Jucer project", CommandCategories::general, 0);
  477. result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0));
  478. break;
  479. case CommandIDs::showGlobalPathsWindow:
  480. result.setInfo ("Global Search Paths...",
  481. "Shows the window to change the global search paths.",
  482. CommandCategories::general, 0);
  483. break;
  484. case CommandIDs::closeAllDocuments:
  485. result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0);
  486. result.setActive (openDocumentManager.getNumOpenDocuments() > 0);
  487. break;
  488. case CommandIDs::saveAll:
  489. result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0);
  490. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::altModifier, 0));
  491. break;
  492. case CommandIDs::showUTF8Tool:
  493. result.setInfo ("UTF-8 String-Literal Helper", "Shows the UTF-8 string literal utility", CommandCategories::general, 0);
  494. break;
  495. case CommandIDs::showSVGPathTool:
  496. result.setInfo ("SVG Path Converter", "Shows the SVG->Path data conversion utility", CommandCategories::general, 0);
  497. break;
  498. case CommandIDs::showAboutWindow:
  499. result.setInfo ("About Projucer", "Shows the Projucer's 'About' page.", CommandCategories::general, 0);
  500. break;
  501. case CommandIDs::showAppUsageWindow:
  502. result.setInfo ("Application Usage Data", "Shows the application usage data agreement window", CommandCategories::general, 0);
  503. break;
  504. case CommandIDs::loginLogout:
  505. {
  506. bool isLoggedIn = false;
  507. String username;
  508. if (licenseController != nullptr)
  509. {
  510. const LicenseState state = licenseController->getState();
  511. isLoggedIn = (state.type != LicenseState::Type::notLoggedIn && state.type != LicenseState::Type::GPL);
  512. username = state.username;
  513. }
  514. result.setInfo (isLoggedIn
  515. ? String ("Sign out ") + username + "..."
  516. : String ("Sign in..."),
  517. "Log out of your JUCE account", CommandCategories::general, 0);
  518. }
  519. break;
  520. default:
  521. JUCEApplication::getCommandInfo (commandID, result);
  522. break;
  523. }
  524. }
  525. bool ProjucerApplication::perform (const InvocationInfo& info)
  526. {
  527. switch (info.commandID)
  528. {
  529. case CommandIDs::newProject: createNewProject(); break;
  530. case CommandIDs::open: askUserToOpenFile(); break;
  531. case CommandIDs::saveAll: openDocumentManager.saveAll(); break;
  532. case CommandIDs::closeAllDocuments: closeAllDocuments (true); break;
  533. case CommandIDs::showUTF8Tool: showUTF8ToolWindow(); break;
  534. case CommandIDs::showSVGPathTool: showSVGPathDataToolWindow(); break;
  535. case CommandIDs::showGlobalPathsWindow: showPathsWindow(); break;
  536. case CommandIDs::showAboutWindow: showAboutWindow(); break;
  537. case CommandIDs::showAppUsageWindow: showApplicationUsageDataAgreementPopup(); break;
  538. case CommandIDs::loginLogout: doLogout(); break;
  539. default: return JUCEApplication::perform (info);
  540. }
  541. return true;
  542. }
  543. //==============================================================================
  544. void ProjucerApplication::createNewProject()
  545. {
  546. MainWindow* mw = mainWindowList.getOrCreateEmptyWindow();
  547. mw->showNewProjectWizard();
  548. mainWindowList.avoidSuperimposedWindows (mw);
  549. }
  550. void ProjucerApplication::updateNewlyOpenedProject (Project& p)
  551. {
  552. LiveBuildProjectSettings::updateNewlyOpenedProject (p);
  553. }
  554. void ProjucerApplication::askUserToOpenFile()
  555. {
  556. FileChooser fc ("Open File");
  557. if (fc.browseForFileToOpen())
  558. openFile (fc.getResult());
  559. }
  560. bool ProjucerApplication::openFile (const File& file)
  561. {
  562. return mainWindowList.openFile (file);
  563. }
  564. bool ProjucerApplication::closeAllDocuments (bool askUserToSave)
  565. {
  566. return openDocumentManager.closeAll (askUserToSave);
  567. }
  568. bool ProjucerApplication::closeAllMainWindows()
  569. {
  570. return server != nullptr || mainWindowList.askAllWindowsToClose();
  571. }
  572. //==============================================================================
  573. void ProjucerApplication::showUTF8ToolWindow()
  574. {
  575. if (utf8Window != nullptr)
  576. utf8Window->toFront (true);
  577. else
  578. new FloatingToolWindow ("UTF-8 String Literal Converter",
  579. "utf8WindowPos",
  580. new UTF8Component(), utf8Window, true,
  581. 500, 500, 300, 300, 1000, 1000);
  582. }
  583. void ProjucerApplication::showSVGPathDataToolWindow()
  584. {
  585. if (svgPathWindow != nullptr)
  586. svgPathWindow->toFront (true);
  587. else
  588. new FloatingToolWindow ("SVG Path Converter",
  589. "svgPathWindowPos",
  590. new SVGPathDataComponent(), svgPathWindow, true,
  591. 500, 500, 300, 300, 1000, 1000);
  592. }
  593. void ProjucerApplication::showAboutWindow()
  594. {
  595. if (aboutWindow != nullptr)
  596. aboutWindow->toFront (true);
  597. else
  598. new FloatingToolWindow ({}, {}, new AboutWindowComponent(),
  599. aboutWindow, false,
  600. 500, 300, 500, 300, 500, 300);
  601. }
  602. void ProjucerApplication::showApplicationUsageDataAgreementPopup()
  603. {
  604. if (applicationUsageDataWindow != nullptr)
  605. applicationUsageDataWindow->toFront (true);
  606. else
  607. new FloatingToolWindow ("Application Usage Analytics",
  608. {}, new ApplicationUsageDataWindowComponent (isPaidOrGPL()),
  609. applicationUsageDataWindow, false,
  610. 400, 300, 400, 300, 400, 300);
  611. }
  612. void ProjucerApplication::dismissApplicationUsageDataAgreementPopup()
  613. {
  614. if (applicationUsageDataWindow != nullptr)
  615. applicationUsageDataWindow.reset();
  616. }
  617. void ProjucerApplication::showPathsWindow()
  618. {
  619. if (pathsWindow != nullptr)
  620. pathsWindow->toFront (true);
  621. else
  622. new FloatingToolWindow ("Global Search Paths",
  623. "pathsWindowPos",
  624. new GlobalSearchPathsWindowComponent(), pathsWindow, false,
  625. 600, 500, 600, 500, 600, 500);
  626. }
  627. void ProjucerApplication::showEditorColourSchemeWindow()
  628. {
  629. if (editorColourSchemeWindow != nullptr)
  630. editorColourSchemeWindow->toFront (true);
  631. else
  632. {
  633. new FloatingToolWindow ("Editor Colour Scheme",
  634. "editorColourSchemeWindowPos",
  635. new EditorColourSchemeWindowComponent(),
  636. editorColourSchemeWindow,
  637. false,
  638. 500, 500, 500, 500, 500, 500);
  639. }
  640. }
  641. //==============================================================================
  642. struct FileWithTime
  643. {
  644. FileWithTime (const File& f) : file (f), time (f.getLastModificationTime()) {}
  645. FileWithTime() {}
  646. bool operator< (const FileWithTime& other) const { return time < other.time; }
  647. bool operator== (const FileWithTime& other) const { return time == other.time; }
  648. File file;
  649. Time time;
  650. };
  651. void ProjucerApplication::deleteLogger()
  652. {
  653. const int maxNumLogFilesToKeep = 50;
  654. Logger::setCurrentLogger (nullptr);
  655. if (logger != nullptr)
  656. {
  657. Array<File> logFiles;
  658. logger->getLogFile().getParentDirectory().findChildFiles (logFiles, File::findFiles, false);
  659. if (logFiles.size() > maxNumLogFilesToKeep)
  660. {
  661. Array <FileWithTime> files;
  662. for (int i = 0; i < logFiles.size(); ++i)
  663. files.addUsingDefaultSort (logFiles.getReference(i));
  664. for (int i = 0; i < files.size() - maxNumLogFilesToKeep; ++i)
  665. files.getReference(i).file.deleteFile();
  666. }
  667. }
  668. logger.reset();
  669. }
  670. PropertiesFile::Options ProjucerApplication::getPropertyFileOptionsFor (const String& filename, bool isProjectSettings)
  671. {
  672. PropertiesFile::Options options;
  673. options.applicationName = filename;
  674. options.filenameSuffix = "settings";
  675. options.osxLibrarySubFolder = "Application Support";
  676. #if JUCE_LINUX
  677. options.folderName = "~/.config/Projucer";
  678. #else
  679. options.folderName = "Projucer";
  680. #endif
  681. if (isProjectSettings)
  682. options.folderName += "/ProjectSettings";
  683. return options;
  684. }
  685. void ProjucerApplication::updateAllBuildTabs()
  686. {
  687. for (int i = 0; i < mainWindowList.windows.size(); ++i)
  688. if (ProjectContentComponent* p = mainWindowList.windows.getUnchecked(i)->getProjectContentComponent())
  689. p->rebuildProjectTabs();
  690. }
  691. void ProjucerApplication::initCommandManager()
  692. {
  693. commandManager = new ApplicationCommandManager();
  694. commandManager->registerAllCommandsForTarget (this);
  695. {
  696. CodeDocument doc;
  697. CppCodeEditorComponent ed (File(), doc);
  698. commandManager->registerAllCommandsForTarget (&ed);
  699. }
  700. registerGUIEditorCommands();
  701. }
  702. void ProjucerApplication::selectEditorColourSchemeWithName (const String& schemeName)
  703. {
  704. auto& appearanceSettings = getAppSettings().appearance;
  705. auto schemes = appearanceSettings.getPresetSchemes();
  706. auto schemeIndex = schemes.indexOf (schemeName);
  707. if (schemeIndex >= 0)
  708. setEditorColourScheme (schemeIndex, true);
  709. }
  710. void ProjucerApplication::setColourScheme (int index, bool saveSetting)
  711. {
  712. switch (index)
  713. {
  714. case 0: lookAndFeel.setColourScheme (LookAndFeel_V4::getDarkColourScheme()); break;
  715. case 1: lookAndFeel.setColourScheme (LookAndFeel_V4::getGreyColourScheme()); break;
  716. case 2: lookAndFeel.setColourScheme (LookAndFeel_V4::getLightColourScheme()); break;
  717. default: break;
  718. }
  719. lookAndFeel.setupColours();
  720. mainWindowList.sendLookAndFeelChange();
  721. if (utf8Window != nullptr) utf8Window->sendLookAndFeelChange();
  722. if (svgPathWindow != nullptr) svgPathWindow->sendLookAndFeelChange();
  723. if (aboutWindow != nullptr) aboutWindow->sendLookAndFeelChange();
  724. if (applicationUsageDataWindow != nullptr) applicationUsageDataWindow->sendLookAndFeelChange();
  725. if (pathsWindow != nullptr) pathsWindow->sendLookAndFeelChange();
  726. if (editorColourSchemeWindow != nullptr) editorColourSchemeWindow->sendLookAndFeelChange();
  727. auto* mcm = ModalComponentManager::getInstance();
  728. for (auto i = 0; i < mcm->getNumModalComponents(); ++i)
  729. mcm->getModalComponent (i)->sendLookAndFeelChange();
  730. if (saveSetting)
  731. {
  732. auto& properties = settings->getGlobalProperties();
  733. properties.setValue ("COLOUR SCHEME", index);
  734. }
  735. selectedColourSchemeIndex = index;
  736. getCommandManager().commandStatusChanged();
  737. }
  738. void ProjucerApplication::setEditorColourScheme (int index, bool saveSetting)
  739. {
  740. auto& appearanceSettings = getAppSettings().appearance;
  741. auto schemes = appearanceSettings.getPresetSchemes();
  742. index = jmin (index, schemes.size() - 1);
  743. appearanceSettings.selectPresetScheme (index);
  744. if (saveSetting)
  745. {
  746. auto& properties = settings->getGlobalProperties();
  747. properties.setValue ("EDITOR COLOUR SCHEME", index);
  748. }
  749. selectedEditorColourSchemeIndex = index;
  750. getCommandManager().commandStatusChanged();
  751. }
  752. bool ProjucerApplication::isEditorColourSchemeADefaultScheme (const StringArray& schemes, int editorColourSchemeIndex)
  753. {
  754. auto& schemeName = schemes[editorColourSchemeIndex];
  755. return (schemeName == "Default (Dark)" || schemeName == "Default (Light)");
  756. }
  757. int ProjucerApplication::getEditorColourSchemeForGUIColourScheme (const StringArray& schemes, int guiColourSchemeIndex)
  758. {
  759. auto defaultDarkEditorIndex = schemes.indexOf ("Default (Dark)");
  760. auto defaultLightEditorIndex = schemes.indexOf ("Default (Light)");
  761. // Can't find default code editor colour schemes!
  762. jassert (defaultDarkEditorIndex != -1 && defaultLightEditorIndex != -1);
  763. return (guiColourSchemeIndex == 2 ? defaultLightEditorIndex : defaultDarkEditorIndex);
  764. }
  765. void ProjucerApplication::updateEditorColourSchemeIfNeeded()
  766. {
  767. auto& appearanceSettings = getAppSettings().appearance;
  768. auto schemes = appearanceSettings.getPresetSchemes();
  769. if (isEditorColourSchemeADefaultScheme (schemes, selectedEditorColourSchemeIndex))
  770. setEditorColourScheme (getEditorColourSchemeForGUIColourScheme (schemes, selectedColourSchemeIndex), true);
  771. }