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.

153 lines
5.3KB

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