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.

941 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 = nullptr;
  155. utf8Window = nullptr;
  156. svgPathWindow = nullptr;
  157. aboutWindow = nullptr;
  158. pathsWindow = nullptr;
  159. editorColourSchemeWindow = nullptr;
  160. if (licenseController != nullptr)
  161. {
  162. licenseController->removeLicenseStatusChangedCallback (this);
  163. licenseController = nullptr;
  164. }
  165. mainWindowList.forceCloseAllWindows();
  166. openDocumentManager.clear();
  167. childProcessCache = nullptr;
  168. #if JUCE_MAC
  169. MenuBarModel::setMacMainMenu (nullptr);
  170. #endif
  171. menuModel = nullptr;
  172. commandManager = nullptr;
  173. settings = nullptr;
  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 (JUCEApplicationBase* 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. const char* const names[] = { "File", "Edit", "View", "Build", "Window", "GUI Editor", "Tools", nullptr };
  273. return StringArray (names);
  274. }
  275. void ProjucerApplication::createMenu (PopupMenu& menu, const String& menuName)
  276. {
  277. if (menuName == "File") createFileMenu (menu);
  278. else if (menuName == "Edit") createEditMenu (menu);
  279. else if (menuName == "View") createViewMenu (menu);
  280. else if (menuName == "Build") createBuildMenu (menu);
  281. else if (menuName == "Window") createWindowMenu (menu);
  282. else if (menuName == "Tools") createToolsMenu (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::closeWindow);
  391. menu.addSeparator();
  392. menu.addCommandItem (commandManager, CommandIDs::goToPreviousDoc);
  393. menu.addCommandItem (commandManager, CommandIDs::goToNextDoc);
  394. menu.addCommandItem (commandManager, CommandIDs::goToCounterpart);
  395. menu.addSeparator();
  396. const int numDocs = jmin (50, openDocumentManager.getNumOpenDocuments());
  397. for (int i = 0; i < numDocs; ++i)
  398. {
  399. OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument(i);
  400. menu.addItem (activeDocumentsBaseID + i, doc->getName());
  401. }
  402. menu.addSeparator();
  403. menu.addCommandItem (commandManager, CommandIDs::closeAllDocuments);
  404. }
  405. void ProjucerApplication::createToolsMenu (PopupMenu& menu)
  406. {
  407. menu.addCommandItem (commandManager, CommandIDs::showUTF8Tool);
  408. menu.addCommandItem (commandManager, CommandIDs::showSVGPathTool);
  409. menu.addCommandItem (commandManager, CommandIDs::showTranslationTool);
  410. }
  411. void ProjucerApplication::createExtraAppleMenuItems (PopupMenu& menu)
  412. {
  413. menu.addCommandItem (commandManager, CommandIDs::showAboutWindow);
  414. menu.addCommandItem (commandManager, CommandIDs::showAppUsageWindow);
  415. menu.addSeparator();
  416. menu.addCommandItem (commandManager, CommandIDs::showGlobalPathsWindow);
  417. }
  418. void ProjucerApplication::handleMainMenuCommand (int menuItemID)
  419. {
  420. if (menuItemID >= recentProjectsBaseID && menuItemID < (recentProjectsBaseID + 100))
  421. {
  422. // open a file from the "recent files" menu
  423. openFile (settings->recentFiles.getFile (menuItemID - recentProjectsBaseID));
  424. }
  425. else if (menuItemID >= activeDocumentsBaseID && menuItemID < (activeDocumentsBaseID + 200))
  426. {
  427. if (OpenDocumentManager::Document* doc = openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID))
  428. mainWindowList.openDocument (doc, true);
  429. else
  430. jassertfalse;
  431. }
  432. else if (menuItemID >= colourSchemeBaseID && menuItemID < (colourSchemeBaseID + 3))
  433. {
  434. setColourScheme (menuItemID - colourSchemeBaseID, true);
  435. updateEditorColourSchemeIfNeeded();
  436. }
  437. else if (menuItemID >= codeEditorColourSchemeBaseID && menuItemID < (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  438. {
  439. setEditorColourScheme (menuItemID - codeEditorColourSchemeBaseID, true);
  440. }
  441. else if (menuItemID == (codeEditorColourSchemeBaseID + numEditorColourSchemes))
  442. {
  443. showEditorColourSchemeWindow();
  444. }
  445. else
  446. {
  447. handleGUIEditorMenuCommand (menuItemID);
  448. }
  449. }
  450. //==============================================================================
  451. void ProjucerApplication::getAllCommands (Array <CommandID>& commands)
  452. {
  453. JUCEApplication::getAllCommands (commands);
  454. const CommandID ids[] = { CommandIDs::newProject,
  455. CommandIDs::open,
  456. CommandIDs::closeAllDocuments,
  457. CommandIDs::saveAll,
  458. CommandIDs::showGlobalPathsWindow,
  459. CommandIDs::showUTF8Tool,
  460. CommandIDs::showSVGPathTool,
  461. CommandIDs::showAboutWindow,
  462. CommandIDs::showAppUsageWindow,
  463. CommandIDs::loginLogout };
  464. commands.addArray (ids, numElementsInArray (ids));
  465. }
  466. void ProjucerApplication::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
  467. {
  468. switch (commandID)
  469. {
  470. case CommandIDs::newProject:
  471. result.setInfo ("New Project...", "Creates a new Jucer project", CommandCategories::general, 0);
  472. result.defaultKeypresses.add (KeyPress ('n', ModifierKeys::commandModifier, 0));
  473. break;
  474. case CommandIDs::open:
  475. result.setInfo ("Open...", "Opens a Jucer project", CommandCategories::general, 0);
  476. result.defaultKeypresses.add (KeyPress ('o', ModifierKeys::commandModifier, 0));
  477. break;
  478. case CommandIDs::showGlobalPathsWindow:
  479. result.setInfo ("Global Search Paths...",
  480. "Shows the window to change the global search paths.",
  481. CommandCategories::general, 0);
  482. break;
  483. case CommandIDs::closeAllDocuments:
  484. result.setInfo ("Close All Documents", "Closes all open documents", CommandCategories::general, 0);
  485. result.setActive (openDocumentManager.getNumOpenDocuments() > 0);
  486. break;
  487. case CommandIDs::saveAll:
  488. result.setInfo ("Save All", "Saves all open documents", CommandCategories::general, 0);
  489. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::altModifier, 0));
  490. break;
  491. case CommandIDs::showUTF8Tool:
  492. result.setInfo ("UTF-8 String-Literal Helper", "Shows the UTF-8 string literal utility", CommandCategories::general, 0);
  493. break;
  494. case CommandIDs::showSVGPathTool:
  495. result.setInfo ("SVG Path Converter", "Shows the SVG->Path data conversion utility", CommandCategories::general, 0);
  496. break;
  497. case CommandIDs::showAboutWindow:
  498. result.setInfo ("About Projucer", "Shows the Projucer's 'About' page.", CommandCategories::general, 0);
  499. break;
  500. case CommandIDs::showAppUsageWindow:
  501. result.setInfo ("Application Usage Data", "Shows the application usage data agreement window", CommandCategories::general, 0);
  502. break;
  503. case CommandIDs::loginLogout:
  504. {
  505. bool isLoggedIn = false;
  506. String username;
  507. if (licenseController != nullptr)
  508. {
  509. const LicenseState state = licenseController->getState();
  510. isLoggedIn = (state.type != LicenseState::Type::notLoggedIn && state.type != LicenseState::Type::GPL);
  511. username = state.username;
  512. }
  513. result.setInfo (isLoggedIn
  514. ? String ("Sign out ") + username + "..."
  515. : String ("Sign in..."),
  516. "Log out of your JUCE account", CommandCategories::general, 0);
  517. }
  518. break;
  519. default:
  520. JUCEApplication::getCommandInfo (commandID, result);
  521. break;
  522. }
  523. }
  524. bool ProjucerApplication::perform (const InvocationInfo& info)
  525. {
  526. switch (info.commandID)
  527. {
  528. case CommandIDs::newProject: createNewProject(); break;
  529. case CommandIDs::open: askUserToOpenFile(); break;
  530. case CommandIDs::saveAll: openDocumentManager.saveAll(); break;
  531. case CommandIDs::closeAllDocuments: closeAllDocuments (true); break;
  532. case CommandIDs::showUTF8Tool: showUTF8ToolWindow(); break;
  533. case CommandIDs::showSVGPathTool: showSVGPathDataToolWindow(); break;
  534. case CommandIDs::showGlobalPathsWindow: showPathsWindow(); break;
  535. case CommandIDs::showAboutWindow: showAboutWindow(); break;
  536. case CommandIDs::showAppUsageWindow: showApplicationUsageDataAgreementPopup(); break;
  537. case CommandIDs::loginLogout: doLogout(); break;
  538. default: return JUCEApplication::perform (info);
  539. }
  540. return true;
  541. }
  542. //==============================================================================
  543. void ProjucerApplication::createNewProject()
  544. {
  545. MainWindow* mw = mainWindowList.getOrCreateEmptyWindow();
  546. mw->showNewProjectWizard();
  547. mainWindowList.avoidSuperimposedWindows (mw);
  548. }
  549. void ProjucerApplication::updateNewlyOpenedProject (Project& p)
  550. {
  551. LiveBuildProjectSettings::updateNewlyOpenedProject (p);
  552. }
  553. void ProjucerApplication::askUserToOpenFile()
  554. {
  555. FileChooser fc ("Open File");
  556. if (fc.browseForFileToOpen())
  557. openFile (fc.getResult());
  558. }
  559. bool ProjucerApplication::openFile (const File& file)
  560. {
  561. return mainWindowList.openFile (file);
  562. }
  563. bool ProjucerApplication::closeAllDocuments (bool askUserToSave)
  564. {
  565. return openDocumentManager.closeAll (askUserToSave);
  566. }
  567. bool ProjucerApplication::closeAllMainWindows()
  568. {
  569. return server != nullptr || mainWindowList.askAllWindowsToClose();
  570. }
  571. //==============================================================================
  572. void ProjucerApplication::showUTF8ToolWindow()
  573. {
  574. if (utf8Window != nullptr)
  575. utf8Window->toFront (true);
  576. else
  577. new FloatingToolWindow ("UTF-8 String Literal Converter",
  578. "utf8WindowPos",
  579. new UTF8Component(), utf8Window, true,
  580. 500, 500, 300, 300, 1000, 1000);
  581. }
  582. void ProjucerApplication::showSVGPathDataToolWindow()
  583. {
  584. if (svgPathWindow != nullptr)
  585. svgPathWindow->toFront (true);
  586. else
  587. new FloatingToolWindow ("SVG Path Converter",
  588. "svgPathWindowPos",
  589. new SVGPathDataComponent(), svgPathWindow, true,
  590. 500, 500, 300, 300, 1000, 1000);
  591. }
  592. void ProjucerApplication::showAboutWindow()
  593. {
  594. if (aboutWindow != nullptr)
  595. aboutWindow->toFront (true);
  596. else
  597. new FloatingToolWindow ({}, {}, new AboutWindowComponent(),
  598. aboutWindow, false,
  599. 500, 300, 500, 300, 500, 300);
  600. }
  601. void ProjucerApplication::showApplicationUsageDataAgreementPopup()
  602. {
  603. if (applicationUsageDataWindow != nullptr)
  604. applicationUsageDataWindow->toFront (true);
  605. else
  606. new FloatingToolWindow ("Application Usage Analytics",
  607. {}, new ApplicationUsageDataWindowComponent (isPaidOrGPL()),
  608. applicationUsageDataWindow, false,
  609. 400, 300, 400, 300, 400, 300);
  610. }
  611. void ProjucerApplication::dismissApplicationUsageDataAgreementPopup()
  612. {
  613. if (applicationUsageDataWindow != nullptr)
  614. applicationUsageDataWindow = nullptr;
  615. }
  616. void ProjucerApplication::showPathsWindow()
  617. {
  618. if (pathsWindow != nullptr)
  619. pathsWindow->toFront (true);
  620. else
  621. new FloatingToolWindow ("Global Search Paths",
  622. "pathsWindowPos",
  623. new GlobalSearchPathsWindowComponent(), pathsWindow, false,
  624. 600, 500, 600, 500, 600, 500);
  625. }
  626. void ProjucerApplication::showEditorColourSchemeWindow()
  627. {
  628. if (editorColourSchemeWindow != nullptr)
  629. editorColourSchemeWindow->toFront (true);
  630. else
  631. {
  632. new FloatingToolWindow ("Editor Colour Scheme",
  633. "editorColourSchemeWindowPos",
  634. new EditorColourSchemeWindowComponent(),
  635. editorColourSchemeWindow,
  636. false,
  637. 500, 500, 500, 500, 500, 500);
  638. }
  639. }
  640. //==============================================================================
  641. struct FileWithTime
  642. {
  643. FileWithTime (const File& f) : file (f), time (f.getLastModificationTime()) {}
  644. FileWithTime() {}
  645. bool operator< (const FileWithTime& other) const { return time < other.time; }
  646. bool operator== (const FileWithTime& other) const { return time == other.time; }
  647. File file;
  648. Time time;
  649. };
  650. void ProjucerApplication::deleteLogger()
  651. {
  652. const int maxNumLogFilesToKeep = 50;
  653. Logger::setCurrentLogger (nullptr);
  654. if (logger != nullptr)
  655. {
  656. Array<File> logFiles;
  657. logger->getLogFile().getParentDirectory().findChildFiles (logFiles, File::findFiles, false);
  658. if (logFiles.size() > maxNumLogFilesToKeep)
  659. {
  660. Array <FileWithTime> files;
  661. for (int i = 0; i < logFiles.size(); ++i)
  662. files.addUsingDefaultSort (logFiles.getReference(i));
  663. for (int i = 0; i < files.size() - maxNumLogFilesToKeep; ++i)
  664. files.getReference(i).file.deleteFile();
  665. }
  666. }
  667. logger = nullptr;
  668. }
  669. PropertiesFile::Options ProjucerApplication::getPropertyFileOptionsFor (const String& filename, bool isProjectSettings)
  670. {
  671. PropertiesFile::Options options;
  672. options.applicationName = filename;
  673. options.filenameSuffix = "settings";
  674. options.osxLibrarySubFolder = "Application Support";
  675. #if JUCE_LINUX
  676. options.folderName = "~/.config/Projucer";
  677. #else
  678. options.folderName = "Projucer";
  679. #endif
  680. if (isProjectSettings)
  681. options.folderName += "/ProjectSettings";
  682. return options;
  683. }
  684. void ProjucerApplication::updateAllBuildTabs()
  685. {
  686. for (int i = 0; i < mainWindowList.windows.size(); ++i)
  687. if (ProjectContentComponent* p = mainWindowList.windows.getUnchecked(i)->getProjectContentComponent())
  688. p->rebuildProjectTabs();
  689. }
  690. void ProjucerApplication::initCommandManager()
  691. {
  692. commandManager = new ApplicationCommandManager();
  693. commandManager->registerAllCommandsForTarget (this);
  694. {
  695. CodeDocument doc;
  696. CppCodeEditorComponent ed (File(), doc);
  697. commandManager->registerAllCommandsForTarget (&ed);
  698. }
  699. registerGUIEditorCommands();
  700. }
  701. void ProjucerApplication::selectEditorColourSchemeWithName (const String& schemeName)
  702. {
  703. auto& appearanceSettings = getAppSettings().appearance;
  704. auto schemes = appearanceSettings.getPresetSchemes();
  705. auto schemeIndex = schemes.indexOf (schemeName);
  706. if (schemeIndex >= 0)
  707. setEditorColourScheme (schemeIndex, true);
  708. }
  709. void ProjucerApplication::setColourScheme (int index, bool saveSetting)
  710. {
  711. switch (index)
  712. {
  713. case 0: lookAndFeel.setColourScheme (LookAndFeel_V4::getDarkColourScheme()); break;
  714. case 1: lookAndFeel.setColourScheme (LookAndFeel_V4::getGreyColourScheme()); break;
  715. case 2: lookAndFeel.setColourScheme (LookAndFeel_V4::getLightColourScheme()); break;
  716. default: break;
  717. }
  718. lookAndFeel.setupColours();
  719. mainWindowList.sendLookAndFeelChange();
  720. if (utf8Window != nullptr) utf8Window->sendLookAndFeelChange();
  721. if (svgPathWindow != nullptr) svgPathWindow->sendLookAndFeelChange();
  722. if (aboutWindow != nullptr) aboutWindow->sendLookAndFeelChange();
  723. if (applicationUsageDataWindow != nullptr) applicationUsageDataWindow->sendLookAndFeelChange();
  724. if (pathsWindow != nullptr) pathsWindow->sendLookAndFeelChange();
  725. if (editorColourSchemeWindow != nullptr) editorColourSchemeWindow->sendLookAndFeelChange();
  726. auto* mcm = ModalComponentManager::getInstance();
  727. for (auto i = 0; i < mcm->getNumModalComponents(); ++i)
  728. mcm->getModalComponent (i)->sendLookAndFeelChange();
  729. if (saveSetting)
  730. {
  731. auto& properties = settings->getGlobalProperties();
  732. properties.setValue ("COLOUR SCHEME", index);
  733. }
  734. selectedColourSchemeIndex = index;
  735. getCommandManager().commandStatusChanged();
  736. }
  737. void ProjucerApplication::setEditorColourScheme (int index, bool saveSetting)
  738. {
  739. auto& appearanceSettings = getAppSettings().appearance;
  740. auto schemes = appearanceSettings.getPresetSchemes();
  741. index = jmin (index, schemes.size() - 1);
  742. appearanceSettings.selectPresetScheme (index);
  743. if (saveSetting)
  744. {
  745. auto& properties = settings->getGlobalProperties();
  746. properties.setValue ("EDITOR COLOUR SCHEME", index);
  747. }
  748. selectedEditorColourSchemeIndex = index;
  749. getCommandManager().commandStatusChanged();
  750. }
  751. bool ProjucerApplication::isEditorColourSchemeADefaultScheme (const StringArray& schemes, int editorColourSchemeIndex)
  752. {
  753. auto& schemeName = schemes[editorColourSchemeIndex];
  754. return (schemeName == "Default (Dark)" || schemeName == "Default (Light)");
  755. }
  756. int ProjucerApplication::getEditorColourSchemeForGUIColourScheme (const StringArray& schemes, int guiColourSchemeIndex)
  757. {
  758. auto defaultDarkEditorIndex = schemes.indexOf ("Default (Dark)");
  759. auto defaultLightEditorIndex = schemes.indexOf ("Default (Light)");
  760. // Can't find default code editor colour schemes!
  761. jassert (defaultDarkEditorIndex != -1 && defaultLightEditorIndex != -1);
  762. return (guiColourSchemeIndex == 2 ? defaultLightEditorIndex : defaultDarkEditorIndex);
  763. }
  764. void ProjucerApplication::updateEditorColourSchemeIfNeeded()
  765. {
  766. auto& appearanceSettings = getAppSettings().appearance;
  767. auto schemes = appearanceSettings.getPresetSchemes();
  768. if (isEditorColourSchemeADefaultScheme (schemes, selectedEditorColourSchemeIndex))
  769. setEditorColourScheme (getEditorColourSchemeForGUIColourScheme (schemes, selectedColourSchemeIndex), true);
  770. }