Plasma Engine  2.0
Loading...
Searching...
No Matches
Preferences.h
1#pragma once
2
3#include <EditorFramework/EditorFrameworkDLL.h>
4#include <Foundation/Reflection/Reflection.h>
5
6class plDocument;
7
16class PL_EDITORFRAMEWORK_DLL plPreferences : public plReflectedClass
17{
18 PL_ADD_DYNAMIC_REFLECTION(plPreferences, plReflectedClass);
19
20public:
21 enum class Domain
22 {
23 Application,
24 Project,
25 Document
26 };
27
30 template <typename TYPE>
31 static TYPE* QueryPreferences(const plDocument* pDocument = nullptr)
32 {
33 static_assert((std::is_base_of<plPreferences, TYPE>::value == true), "All preferences objects must be derived from plPreferences");
34 return static_cast<TYPE*>(QueryPreferences(plGetStaticRTTI<TYPE>(), pDocument));
35 }
36
39 static plPreferences* QueryPreferences(const plRTTI* pRtti, const plDocument* pDocument = nullptr);
40
42 static void SaveDocumentPreferences(const plDocument* pDocument);
43
46 static void ClearDocumentPreferences(const plDocument* pDocument);
47
49 static void SaveProjectPreferences();
50
53 static void ClearProjectPreferences();
54
56 static void SaveApplicationPreferences();
57
60 static void ClearApplicationPreferences();
61
63 static void GatherAllPreferences(plHybridArray<plPreferences*, 16>& out_allPreferences);
64
66 Domain GetDomain() const { return m_Domain; }
67
69 plString GetName() const;
70
72 const plDocument* GetDocumentAssociation() const { return m_pDocument; }
73
76
78 void TriggerPreferencesChangedEvent() { m_ChangedEvent.Broadcast(this); }
79
80protected:
81 plPreferences(Domain domain, const char* szUniqueName);
82
83 plString GetFilePath() const;
84
85private:
86 static void SavePreferences(const plDocument* pDocument, Domain domain);
87 static void ClearPreferences(const plDocument* pDocument, Domain domain);
88
89 void Load();
90 void Save() const;
91
92
93
94private:
95 Domain m_Domain;
96 plString m_sUniqueName;
97 const plDocument* m_pDocument;
98
100};
Definition Document.h:57
void Broadcast(EventData pEventData, plUInt8 uiMaxRecursionDepth=MaxRecursionDepthDefault)
This function will broadcast to all registered users, that this event has just happened....
Definition Event_inl.h:187
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
Base class for all preferences.
Definition Preferences.h:17
plEvent< plPreferences * > m_ChangedEvent
A simple event that can be fired when any preference property changes. No specific change details are...
Definition Preferences.h:75
void TriggerPreferencesChangedEvent()
Call this to broadcast that this preference object was modified.
Definition Preferences.h:78
static TYPE * QueryPreferences(const plDocument *pDocument=nullptr)
Static function to query a preferences object of the given type. If the instance does not exist yet,...
Definition Preferences.h:31
const plDocument * GetDocumentAssociation() const
If these preferences are per document, the pointer is valid, otherwise nullptr.
Definition Preferences.h:72
Domain GetDomain() const
Whether the preferences are app, project or document specific.
Definition Preferences.h:66
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86