Skip to content

Commit c98c50a

Browse files
authored
ofFileDialogResult using fs::path (#8119)
1 parent 7d2ca5b commit c98c50a

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

libs/openFrameworks/utils/ofFileUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ fs::path ofFilePath::getPathForDirectory(const fs::path & path){
17731773
// FIXME: - re-avail
17741774
string ofFilePath::removeTrailingSlash(const fs::path & _path){
17751775
auto path = ofPathToString(_path);
1776-
if(path.length() > 0 && (path[path.length() - 1] == '/' || path[path.length() - 1] == '\\')){
1776+
if(!path.empty() && (path[path.length() - 1] == '/' || path[path.length() - 1] == '\\')){
17771777
path = path.substr(0, path.length() - 1);
17781778
}
17791779
return path;

libs/openFrameworks/utils/ofSystemUtils.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,15 @@ void resetLocale(std::locale locale){
257257

258258
//------------------------------------------------------------------------------
259259
ofFileDialogResult::ofFileDialogResult(){
260-
filePath = "";
261-
fileName = "";
262-
bSuccess = false;
263260
}
264261

265262
//------------------------------------------------------------------------------
266-
std::string ofFileDialogResult::getName(){
263+
of::filesystem::path ofFileDialogResult::getName(){
267264
return fileName;
268265
}
269266

270267
//------------------------------------------------------------------------------
271-
std::string ofFileDialogResult::getPath(){
268+
of::filesystem::path ofFileDialogResult::getPath(){
272269
return filePath;
273270
}
274271

@@ -337,7 +334,7 @@ static int CALLBACK loadDialogBrowseCallback(
337334
//---------------------------------------------------------------------
338335

339336
// OS specific results here. "" = cancel or something bad like can't load, can't save, etc...
340-
ofFileDialogResult ofSystemLoadDialog(std::string windowTitle, bool bFolderSelection, std::string defaultPath){
337+
ofFileDialogResult ofSystemLoadDialog(std::string windowTitle, bool bFolderSelection, of::filesystem::path defaultPath){
341338

342339
ofFileDialogResult results;
343340

@@ -494,7 +491,7 @@ ofFileDialogResult ofSystemLoadDialog(std::string windowTitle, bool bFolderSelec
494491

495492

496493

497-
if( results.filePath.length() > 0 ){
494+
if( !results.filePath.empty() ){
498495
results.bSuccess = true;
499496
results.fileName = ofFilePath::getFileName(results.filePath);
500497
}
@@ -575,7 +572,7 @@ ofFileDialogResult ofSystemSaveDialog(std::string defaultName, std::string messa
575572
//----------------------------------------------------------------------------------------
576573
//----------------------------------------------------------------------------------------
577574

578-
if( results.filePath.length() > 0 ){
575+
if( !results.filePath.empty() ){
579576
results.bSuccess = true;
580577
results.fileName = ofFilePath::getFileName(results.filePath);
581578
}

libs/openFrameworks/utils/ofSystemUtils.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "ofConstants.h" // fs::path
34
#include <string>
45

56
/// \class ofFileDialogResult
@@ -10,14 +11,14 @@ class ofFileDialogResult{
1011

1112
/// \return the name of the selected file or directory, if set
1213
/// currently returns only 1 file, this may change in the future
13-
std::string getName();
14+
of::filesystem::path getName();
1415

1516
/// \return the full path of the selected file or directory, if set
16-
std::string getPath();
17+
of::filesystem::path getPath();
1718

18-
std::string filePath; ///< full path to selected file or directory
19-
std::string fileName; ///< selected file or directory name
20-
bool bSuccess; ///< true if the dialog action was successful, aka file select not cancel
19+
of::filesystem::path filePath { "" }; ///< full path to selected file or directory
20+
of::filesystem::path fileName { "" }; ///< selected file or directory name
21+
bool bSuccess = false; ///< true if the dialog action was successful, aka file select not cancel
2122
};
2223

2324
/// \brief show an error message in an alert dialog box
@@ -28,7 +29,7 @@ void ofSystemAlertDialog(std::string errorMessage);
2829
/// \param bFolderSelection set to true to allow folder selection
2930
/// \param defaultPath optional default directory path to start the dialog in, ie. ofFilePath::getUserHomeDir()
3031
/// \return dialog result with selection (if any)
31-
ofFileDialogResult ofSystemLoadDialog(std::string windowTitle="", bool bFolderSelection = false, std::string defaultPath="");
32+
ofFileDialogResult ofSystemLoadDialog(std::string windowTitle="", bool bFolderSelection = false, of::filesystem::path defaultPath="");
3233

3334
/// \brief show a file save dialog box
3435
/// \param defaultName suggested filename to start dialog, ie "screenshot.png"

0 commit comments

Comments
 (0)