MeshLib Documentation
Loading...
Searching...
No Matches
MRFileDialog.h
Go to the documentation of this file.
1#pragma once
2#include "exports.h"
4#include "MRMesh/MRSignal.h"
5#include <filesystem>
6#include <functional>
7
8namespace MR
9{
10
12struct MRVIEWER_CLASS FileDialogSignals
13{
14public:
15 using SelectFileSignal = Signal<void( const std::filesystem::path& path )>;
16 using SelectFilesSignal = Signal<void( const std::vector<std::filesystem::path>& )>;
19
21 MRVIEWER_API static FileDialogSignals& instance();
22
25
27
30
31private:
32 FileDialogSignals() = default;
33 ~FileDialogSignals() = default;
34};
35
36
38{
39 // Default filename
40 std::string fileName;
41 // Dialog will open this folder for browsing, default: last used folder
42 // this parameter is not used in emscripten build
43 std::filesystem::path baseFolder{};
45};
46
47// Allow user to select only one file
48// returns empty path on cancel
49MRVIEWER_API std::filesystem::path openFileDialog( const FileParameters& params = {} );
50
51// Unified function to open file in desktop code and in emscripten
52// callback is called inside this function in desktop build and deferred in emscripten build
53MRVIEWER_API void openFileDialogAsync( std::function<void( const std::filesystem::path& )> callback, const FileParameters& params = {} );
54
55// Allow user to select several files
56// returns empty vector on cancel
57MRVIEWER_API std::vector<std::filesystem::path> openFilesDialog( const FileParameters& params = {} );
58
59// Unified function to open files in desktop code and in emscripten
60// callback is called inside this function in desktop build and deferred in emscripten build
61MRVIEWER_API void openFilesDialogAsync( std::function<void( const std::vector<std::filesystem::path>& )> callback, const FileParameters& params = {} );
62
63// Select one folder
64// returns empty path on cancel
65MRVIEWER_API std::filesystem::path openFolderDialog( std::filesystem::path baseFolder = {} );
66
67// Unified function to select a folder in desktop code and in emscripten
68// callback is called inside this function in desktop build and deferred in emscripten build
69MRVIEWER_API void openFolderDialogAsync( std::function<void ( const std::filesystem::path& )> callback, std::filesystem::path baseFolder = {} );
70
71// Allow user to select several folders
72// returns empty path on cancel
73MRVIEWER_API std::vector<std::filesystem::path> openFoldersDialog( std::filesystem::path baseFolder = {} );
74
75// returns empty path on cancel
76MRVIEWER_API std::filesystem::path saveFileDialog( const FileParameters& params = {} );
77
78// Unified function to save file in desktop code and in emscripten
79// callback is called inside this function in desktop build and deferred in emscripten build
80MRVIEWER_API void saveFileDialogAsync( std::function<void( const std::filesystem::path& )> callback, const FileParameters& params = {} );
81
82}
std::vector< IOFilter > IOFilters
Definition MRIOFilters.h:32
Definition MRCameraOrientationPlugin.h:8
MRVIEWER_API std::filesystem::path openFileDialog(const FileParameters &params={})
MRVIEWER_API std::vector< std::filesystem::path > openFoldersDialog(std::filesystem::path baseFolder={})
MRVIEWER_API void openFilesDialogAsync(std::function< void(const std::vector< std::filesystem::path > &)> callback, const FileParameters &params={})
MRVIEWER_API std::filesystem::path saveFileDialog(const FileParameters &params={})
MRVIEWER_API void openFileDialogAsync(std::function< void(const std::filesystem::path &)> callback, const FileParameters &params={})
MRVIEWER_API std::filesystem::path openFolderDialog(std::filesystem::path baseFolder={})
MRVIEWER_API void openFolderDialogAsync(std::function< void(const std::filesystem::path &)> callback, std::filesystem::path baseFolder={})
MRVIEWER_API std::vector< std::filesystem::path > openFilesDialog(const FileParameters &params={})
MRVIEWER_API void saveFileDialogAsync(std::function< void(const std::filesystem::path &)> callback, const FileParameters &params={})
This structure contains global signals for file dialogs, that are called on valid selection of file o...
Definition MRFileDialog.h:13
SelectFileSignal onOpenFile
called when one file is selected for opening (openFileDialog and openFileDialogAsync)
Definition MRFileDialog.h:23
static MRVIEWER_API FileDialogSignals & instance()
returns instance of this holder
SelectFilesSignal onOpenFiles
called when several files are selected for opening (openFilesDialog and openFilesDialogAsync)
Definition MRFileDialog.h:24
SelectFileSignal onSaveFile
called when file name is selected for saving (saveFileDialog and saveFileDialogAsync)
Definition MRFileDialog.h:26
SelectFolderSignal onSelectFolder
called when one folder is selected (we do not now differ reason)(openFolderDialog and openFolderDialo...
Definition MRFileDialog.h:28
SelectFoldersSignal onSelectFolders
called when several folders are selected (we do not now differ reason)(openFoldersDialog)
Definition MRFileDialog.h:29
Definition MRFileDialog.h:38
std::string fileName
Definition MRFileDialog.h:40
std::filesystem::path baseFolder
Definition MRFileDialog.h:43
IOFilters filters
Definition MRFileDialog.h:44