Implemented "Open recent Project" menu entry

+ Clean up handle -> asset map when chaning Asset or Resource directory
This commit is contained in:
Simon Lübeß
2023-08-21 14:11:51 +02:00
parent 3affb8a32f
commit 0165279220
4 changed files with 90 additions and 4 deletions
+2 -2
View File
@@ -28,7 +28,7 @@ class AssetFile
private String _path; private String _path;
private String _identifier; private String _identifier;
private String _assetConfigPath; private String _assetConfigPath ~ delete _;
private AssetConfig _assetConfig ~ delete _; private AssetConfig _assetConfig ~ delete _;
@@ -53,7 +53,7 @@ class AssetFile
{ {
String identifierBuffer = append String(identifier); String identifierBuffer = append String(identifier);
String pathBuffer = append String(path); String pathBuffer = append String(path);
String configPathBuffer = append String(path.Length + ConfigFileExtension.Length); String configPathBuffer = new String(path.Length + ConfigFileExtension.Length);
_identifier = identifierBuffer; _identifier = identifierBuffer;
_path = pathBuffer; _path = pathBuffer;
@@ -250,6 +250,10 @@ class AssetHierarchy
_resourcesDirectoryNode?.ForEach(scope (node) => { _resourcesDirectoryNode?.ForEach(scope (node) => {
_pathToAssetNode.Remove(node->Path); _pathToAssetNode.Remove(node->Path);
_identifierToAssetNode.Remove(node->Identifier); _identifierToAssetNode.Remove(node->Identifier);
let handle = node->AssetFile?.AssetConfig?.AssetHandle;
if (handle != null)
_handleToAssetNode.Remove(handle.Value);
}); });
_assetRootNode.RemoveChild(_resourcesDirectoryNode); _assetRootNode.RemoveChild(_resourcesDirectoryNode);
DeleteTreeAndChildren!(_resourcesDirectoryNode); DeleteTreeAndChildren!(_resourcesDirectoryNode);
@@ -283,11 +287,18 @@ class AssetHierarchy
/// Sets path to the directory that contains the game assets. /// Sets path to the directory that contains the game assets.
public void SetAssetsDirectory(StringView fileName) public void SetAssetsDirectory(StringView fileName)
{ {
if (AssetsDirectory == fileName)
return;
AssetsDirectory = fileName; AssetsDirectory = fileName;
_assetsDirectoryNode?.ForEach(scope (node) => { _assetsDirectoryNode?.ForEach(scope (node) => {
_pathToAssetNode.Remove(node->Path); _pathToAssetNode.Remove(node->Path);
_identifierToAssetNode.Remove(node->Identifier); _identifierToAssetNode.Remove(node->Identifier);
let handle = node->AssetFile?.AssetConfig?.AssetHandle;
if (handle != null)
_handleToAssetNode.Remove(handle.Value);
}); });
_assetRootNode.RemoveChild(_assetsDirectoryNode); _assetRootNode.RemoveChild(_assetsDirectoryNode);
DeleteTreeAndChildren!(_assetsDirectoryNode); DeleteTreeAndChildren!(_assetsDirectoryNode);
+33
View File
@@ -705,6 +705,12 @@ namespace GlitchyEditor
UpdateWindowTitle(); UpdateWindowTitle();
if (Directory.Exists(project.WorkspacePath))
{
Application.Instance.Settings.EditorSettings.LastOpenedProject = project.WorkspacePath;
Application.Instance.Settings.Save();
}
return .Ok; return .Ok;
} }
@@ -1174,6 +1180,32 @@ namespace GlitchyEditor
} }
} }
private void ShowOpenRecentProjectMenu()
{
let recentProjects = Application.Instance.Settings.EditorSettings.RecentProjects;
if (recentProjects == null)
return;
int i = 0;
for (let workspacePath in recentProjects)
{
i++;
if (!Directory.Exists(workspacePath))
{
delete workspacePath;
@workspacePath.Remove();
}
if (ImGui.MenuItem(scope $"{i}: {workspacePath}"))
{
LoadAndOpenProject(workspacePath);
}
}
}
private void DrawMainMenuBar() private void DrawMainMenuBar()
{ {
ImGui.BeginMainMenuBar(); ImGui.BeginMainMenuBar();
@@ -1219,6 +1251,7 @@ namespace GlitchyEditor
if (ImGui.BeginMenu("Open recent project")) if (ImGui.BeginMenu("Open recent project"))
{ {
ShowOpenRecentProjectMenu();
ImGui.EndMenu(); ImGui.EndMenu();
} }
+44 -2
View File
@@ -38,8 +38,50 @@ class EditorSettings
[Setting("Editor", "Switch to Editor on pause", "If checked the editor will automatically switch to the \"Editor\" window when the game is being paused."), BonInclude] [Setting("Editor", "Switch to Editor on pause", "If checked the editor will automatically switch to the \"Editor\" window when the game is being paused."), BonInclude]
public bool SwitchToEditorOnPause = false; public bool SwitchToEditorOnPause = false;
// [BonInclude]
//public readonly List<String> RecentProjects = new .() ~ delete _; private List<String> _recentProjects ~ DeleteContainerAndItems!(_);
/// Gets or sets the path of the Project that was last open.
public StringView LastOpenedProject
{
get
{
if (_recentProjects == null || _recentProjects.Count == 0)
return "";
return _recentProjects[0];
}
set
{
if (_recentProjects == null)
_recentProjects = new List<String>();
// Remove duplicates
for (var entry in _recentProjects)
{
if (entry == value)
{
delete entry;
@entry.Remove();
}
}
_recentProjects.Insert(0, new String(value));
if (_recentProjects.Count > 10)
{
// We only store 10 entries, delete the rest
for (int i = 10; i < _recentProjects.Count; i++)
{
delete _recentProjects[i];
}
_recentProjects.Count = 10;
}
}
}
public List<String> RecentProjects => _recentProjects;
public void Apply() public void Apply()
{ {