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.

225 lines
8.3KB

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