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.

154 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "../Project/jucer_Project.h"
  21. //==============================================================================
  22. /**
  23. */
  24. class OpenDocumentManager
  25. {
  26. public:
  27. //==============================================================================
  28. OpenDocumentManager();
  29. ~OpenDocumentManager();
  30. //==============================================================================
  31. class Document
  32. {
  33. public:
  34. Document() {}
  35. virtual ~Document() {}
  36. virtual bool loadedOk() const = 0;
  37. virtual bool isForFile (const File& file) const = 0;
  38. virtual bool isForNode (const ValueTree& node) const = 0;
  39. virtual bool refersToProject (Project& project) const = 0;
  40. virtual Project* getProject() const = 0;
  41. virtual String getName() const = 0;
  42. virtual String getType() const = 0;
  43. virtual File getFile() const = 0;
  44. virtual bool needsSaving() const = 0;
  45. virtual bool save() = 0;
  46. virtual bool saveAs() = 0;
  47. virtual bool hasFileBeenModifiedExternally() = 0;
  48. virtual void reloadFromFile() = 0;
  49. virtual Component* createEditor() = 0;
  50. virtual Component* createViewer() = 0;
  51. virtual void fileHasBeenRenamed (const File& newFile) = 0;
  52. virtual String getState() const = 0;
  53. virtual void restoreState (const String& state) = 0;
  54. virtual File getCounterpartFile() const { return {}; }
  55. };
  56. //==============================================================================
  57. int getNumOpenDocuments() const;
  58. Document* getOpenDocument (int index) const;
  59. void clear();
  60. bool canOpenFile (const File& file);
  61. Document* openFile (Project* project, const File& file);
  62. bool closeDocument (int index, bool saveIfNeeded);
  63. bool closeDocument (Document* document, bool saveIfNeeded);
  64. bool closeAll (bool askUserToSave);
  65. bool closeAllDocumentsUsingProject (Project& project, bool saveIfNeeded);
  66. void closeFile (const File& f, bool saveIfNeeded);
  67. bool anyFilesNeedSaving() const;
  68. bool saveAll();
  69. FileBasedDocument::SaveResult saveIfNeededAndUserAgrees (Document* doc);
  70. void reloadModifiedFiles();
  71. void fileHasBeenRenamed (const File& oldFile, const File& newFile);
  72. //==============================================================================
  73. class DocumentCloseListener
  74. {
  75. public:
  76. DocumentCloseListener() {}
  77. virtual ~DocumentCloseListener() {}
  78. // return false to force it to stop.
  79. virtual bool documentAboutToClose (Document* document) = 0;
  80. };
  81. void addListener (DocumentCloseListener*);
  82. void removeListener (DocumentCloseListener*);
  83. //==============================================================================
  84. class DocumentType
  85. {
  86. public:
  87. DocumentType() {}
  88. virtual ~DocumentType() {}
  89. virtual bool canOpenFile (const File& file) = 0;
  90. virtual Document* openFile (Project* project, const File& file) = 0;
  91. };
  92. void registerType (DocumentType* type, int index = -1);
  93. private:
  94. OwnedArray<DocumentType> types;
  95. OwnedArray<Document> documents;
  96. Array<DocumentCloseListener*> listeners;
  97. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenDocumentManager)
  98. };
  99. //==============================================================================
  100. class RecentDocumentList : private OpenDocumentManager::DocumentCloseListener
  101. {
  102. public:
  103. RecentDocumentList();
  104. ~RecentDocumentList();
  105. void clear();
  106. void newDocumentOpened (OpenDocumentManager::Document* document);
  107. OpenDocumentManager::Document* getCurrentDocument() const { return previousDocs.getLast(); }
  108. bool canGoToPrevious() const;
  109. bool canGoToNext() const;
  110. bool contains (const File&) const;
  111. OpenDocumentManager::Document* getPrevious();
  112. OpenDocumentManager::Document* getNext();
  113. OpenDocumentManager::Document* getClosestPreviousDocOtherThan (OpenDocumentManager::Document* oneToAvoid) const;
  114. void restoreFromXML (Project& project, const XmlElement& xml);
  115. XmlElement* createXML() const;
  116. private:
  117. bool documentAboutToClose (OpenDocumentManager::Document*);
  118. Array<OpenDocumentManager::Document*> previousDocs, nextDocs;
  119. };