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.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef __JUCER_OPENDOCUMENTMANAGER_JUCEHEADER__
  18. #define __JUCER_OPENDOCUMENTMANAGER_JUCEHEADER__
  19. #include "../Project/jucer_Project.h"
  20. //==============================================================================
  21. /**
  22. */
  23. class OpenDocumentManager
  24. {
  25. public:
  26. //==============================================================================
  27. OpenDocumentManager();
  28. ~OpenDocumentManager();
  29. //==============================================================================
  30. class Document
  31. {
  32. public:
  33. Document() {}
  34. virtual ~Document() {}
  35. virtual bool loadedOk() const = 0;
  36. virtual bool isForFile (const File& file) const = 0;
  37. virtual bool isForNode (const ValueTree& node) const = 0;
  38. virtual bool refersToProject (Project& project) const = 0;
  39. virtual Project* getProject() const = 0;
  40. virtual String getName() const = 0;
  41. virtual String getType() const = 0;
  42. virtual File getFile() const = 0;
  43. virtual bool needsSaving() const = 0;
  44. virtual bool save() = 0;
  45. virtual bool saveAs() = 0;
  46. virtual bool hasFileBeenModifiedExternally() = 0;
  47. virtual void reloadFromFile() = 0;
  48. virtual Component* createEditor() = 0;
  49. virtual Component* createViewer() = 0;
  50. virtual void fileHasBeenRenamed (const File& newFile) = 0;
  51. virtual String getState() const = 0;
  52. virtual void restoreState (const String& state) = 0;
  53. virtual File getCounterpartFile() const { return File::nonexistent; }
  54. };
  55. //==============================================================================
  56. int getNumOpenDocuments() const;
  57. Document* getOpenDocument (int index) const;
  58. void clear();
  59. bool canOpenFile (const File& file);
  60. Document* openFile (Project* project, const File& file);
  61. bool closeDocument (int index, bool saveIfNeeded);
  62. bool closeDocument (Document* document, bool saveIfNeeded);
  63. bool closeAll (bool askUserToSave);
  64. bool closeAllDocumentsUsingProject (Project& project, bool saveIfNeeded);
  65. void closeFile (const File& f, bool saveIfNeeded);
  66. bool anyFilesNeedSaving() const;
  67. bool saveAll();
  68. FileBasedDocument::SaveResult saveIfNeededAndUserAgrees (Document* doc);
  69. void reloadModifiedFiles();
  70. void fileHasBeenRenamed (const File& oldFile, const File& newFile);
  71. //==============================================================================
  72. class DocumentCloseListener
  73. {
  74. public:
  75. DocumentCloseListener() {}
  76. virtual ~DocumentCloseListener() {}
  77. // return false to force it to stop.
  78. virtual bool documentAboutToClose (Document* document) = 0;
  79. };
  80. void addListener (DocumentCloseListener*);
  81. void removeListener (DocumentCloseListener*);
  82. //==============================================================================
  83. class DocumentType
  84. {
  85. public:
  86. DocumentType() {}
  87. virtual ~DocumentType() {}
  88. virtual bool canOpenFile (const File& file) = 0;
  89. virtual Document* openFile (Project* project, const File& file) = 0;
  90. };
  91. void registerType (DocumentType* type);
  92. private:
  93. OwnedArray<DocumentType> types;
  94. OwnedArray<Document> documents;
  95. Array<DocumentCloseListener*> listeners;
  96. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenDocumentManager)
  97. };
  98. //==============================================================================
  99. class RecentDocumentList : private OpenDocumentManager::DocumentCloseListener
  100. {
  101. public:
  102. RecentDocumentList();
  103. ~RecentDocumentList();
  104. void clear();
  105. void newDocumentOpened (OpenDocumentManager::Document* document);
  106. OpenDocumentManager::Document* getCurrentDocument() const { return previousDocs.getLast(); }
  107. bool canGoToPrevious() const;
  108. bool canGoToNext() 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. };
  118. #endif // __JUCER_OPENDOCUMENTMANAGER_JUCEHEADER__