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

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_OPENDOCUMENTMANAGER_JUCEHEADER__
  19. #define __JUCER_OPENDOCUMENTMANAGER_JUCEHEADER__
  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 File::nonexistent; }
  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. virtual void documentAboutToClose (Document* document) = 0;
  79. };
  80. void addListener (DocumentCloseListener* listener);
  81. void removeListener (DocumentCloseListener* listener);
  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. void documentAboutToClose (OpenDocumentManager::Document*);
  116. Array <OpenDocumentManager::Document*> previousDocs, nextDocs;
  117. };
  118. #endif // __JUCER_OPENDOCUMENTMANAGER_JUCEHEADER__