Elevate Engine 1
Loading...
Searching...
No Matches
DesktopFileDialog.cpp
Go to the documentation of this file.
1#include "DesktopFileDialog.h"
2
3#ifndef EE_PLATFORM_WEB
4#include <tinyfiledialogs.h>
5
6namespace Elevate
7{
8 std::vector<const char*> DesktropFileDialog::ConvertFilters(const std::vector<std::string>& filters) const
9 {
10 std::vector<const char*> filterPtrs;
11 filterPtrs.reserve(filters.size());
12 for (const auto& f : filters)
13 {
14 filterPtrs.push_back(f.c_str());
15 }
16 return filterPtrs;
17 }
18
19 void DesktropFileDialog::OpenFile(const std::string& title, const std::string& defaultPathOrFile, const std::vector<std::string>& filters, const std::string& filterDescription, bool allowMultiple)
20 {
21 std::vector<const char*> filterPtrs = ConvertFilters(filters);
22
23 const char* result = tinyfd_openFileDialog(
24 title.empty() ? nullptr : title.c_str(),
25 defaultPathOrFile.empty() ? nullptr : defaultPathOrFile.c_str(),
26 static_cast<int>(filterPtrs.size()),
27 filterPtrs.empty() ? nullptr : filterPtrs.data(),
28 filterDescription.empty() ? nullptr : filterDescription.c_str(),
29 allowMultiple ? 1 : 0
30 );
31
32 if (result == nullptr)
33 {
34 result = "";
35 }
36 SetResult(std::string(result));
37 }
38
39 void DesktropFileDialog::SaveFile(const std::string& title, const std::string& defaultPathOrFile, const std::vector<std::string>& filters, const std::string& filterDescription)
40 {
41 std::vector<const char*> filterPtrs = ConvertFilters(filters);
42
43 const char* result = tinyfd_saveFileDialog(
44 title.empty() ? nullptr : title.c_str(),
45 defaultPathOrFile.empty() ? nullptr : defaultPathOrFile.c_str(),
46 static_cast<int>(filterPtrs.size()),
47 filterPtrs.empty() ? nullptr : filterPtrs.data(),
48 filterDescription.empty() ? nullptr : filterDescription.c_str()
49 );
50
51 if (result == nullptr)
52 {
53 result = "";
54 }
55 SetResult(std::string(result));
56 }
57
58 void DesktropFileDialog::SelectFolder(const std::string& title, const std::string& defaultPath)
59 {
60 const char* result = tinyfd_selectFolderDialog(
61 title.empty() ? nullptr : title.c_str(),
62 defaultPath.empty() ? nullptr : defaultPath.c_str()
63 );
64
65 if (result == nullptr)
66 {
67 result = "";
68 }
69 SetResult(std::string(result));
70 }
71}
72
73#endif
virtual void SelectFolder(const std::string &title, const std::string &defaultPath) override
virtual void SaveFile(const std::string &title, const std::string &defaultPathOrFile, const std::vector< std::string > &filters, const std::string &filterDescription) override
virtual void OpenFile(const std::string &title, const std::string &defaultPathOrFile, const std::vector< std::string > &filters, const std::string &filterDescription, bool allowMultiple) override
void SetResult(const std::string &result)