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.

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