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.

152 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. #include "../Project/jucer_Project.h"
  19. //==============================================================================
  20. /**
  21. */
  22. class OpenDocumentManager
  23. {
  24. public:
  25. //==============================================================================
  26. OpenDocumentManager();
  27. ~OpenDocumentManager();
  28. //==============================================================================
  29. class Document
  30. {
  31. public:
  32. Document() {}
  33. virtual ~Document() {}
  34. virtual bool loadedOk() const = 0;
  35. virtual bool isForFile (const File& file) const = 0;
  36. virtual bool isForNode (const ValueTree& node) const = 0;
  37. virtual bool refersToProject (Project& project) const = 0;
  38. virtual Project* getProject() const = 0;
  39. virtual String getName() const = 0;
  40. virtual String getType() const = 0;
  41. virtual File getFile() const = 0;
  42. virtual bool needsSaving() const = 0;
  43. virtual bool save() = 0;
  44. virtual bool saveAs() = 0;
  45. virtual bool hasFileBeenModifiedExternally() = 0;
  46. virtual void reloadFromFile() = 0;
  47. virtual Component* createEditor() = 0;
  48. virtual Component* createViewer() = 0;
  49. virtual void fileHasBeenRenamed (const File& newFile) = 0;
  50. virtual String getState() const = 0;
  51. virtual void restoreState (const String& state) = 0;
  52. virtual File getCounterpartFile() const { return {}; }
  53. };
  54. //==============================================================================
  55. int getNumOpenDocuments() const;
  56. Document* getOpenDocument (int index) const;
  57. void clear();
  58. bool canOpenFile (const File& file);
  59. Document* openFile (Project* project, const File& file);
  60. bool closeDocument (int index, bool saveIfNeeded);
  61. bool closeDocument (Document* document, bool saveIfNeeded);
  62. bool closeAll (bool askUserToSave);
  63. bool closeAllDocumentsUsingProject (Project& project, bool saveIfNeeded);
  64. void closeFile (const File& f, bool 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. XmlElement* createXML() const;
  114. private:
  115. bool documentAboutToClose (OpenDocumentManager::Document*);
  116. Array<OpenDocumentManager::Document*> previousDocs, nextDocs;
  117. };