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.

218 lines
8.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "UserAccount/jucer_LicenseController.h"
  15. #include "jucer_MainWindow.h"
  16. #include "../Project/Modules/jucer_Modules.h"
  17. #include "jucer_AutoUpdater.h"
  18. #include "../CodeEditor/jucer_SourceCodeEditor.h"
  19. #include "../Utility/UI/jucer_ProjucerLookAndFeel.h"
  20. //==============================================================================
  21. class ProjucerApplication : public JUCEApplication,
  22. private AsyncUpdater
  23. {
  24. public:
  25. ProjucerApplication() = default;
  26. static ProjucerApplication& getApp();
  27. static ApplicationCommandManager& getCommandManager();
  28. //==============================================================================
  29. void initialise (const String& commandLine) override;
  30. void shutdown() override;
  31. void systemRequestedQuit() override;
  32. void deleteLogger();
  33. const String getApplicationName() override { return "Projucer"; }
  34. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  35. String getVersionDescription() const;
  36. bool moreThanOneInstanceAllowed() override { return true; } // this is handled manually in initialise()
  37. void anotherInstanceStarted (const String& commandLine) override;
  38. //==============================================================================
  39. MenuBarModel* getMenuModel();
  40. void getAllCommands (Array<CommandID>&) override;
  41. void getCommandInfo (CommandID commandID, ApplicationCommandInfo&) override;
  42. bool perform (const InvocationInfo&) override;
  43. bool isGUIEditorEnabled() const;
  44. //==============================================================================
  45. void openFile (const File&, std::function<void (bool)>);
  46. void showPathsWindow (bool highlightJUCEPath = false);
  47. PropertiesFile::Options getPropertyFileOptionsFor (const String& filename, bool isProjectSettings);
  48. void selectEditorColourSchemeWithName (const String& schemeName);
  49. //==============================================================================
  50. void rescanJUCEPathModules();
  51. void rescanUserPathModules();
  52. AvailableModulesList& getJUCEPathModulesList() { return jucePathModulesList; }
  53. AvailableModulesList& getUserPathsModulesList() { return userPathsModulesList; }
  54. LicenseController& getLicenseController() { return *licenseController; }
  55. bool isAutomaticVersionCheckingEnabled() const;
  56. void setAutomaticVersionCheckingEnabled (bool shouldBeEnabled);
  57. bool shouldPromptUserAboutIncorrectJUCEPath() const;
  58. void setShouldPromptUserAboutIncorrectJUCEPath (bool shouldPrompt);
  59. static File getJUCEExamplesDirectoryPathFromGlobal() noexcept;
  60. static Array<File> getSortedExampleDirectories() noexcept;
  61. static Array<File> getSortedExampleFilesInDirectory (const File&) noexcept;
  62. //==============================================================================
  63. ProjucerLookAndFeel lookAndFeel;
  64. std::unique_ptr<StoredSettings> settings;
  65. std::unique_ptr<Icons> icons;
  66. struct MainMenuModel;
  67. std::unique_ptr<MainMenuModel> menuModel;
  68. MainWindowList mainWindowList;
  69. OpenDocumentManager openDocumentManager;
  70. std::unique_ptr<ApplicationCommandManager> commandManager;
  71. bool isRunningCommandLine = false;
  72. private:
  73. //==============================================================================
  74. void handleAsyncUpdate() override;
  75. void doBasicApplicationSetup();
  76. void initCommandManager();
  77. bool initialiseLogger (const char* filePrefix);
  78. void initialiseWindows (const String& commandLine);
  79. void createNewProject();
  80. void createNewProjectFromClipboard();
  81. void createNewPIP();
  82. void askUserToOpenFile();
  83. void saveAllDocuments();
  84. void closeAllDocuments (OpenDocumentManager::SaveIfNeeded askUserToSave);
  85. void closeAllMainWindows (std::function<void (bool)>);
  86. void closeAllMainWindowsAndQuitIfNeeded();
  87. void clearRecentFiles();
  88. StringArray getMenuNames();
  89. PopupMenu createMenu (const String& menuName);
  90. PopupMenu createFileMenu();
  91. PopupMenu createEditMenu();
  92. PopupMenu createViewMenu();
  93. void createColourSchemeItems (PopupMenu&);
  94. PopupMenu createWindowMenu();
  95. PopupMenu createDocumentMenu();
  96. PopupMenu createToolsMenu();
  97. PopupMenu createHelpMenu();
  98. PopupMenu createExtraAppleMenuItems();
  99. void handleMainMenuCommand (int menuItemID);
  100. PopupMenu createExamplesPopupMenu() noexcept;
  101. void findAndLaunchExample (int);
  102. void checkIfGlobalJUCEPathHasChanged();
  103. File tryToFindDemoRunnerExecutable();
  104. File tryToFindDemoRunnerProject();
  105. void launchDemoRunner();
  106. void setColourScheme (int index, bool saveSetting);
  107. void setEditorColourScheme (int index, bool saveSetting);
  108. void updateEditorColourSchemeIfNeeded();
  109. void showUTF8ToolWindow();
  110. void showSVGPathDataToolWindow();
  111. void showAboutWindow();
  112. void showEditorColourSchemeWindow();
  113. void showPIPCreatorWindow();
  114. void launchForumBrowser();
  115. void launchModulesBrowser();
  116. void launchClassesBrowser();
  117. void launchTutorialsBrowser();
  118. void doLoginOrLogout();
  119. void showLoginForm();
  120. void enableOrDisableGUIEditor();
  121. //==============================================================================
  122. #if JUCE_MAC
  123. class AppleMenuRebuildListener : private MenuBarModel::Listener
  124. {
  125. public:
  126. AppleMenuRebuildListener()
  127. {
  128. if (auto* model = ProjucerApplication::getApp().getMenuModel())
  129. model->addListener (this);
  130. }
  131. ~AppleMenuRebuildListener() override
  132. {
  133. if (auto* model = ProjucerApplication::getApp().getMenuModel())
  134. model->removeListener (this);
  135. }
  136. private:
  137. void menuBarItemsChanged (MenuBarModel*) override {}
  138. void menuCommandInvoked (MenuBarModel*,
  139. const ApplicationCommandTarget::InvocationInfo& info) override
  140. {
  141. if (info.commandID == CommandIDs::enableNewVersionCheck)
  142. Timer::callAfterDelay (50, [] { ProjucerApplication::getApp().rebuildAppleMenu(); });
  143. }
  144. };
  145. void rebuildAppleMenu();
  146. std::unique_ptr<AppleMenuRebuildListener> appleMenuRebuildListener;
  147. #endif
  148. //==============================================================================
  149. std::unique_ptr<LicenseController> licenseController;
  150. std::unique_ptr<TooltipWindow> tooltipWindow;
  151. AvailableModulesList jucePathModulesList, userPathsModulesList;
  152. std::unique_ptr<Component> utf8Window, svgPathWindow, aboutWindow, pathsWindow,
  153. editorColourSchemeWindow, pipCreatorWindow;
  154. std::unique_ptr<FileLogger> logger;
  155. int numExamples = 0;
  156. std::unique_ptr<AlertWindow> demoRunnerAlert;
  157. bool hasScannedForDemoRunnerExecutable = false, hasScannedForDemoRunnerProject = false;
  158. File lastJUCEPath, lastDemoRunnerExectuableFile, lastDemoRunnerProjectFile;
  159. int selectedColourSchemeIndex = 0, selectedEditorColourSchemeIndex = 0;
  160. std::unique_ptr<FileChooser> chooser;
  161. //==============================================================================
  162. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjucerApplication)
  163. JUCE_DECLARE_WEAK_REFERENCEABLE (ProjucerApplication)
  164. };