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.

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