From 11f41a4467e4d1daf64a4c72209c26f3e5a2d7ba Mon Sep 17 00:00:00 2001 From: Steve Pham <82231385+spham-amzn@users.noreply.github.com> Date: Fri, 19 Nov 2021 08:22:53 -0800 Subject: [PATCH] Fix UI canvas save as start folder (#5756) Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com> --- Gems/LyShine/Code/Editor/EditorWindow.cpp | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Gems/LyShine/Code/Editor/EditorWindow.cpp b/Gems/LyShine/Code/Editor/EditorWindow.cpp index a4ad4d7043..7b60474ed5 100644 --- a/Gems/LyShine/Code/Editor/EditorWindow.cpp +++ b/Gems/LyShine/Code/Editor/EditorWindow.cpp @@ -8,6 +8,7 @@ #include "EditorCommon.h" #include "CanvasHelpers.h" #include "AssetDropHelpers.h" +#include #include #include #include @@ -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(dirPath.Native().size())); + QString filename = AzQtComponents::FileDialog::GetSaveFileName(nullptr, QString(), dir,