Plasma Engine  2.0
Loading...
Searching...
No Matches
ToolsProject.h
1#pragma once
2
3#include <Foundation/Communication/Event.h>
4#include <Foundation/Configuration/Singleton.h>
5#include <Foundation/Types/Status.h>
6#include <Foundation/Types/Uuid.h>
7#include <ToolsFoundation/ToolsFoundationDLL.h>
8
10class plDocument;
11
13{
14 enum class Type
15 {
16 ProjectCreated,
17 ProjectOpened,
18 ProjectSaveState,
19 ProjectClosing,
20 ProjectClosed,
23 SaveAll,
24 };
25
26 plToolsProject* m_pProject;
27 Type m_Type;
28};
29
31{
33
34 enum class Type
35 {
40 GetPathForDocumentGuid,
41 };
42
43 Type m_Type;
46 plInt32
48
49 plUuid m_documentGuid;
50 plStringBuilder m_sAbsDocumentPath;
51};
52
53class PL_TOOLSFOUNDATION_DLL plToolsProject
54{
55 PL_DECLARE_SINGLETON(plToolsProject);
56
57public:
59 static plEvent<plToolsProjectRequest&> s_Requests;
60
61public:
62 static bool IsProjectOpen() { return GetSingleton() != nullptr; }
63 static bool IsProjectClosing() { return (GetSingleton() != nullptr && GetSingleton()->m_bIsClosing); }
64 static void CloseProject();
65 static void SaveProjectState();
67 static bool CanCloseProject();
69 static bool CanCloseDocuments(plArrayPtr<plDocument*> documents);
72 static plInt32 SuggestContainerWindow(plDocument* pDoc);
74 plStringBuilder GetPathForDocumentGuid(const plUuid& guid);
75 static plStatus OpenProject(plStringView sProjectPath);
76 static plStatus CreateProject(plStringView sProjectPath);
77
79 static void BroadcastSaveAll();
80
83 static void BroadcastConfigChanged();
84
86 const plString& GetProjectFile() const { return m_sProjectPath; }
87
91 const plString GetProjectName(bool bSanitize) const;
92
94 plString GetProjectDirectory() const;
95
97 plString GetProjectDataFolder() const;
98
100 static plString FindProjectDirectoryForDocument(plStringView sDocumentPath);
101
102 bool IsDocumentInAllowedRoot(plStringView sDocumentPath, plString* out_pRelativePath = nullptr) const;
103
104 void AddAllowedDocumentRoot(plStringView sPath);
105
107 void CreateSubFolder(plStringView sFolder) const;
108
109private:
110 static plStatus CreateOrOpenProject(plStringView sProjectPath, bool bCreate);
111
112private:
113 plToolsProject(plStringView sProjectPath);
115
116 plStatus Create();
117 plStatus Open();
118
119private:
120 bool m_bIsClosing;
121 plString m_sProjectPath;
122 plHybridArray<plString, 4> m_AllowedDocumentRoots;
123};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition Document.h:57
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
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Definition ToolsProject.h:54
const plString & GetProjectFile() const
Returns the path to the 'plProject' file.
Definition ToolsProject.h:86
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
An plResult with an additional message for the reason of failure.
Definition Status.h:12
Definition ToolsProject.h:13
Type
Definition ToolsProject.h:15
@ SaveAll
When sent, this shall save all outstanding modifications.
Definition ToolsProject.h:31
plInt32 m_iContainerWindowUniqueIdentifier
In case of 'SuggestContainerWindow', the ID of the container to be used for the docs in m_Documents.
Definition ToolsProject.h:47
plDynamicArray< plDocument * > m_Documents
In case of 'CanCloseDocuments', these will be the documents in question.
Definition ToolsProject.h:45
bool m_bCanClose
When the event is sent, interested code can set this to false to prevent closing.
Definition ToolsProject.h:44
Type
Definition ToolsProject.h:35
@ CanCloseDocuments
Can we close the documents in m_Documents? Listener needs to set m_bCanClose if not.
@ CanCloseProject
Can we close the project? Listener needs to set m_bCanClose if not.