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.

146 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - 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 this technical preview, this file is not subject to commercial licensing.
  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 "../Project/jucer_Project.h"
  15. //==============================================================================
  16. class OpenDocumentManager
  17. {
  18. public:
  19. //==============================================================================
  20. OpenDocumentManager();
  21. ~OpenDocumentManager();
  22. //==============================================================================
  23. class Document
  24. {
  25. public:
  26. Document() {}
  27. virtual ~Document() {}
  28. virtual bool loadedOk() const = 0;
  29. virtual bool isForFile (const File& file) const = 0;
  30. virtual bool isForNode (const ValueTree& node) const = 0;
  31. virtual bool refersToProject (Project& project) const = 0;
  32. virtual Project* getProject() const = 0;
  33. virtual String getName() const = 0;
  34. virtual String getType() const = 0;
  35. virtual File getFile() const = 0;
  36. virtual bool needsSaving() const = 0;
  37. virtual bool save() = 0;
  38. virtual bool saveAs() = 0;
  39. virtual bool hasFileBeenModifiedExternally() = 0;
  40. virtual void reloadFromFile() = 0;
  41. virtual Component* createEditor() = 0;
  42. virtual Component* createViewer() = 0;
  43. virtual void fileHasBeenRenamed (const File& newFile) = 0;
  44. virtual String getState() const = 0;
  45. virtual void restoreState (const String& state) = 0;
  46. virtual File getCounterpartFile() const { return {}; }
  47. };
  48. //==============================================================================
  49. int getNumOpenDocuments() const;
  50. Document* getOpenDocument (int index) const;
  51. void clear();
  52. enum class SaveIfNeeded { no, yes };
  53. bool canOpenFile (const File& file);
  54. Document* openFile (Project* project, const File& file);
  55. bool closeDocument (int index, SaveIfNeeded saveIfNeeded);
  56. bool closeDocument (Document* document, SaveIfNeeded saveIfNeeded);
  57. bool closeAll (SaveIfNeeded askUserToSave);
  58. bool closeAllDocumentsUsingProject (Project& project, SaveIfNeeded saveIfNeeded);
  59. void closeFile (const File& f, SaveIfNeeded saveIfNeeded);
  60. bool anyFilesNeedSaving() const;
  61. bool saveAll();
  62. FileBasedDocument::SaveResult saveIfNeededAndUserAgrees (Document* doc);
  63. void reloadModifiedFiles();
  64. void fileHasBeenRenamed (const File& oldFile, const File& newFile);
  65. //==============================================================================
  66. class DocumentCloseListener
  67. {
  68. public:
  69. DocumentCloseListener() {}
  70. virtual ~DocumentCloseListener() {}
  71. // return false to force it to stop.
  72. virtual bool documentAboutToClose (Document* document) = 0;
  73. };
  74. void addListener (DocumentCloseListener*);
  75. void removeListener (DocumentCloseListener*);
  76. //==============================================================================
  77. class DocumentType
  78. {
  79. public:
  80. DocumentType() {}
  81. virtual ~DocumentType() {}
  82. virtual bool canOpenFile (const File& file) = 0;
  83. virtual Document* openFile (Project* project, const File& file) = 0;
  84. };
  85. void registerType (DocumentType* type, int index = -1);
  86. private:
  87. OwnedArray<DocumentType> types;
  88. OwnedArray<Document> documents;
  89. Array<DocumentCloseListener*> listeners;
  90. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenDocumentManager)
  91. };
  92. //==============================================================================
  93. class RecentDocumentList : private OpenDocumentManager::DocumentCloseListener
  94. {
  95. public:
  96. RecentDocumentList();
  97. ~RecentDocumentList();
  98. void clear();
  99. void newDocumentOpened (OpenDocumentManager::Document* document);
  100. OpenDocumentManager::Document* getCurrentDocument() const { return previousDocs.getLast(); }
  101. bool canGoToPrevious() const;
  102. bool canGoToNext() const;
  103. bool contains (const File&) const;
  104. OpenDocumentManager::Document* getPrevious();
  105. OpenDocumentManager::Document* getNext();
  106. OpenDocumentManager::Document* getClosestPreviousDocOtherThan (OpenDocumentManager::Document* oneToAvoid) const;
  107. void restoreFromXML (Project& project, const XmlElement& xml);
  108. std::unique_ptr<XmlElement> createXML() const;
  109. private:
  110. bool documentAboutToClose (OpenDocumentManager::Document*);
  111. Array<OpenDocumentManager::Document*> previousDocs, nextDocs;
  112. };