Fix UI canvas save as start folder (#5756)

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>
This commit is contained in:
Steve Pham
2021-11-19 08:22:53 -08:00
committed by GitHub
parent 1f0ac46d68
commit 11f41a4467
+24 -2
View File
@@ -8,6 +8,7 @@
#include "EditorCommon.h"
#include "CanvasHelpers.h"
#include "AssetDropHelpers.h"
#include <AzCore/IO/Path/Path.h>
#include <AzCore/IO/SystemFile.h>
#include <AzCore/std/sort.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
@@ -697,15 +698,36 @@ bool EditorWindow::SaveCanvasToXml(UiCanvasMetadata& canvasMetadata, bool forceA
else if (recentFiles.size() > 0)
{
dir = Path::GetPath(recentFiles.front());
dir.append(canvasMetadata.m_canvasDisplayName.c_str());
}
// Else go to the default canvas directory
else
{
dir = FileHelpers::GetAbsoluteDir(UICANVASEDITOR_CANVAS_DIRECTORY);
dir.append(canvasMetadata.m_canvasDisplayName.c_str());
}
// Make sure the directory exists. If not, walk up the directory path until we find one that does
// so that we will have a consistent 'starting folder' in the 'AzQtComponents::FileDialog::GetSaveFileName' call
// across different platforms.
AZ::IO::FixedMaxPath dirPath(dir.toUtf8().constData());
while (!AZ::IO::SystemFile::IsDirectory(dirPath.c_str()))
{
AZ::IO::PathView parentPath = dirPath.ParentPath();
if (parentPath == dirPath)
{
// We've reach the root path, need to break out whether or not
// the root path exists
break;
}
else
{
dirPath = parentPath;
}
}
// Append the default filename
dirPath /= canvasMetadata.m_canvasDisplayName;
dir = QString::fromUtf8(dirPath.c_str(), static_cast<int>(dirPath.Native().size()));
QString filename = AzQtComponents::FileDialog::GetSaveFileName(nullptr,
QString(),
dir,