Nameless Engine
Loading...
Searching...
No Matches
ne::FileDialog Class Reference

#include <FileDialog.h>

Static Public Member Functions

static std::vector< std::filesystem::path > openFile (const std::string &sTitle, const std::vector< std::pair< std::string, std::string > > &vFileTypeFilters={{"All Files", {"*"}}}, const std::filesystem::path &directory=std::filesystem::current_path(), bool bAllowSelectingMultipleFiles=false)
 
static std::optional< std::filesystem::path > saveFile (const std::string &sTitle, const std::pair< std::string, std::string > &fileType={"All Files", {"*"}}, const std::filesystem::path &directory=std::filesystem::current_path())
 
static std::optional< std::filesystem::path > selectDirectory (const std::string &sTitle, const std::filesystem::path &directory=std::filesystem::current_path())
 

Detailed Description

Various file dialog windows: open file, save file, select directory and etc.

Member Function Documentation

◆ openFile()

std::vector< std::filesystem::path > ne::FileDialog::openFile ( const std::string &  sTitle,
const std::vector< std::pair< std::string, std::string > > &  vFileTypeFilters = {{"All Files", {"*"}}},
const std::filesystem::path &  directory = std::filesystem::current_path(),
bool  bAllowSelectingMultipleFiles = false 
)
static

Shows "Open File" dialog window to allow the user to select file(s).

Example:

const auto vSelected = ne::FileDialog::openFile(
"Select audio and image files",
{
{"Audio Files", "*.mp3 *.wav *.flac *.ogg"},
{"Image Files", "*.png *.jpg *.jpeg *.bmp"}
},
std::filesystem::current_path(),
true);
static std::vector< std::filesystem::path > openFile(const std::string &sTitle, const std::vector< std::pair< std::string, std::string > > &vFileTypeFilters={{"All Files", {"*"}}}, const std::filesystem::path &directory=std::filesystem::current_path(), bool bAllowSelectingMultipleFiles=false)
Definition: FileDialog.cpp:16
Parameters
sTitleTitle of the dialog window.
vFileTypeFiltersFilter that determines which types of files can be selected. Each pair contains filter name and space separated types.
directoryStarting directory to show.
bAllowSelectingMultipleFilesWhether to allow selecting multiple files or not.
Returns
Array of selected files (if bAllowSelectingMultipleFiles is 'true'), one selected file (if bAllowSelectingMultipleFiles is 'false') and empty array if the used clicked "Cancel".

◆ saveFile()

std::optional< std::filesystem::path > ne::FileDialog::saveFile ( const std::string &  sTitle,
const std::pair< std::string, std::string > &  fileType = {"All Files", {"*"}},
const std::filesystem::path &  directory = std::filesystem::current_path() 
)
static

Shows "Save File" dialog window to ask the user where to save a file.

Example:

// 3 versions that provide equal result:
const auto optional = ne::FileDialog::saveFile("Save Configuration", {"Configuration", "*.toml"});
const auto optional = ne::FileDialog::saveFile("Save Configuration", {"Configuration", ".toml"});
const auto optional = ne::FileDialog::saveFile("Save Configuration", {"Configuration", "toml"});
// Possible result on Windows when the user saves a file with the name "123":
"D:\Downloads\123.toml".
static std::optional< std::filesystem::path > saveFile(const std::string &sTitle, const std::pair< std::string, std::string > &fileType={"All Files", {"*"}}, const std::filesystem::path &directory=std::filesystem::current_path())
Definition: FileDialog.cpp:43
Parameters
sTitleTitle of the dialog window.
fileTypeA pair of "Name of the file type" and "file extension".
directoryStarting directory to show.
Returns
Empty if the user clicked "Cancel", otherwise path to the file to save (with added extension if the file type was specified).

◆ selectDirectory()

std::optional< std::filesystem::path > ne::FileDialog::selectDirectory ( const std::string &  sTitle,
const std::filesystem::path &  directory = std::filesystem::current_path() 
)
static

Shows "Select Directory" dialog window to ask the user to select a directory.

Parameters
sTitleTitle of the dialog window.
directoryStarting directory to show.
Returns
Empty if the user clicked "Cancel", otherwise path to the selected directory.

The documentation for this class was generated from the following files: