From 490c05ffd4a8e9bb64e1ad4276e846feed07b2bf Mon Sep 17 00:00:00 2001 From: Areloch Date: Mon, 29 Jan 2018 22:16:42 -0600 Subject: [PATCH] Adds the ability to force the path returned by the file dialog to be relative. --- .../platform/nativeDialogs/fileDialog.cpp | 17 ++++++++++++++--- .../source/platform/nativeDialogs/fileDialog.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Engine/source/platform/nativeDialogs/fileDialog.cpp b/Engine/source/platform/nativeDialogs/fileDialog.cpp index 34e57e3e6..ad8bdfafb 100644 --- a/Engine/source/platform/nativeDialogs/fileDialog.cpp +++ b/Engine/source/platform/nativeDialogs/fileDialog.cpp @@ -122,6 +122,7 @@ FileDialog::FileDialog() : mData() // Default to File Must Exist Open Dialog style mData.mStyle = FileDialogData::FDS_OPEN | FileDialogData::FDS_MUSTEXIST; mChangePath = false; + mForceRelativePath = true; } FileDialog::~FileDialog() @@ -151,6 +152,8 @@ void FileDialog::initPersistFields() addProtectedField("changePath", TypeBool, Offset(mChangePath, FileDialog), &setChangePath, &getChangePath, "True/False whether to set the working directory to the directory returned by the dialog."); + addField("forceRelativePath", TypeBool, Offset(mForceRelativePath, FileDialog), "True/False whether to the path returned is always made to be relative."); + Parent::initPersistFields(); } @@ -267,7 +270,8 @@ bool FileDialog::Execute() } String resultPath = String(outPath).replace(rootDir, String("")); - resultPath = resultPath.replace(0, 1, String("")).c_str(); //kill '\\' prefix + if(resultPath[0] == '\\') + resultPath = resultPath.replace(0, 1, String("")).c_str(); //kill '\\' prefix resultPath = resultPath.replace(String("\\"), String("/")); // Did we select a file? @@ -280,7 +284,10 @@ bool FileDialog::Execute() if (mData.mStyle & FileDialogData::FDS_OPEN || mData.mStyle & FileDialogData::FDS_SAVE) { // Single file selection, do it the easy way - mData.mFile = Platform::makeRelativePathName(resultPath.c_str(), NULL); + if(mForceRelativePath) + mData.mFile = Platform::makeRelativePathName(resultPath.c_str(), NULL); + else + mData.mFile = resultPath.c_str(); } else if (mData.mStyle & FileDialogData::FDS_MULTIPLEFILES) { @@ -300,7 +307,11 @@ bool FileDialog::Execute() else { //nope, just one file, so set it as normal - setDataField(StringTable->insert("files"), "0", Platform::makeRelativePathName(resultPath.c_str(), NULL)); + if (mForceRelativePath) + setDataField(StringTable->insert("files"), "0", Platform::makeRelativePathName(resultPath.c_str(), NULL)); + else + setDataField(StringTable->insert("files"), "0", resultPath.c_str()); + setDataField(StringTable->insert("fileCount"), NULL, "1"); } } diff --git a/Engine/source/platform/nativeDialogs/fileDialog.h b/Engine/source/platform/nativeDialogs/fileDialog.h index b5b4ed618..7c08b51ae 100644 --- a/Engine/source/platform/nativeDialogs/fileDialog.h +++ b/Engine/source/platform/nativeDialogs/fileDialog.h @@ -106,6 +106,7 @@ protected: FileDialogData mData; ///< Stores platform agnostic information about the dialogs properties bool mChangePath; ///< Exposed ChangePath Property bool mBoolTranslator; ///< Internally used to translate boolean values into their respective bits of dialog style + bool mForceRelativePath; public: FileDialog();