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.

149 lines
5.2KB

  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 "../Utility/PIPs/jucer_PIPGenerator.h"
  20. #include "../Project/jucer_Project.h"
  21. #include "../CodeEditor/jucer_OpenDocumentManager.h"
  22. class ProjectContentComponent;
  23. //==============================================================================
  24. /**
  25. The big top-level window where everything happens.
  26. */
  27. class MainWindow : public DocumentWindow,
  28. public ApplicationCommandTarget,
  29. public FileDragAndDropTarget,
  30. public DragAndDropContainer,
  31. private Value::Listener,
  32. private ChangeListener
  33. {
  34. public:
  35. //==============================================================================
  36. MainWindow();
  37. ~MainWindow() override;
  38. enum class OpenInIDE { no, yes };
  39. //==============================================================================
  40. void closeButtonPressed() override;
  41. //==============================================================================
  42. bool canOpenFile (const File& file) const;
  43. void openFile (const File& file, std::function<void (bool)> callback);
  44. void setProject (std::unique_ptr<Project> newProject);
  45. Project* getProject() const { return currentProject.get(); }
  46. void makeVisible();
  47. void restoreWindowPosition();
  48. void updateTitleBarIcon();
  49. void closeCurrentProject (OpenDocumentManager::SaveIfNeeded askToSave, std::function<void (bool)> callback);
  50. void moveProject (File newProjectFile, OpenInIDE openInIDE);
  51. void showStartPage();
  52. void showLoginFormOverlay();
  53. void hideLoginFormOverlay();
  54. bool isShowingLoginForm() const noexcept { return loginFormOpen; }
  55. bool isInterestedInFileDrag (const StringArray& files) override;
  56. void filesDropped (const StringArray& filenames, int mouseX, int mouseY) override;
  57. void activeWindowStatusChanged() override;
  58. ProjectContentComponent* getProjectContentComponent() const;
  59. //==============================================================================
  60. ApplicationCommandTarget* getNextCommandTarget() override;
  61. void getAllCommands (Array <CommandID>& commands) override;
  62. void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result) override;
  63. bool perform (const InvocationInfo& info) override;
  64. bool shouldDropFilesWhenDraggedExternally (const DragAndDropTarget::SourceDetails& sourceDetails,
  65. StringArray& files, bool& canMoveFiles) override;
  66. private:
  67. void valueChanged (Value&) override;
  68. void changeListenerCallback (ChangeBroadcaster* source) override;
  69. static const char* getProjectWindowPosName() { return "projectWindowPos"; }
  70. void createProjectContentCompIfNeeded();
  71. void openPIP (const File&, std::function<void (bool)> callback);
  72. void setupTemporaryPIPProject (PIPGenerator&);
  73. void initialiseProjectWindow();
  74. std::unique_ptr<Project> currentProject;
  75. Value projectNameValue;
  76. std::unique_ptr<Component> blurOverlayComponent;
  77. bool loginFormOpen = false;
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
  79. };
  80. //==============================================================================
  81. class MainWindowList
  82. {
  83. public:
  84. MainWindowList();
  85. void forceCloseAllWindows();
  86. void askAllWindowsToClose (std::function<void (bool)> callback);
  87. void closeWindow (MainWindow*);
  88. void goToSiblingWindow (MainWindow*, int delta);
  89. void createWindowIfNoneAreOpen();
  90. void openDocument (OpenDocumentManager::Document*, bool grabFocus);
  91. void openFile (const File& file, std::function<void (bool)> callback, bool openInBackground = false);
  92. MainWindow* createNewMainWindow();
  93. MainWindow* getFrontmostWindow (bool createIfNotFound = true);
  94. MainWindow* getOrCreateEmptyWindow();
  95. MainWindow* getMainWindowForFile (const File&);
  96. MainWindow* getMainWindowWithLoginFormOpen();
  97. Project* getFrontmostProject();
  98. void reopenLastProjects();
  99. void saveCurrentlyOpenProjectList();
  100. void checkWindowBounds (MainWindow&);
  101. void sendLookAndFeelChange();
  102. OwnedArray<MainWindow> windows;
  103. private:
  104. bool isInReopenLastProjects = false;
  105. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindowList)
  106. JUCE_DECLARE_WEAK_REFERENCEABLE (MainWindowList)
  107. };