Use last opened project as initial directory in project file dialog

This commit is contained in:
2025-12-17 03:03:41 +02:00
parent f97ee72f1c
commit 42fa0ffdd1

View File

@@ -526,6 +526,17 @@ int32 Editor::LoadProduct()
return 12;
}
// Get the last opened project path
String localCachePath;
FileSystem::GetSpecialFolderPath(SpecialFolder::AppData, localCachePath);
String editorConfigPath = localCachePath / TEXT("Flax");
String lastProjectSettingPath = editorConfigPath / TEXT("LastProject.txt");
if (!FileSystem::DirectoryExists(editorConfigPath))
FileSystem::CreateDirectory(editorConfigPath);
String lastProjectPath;
if (FileSystem::FileExists(lastProjectSettingPath))
File::ReadAllText(lastProjectSettingPath, lastProjectPath);
// Missing project case
if (projectPath.IsEmpty())
{
@@ -541,7 +552,7 @@ int32 Editor::LoadProduct()
Array<String> files;
if (FileSystem::ShowOpenFileDialog(
nullptr,
StringView::Empty,
lastProjectPath,
TEXT("Project files (*.flaxproj)\0*.flaxproj\0All files (*.*)\0*.*\0"),
false,
TEXT("Select project to open in Editor"),
@@ -625,6 +636,10 @@ int32 Editor::LoadProduct()
}
}
// Update the last opened project path
if (lastProjectPath.Compare(Project->ProjectFolderPath) != 0)
File::WriteAllText(lastProjectSettingPath, Project->ProjectFolderPath, Encoding::UTF8);
return 0;
}