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) 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. 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. };