Plasma Engine  2.0
Loading...
Searching...
No Matches
DocumentManager.h
1#pragma once
2
3#include <Foundation/Types/Status.h>
4#include <ToolsFoundation/Document/Document.h>
5#include <ToolsFoundation/ToolsFoundationDLL.h>
6
7class PL_TOOLSFOUNDATION_DLL plDocumentManager : public plReflectedClass
8{
9 PL_ADD_DYNAMIC_REFLECTION(plDocumentManager, plReflectedClass);
10
11public:
12 virtual ~plDocumentManager() = default;
13
14 static const plHybridArray<plDocumentManager*, 16>& GetAllDocumentManagers() { return s_AllDocumentManagers; }
15
16 static plResult FindDocumentTypeFromPath(plStringView sPath, bool bForCreation, const plDocumentTypeDescriptor*& out_pTypeDesc);
17
18 plStatus CanOpenDocument(plStringView sFilePath) const;
19
27 plStatus CreateDocument(
28 plStringView sDocumentTypeName, plStringView sPath, plDocument*& out_pDocument, plBitflags<plDocumentFlags> flags = plDocumentFlags::None, const plDocumentObject* pOpenContext = nullptr);
29
38 plStatus OpenDocument(plStringView sDocumentTypeName, plStringView sPath, plDocument*& out_pDocument,
40 const plDocumentObject* pOpenContext = nullptr);
41 virtual plStatus CloneDocument(plStringView sPath, plStringView sClonePath, plUuid& inout_cloneGuid);
42 void CloseDocument(plDocument* pDocument);
43 void EnsureWindowRequested(plDocument* pDocument, const plDocumentObject* pOpenContext = nullptr);
44
46 const plDynamicArray<plDocument*>& GetAllOpenDocuments() const { return m_AllOpenDocuments; }
47
48 plDocument* GetDocumentByPath(plStringView sPath) const;
49
50 static plDocument* GetDocumentByGuid(const plUuid& guid);
51
54 static bool EnsureDocumentIsClosedInAllManagers(plStringView sPath);
55
59 bool EnsureDocumentIsClosed(plStringView sPath);
60
61 void CloseAllDocumentsOfManager();
62 static void CloseAllDocuments();
63
64 struct Event
65 {
66 enum class Type
67 {
68 DocumentTypesRemoved,
69 DocumentTypesAdded,
70 DocumentOpened,
71 DocumentWindowRequested,
73 AfterDocumentWindowRequested,
74 DocumentClosing,
75 DocumentClosing2, // sent after DocumentClosing but before removing the document, use this to do stuff that depends on code executed during
76 // DocumentClosing
77 DocumentClosed, // this will not point to a valid document anymore, as the document is deleted, use DocumentClosing to get the event before it
78 // is deleted
79 };
80
81 Type m_Type;
82 plDocument* m_pDocument = nullptr;
83 const plDocumentObject* m_pOpenContext = nullptr;
84 };
85
86 struct Request
87 {
88 enum class Type
89 {
90 DocumentAllowedToOpen,
91 };
92
93 Type m_Type;
94 plString m_sDocumentType;
95 plString m_sDocumentPath;
96 plStatus m_RequestStatus;
97 };
98
100 static plEvent<Request&> s_Requests;
101
102 static const plDocumentTypeDescriptor* GetDescriptorForDocumentType(plStringView sDocumentType);
103 static const plMap<plString, const plDocumentTypeDescriptor*>& GetAllDocumentDescriptors();
104
105 void GetSupportedDocumentTypes(plDynamicArray<const plDocumentTypeDescriptor*>& inout_documentTypes) const;
106
107 using CustomAction = plVariant (*)(const plDocument*);
108 static plMap<plString, CustomAction> s_CustomActions;
109
110protected:
111 virtual void InternalCloneDocument(plStringView sPath, plStringView sClonePath, const plUuid& documentId, const plUuid& seedGuid, const plUuid& cloneGuid, plAbstractObjectGraph* pHeader, plAbstractObjectGraph* pObjects, plAbstractObjectGraph* pTypes);
112
113private:
114 virtual void InternalCreateDocument(plStringView sDocumentTypeName, plStringView sPath, bool bCreateNewDocument, plDocument*& out_pDocument, const plDocumentObject* pOpenContext) = 0;
115 virtual void InternalGetSupportedDocumentTypes(plDynamicArray<const plDocumentTypeDescriptor*>& inout_DocumentTypes) const = 0;
116
117private:
118 plStatus CreateOrOpenDocument(bool bCreate, plStringView sDocumentTypeName, plStringView sPath, plDocument*& out_pDocument,
119 plBitflags<plDocumentFlags> flags, const plDocumentObject* pOpenContext = nullptr);
120
121private:
122 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(ToolsFoundation, DocumentManager);
123
124 static void OnPluginEvent(const plPluginEvent& e);
125
126 static void UpdateBeforeUnloadingPlugins(const plPluginEvent& e);
127 static void UpdatedAfterLoadingPlugins();
128
129 plDynamicArray<plDocument*> m_AllOpenDocuments;
130
131 static plSet<const plRTTI*> s_KnownManagers;
132 static plHybridArray<plDocumentManager*, 16> s_AllDocumentManagers;
133
134 static plMap<plString, const plDocumentTypeDescriptor*> s_AllDocumentDescriptors;
135};
Definition AbstractObjectGraph.h:115
Definition Document.h:57
Definition DocumentManager.h:8
const plDynamicArray< plDocument * > & GetAllOpenDocuments() const
Returns a list of all currently open documents that are managed by this document manager.
Definition DocumentManager.h:46
Definition DocumentObjectBase.h:11
Definition DynamicArray.h:81
Definition Event.h:177
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Map.h:408
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
Definition Set.h:238
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
@ RequestWindow
Open the document visibly (not just internally)
Definition Declarations.h:15
@ AddToRecentFilesList
Add the document path to the recently used list for users.
Definition Declarations.h:16
Definition DocumentManager.h:65
Type
Definition DocumentManager.h:67
Definition DocumentManager.h:87
Definition Declarations.h:35
The data that is broadcast whenever a plugin is (un-) loaded.
Definition Plugin.h:11
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
An plResult with an additional message for the reason of failure.
Definition Status.h:12