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.

144 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  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. bool canOpenFile (const File& file);
  53. Document* openFile (Project* project, const File& file);
  54. bool closeDocument (int index, bool saveIfNeeded);
  55. bool closeDocument (Document* document, bool saveIfNeeded);
  56. bool closeAll (bool askUserToSave);
  57. bool closeAllDocumentsUsingProject (Project& project, bool saveIfNeeded);
  58. void closeFile (const File& f, bool saveIfNeeded);
  59. bool anyFilesNeedSaving() const;
  60. bool saveAll();
  61. FileBasedDocument::SaveResult saveIfNeededAndUserAgrees (Document* doc);
  62. void reloadModifiedFiles();
  63. void fileHasBeenRenamed (const File& oldFile, const File& newFile);
  64. //==============================================================================
  65. class DocumentCloseListener
  66. {
  67. public:
  68. DocumentCloseListener() {}
  69. virtual ~DocumentCloseListener() {}
  70. // return false to force it to stop.
  71. virtual bool documentAboutToClose (Document* document) = 0;
  72. };
  73. void addListener (DocumentCloseListener*);
  74. void removeListener (DocumentCloseListener*);
  75. //==============================================================================
  76. class DocumentType
  77. {
  78. public:
  79. DocumentType() {}
  80. virtual ~DocumentType() {}
  81. virtual bool canOpenFile (const File& file) = 0;
  82. virtual Document* openFile (Project* project, const File& file) = 0;
  83. };
  84. void registerType (DocumentType* type, int index = -1);
  85. private:
  86. OwnedArray<DocumentType> types;
  87. OwnedArray<Document> documents;
  88. Array<DocumentCloseListener*> listeners;
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenDocumentManager)
  90. };
  91. //==============================================================================
  92. class RecentDocumentList : private OpenDocumentManager::DocumentCloseListener
  93. {
  94. public:
  95. RecentDocumentList();
  96. ~RecentDocumentList();
  97. void clear();
  98. void newDocumentOpened (OpenDocumentManager::Document* document);
  99. OpenDocumentManager::Document* getCurrentDocument() const { return previousDocs.getLast(); }
  100. bool canGoToPrevious() const;
  101. bool canGoToNext() const;
  102. bool contains (const File&) const;
  103. OpenDocumentManager::Document* getPrevious();
  104. OpenDocumentManager::Document* getNext();
  105. OpenDocumentManager::Document* getClosestPreviousDocOtherThan (OpenDocumentManager::Document* oneToAvoid) const;
  106. void restoreFromXML (Project& project, const XmlElement& xml);
  107. std::unique_ptr<XmlElement> createXML() const;
  108. private:
  109. bool documentAboutToClose (OpenDocumentManager::Document*);
  110. Array<OpenDocumentManager::Document*> previousDocs, nextDocs;
  111. };