add file save dialog on win
This commit is contained in:
@@ -159,6 +159,7 @@ public:
|
||||
bool clipboard_set_text(const std::string& s);
|
||||
void pick_image(std::function<void(std::string path)> callback);
|
||||
void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
void pick_file_save(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
void pick_dir(std::function<void(std::string path)> callback);
|
||||
void display_file(std::string path);
|
||||
void share_file(std::string path);
|
||||
|
||||
@@ -8,6 +8,7 @@ std::string android_get_clipboard();
|
||||
bool android_set_clipboard(const std::string& s);
|
||||
#elif _WIN32
|
||||
std::string win32_open_file(const char* filter);
|
||||
std::string win32_save_file(const char* filter);
|
||||
std::string win32_open_dir();
|
||||
void win32_show_cursor(bool visible);
|
||||
bool win32_clipboard_set_text(const std::string & s);
|
||||
@@ -193,6 +194,50 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
|
||||
#endif
|
||||
}
|
||||
|
||||
void App::pick_file_save(std::vector<std::string> types, std::function<void (std::string)> callback)
|
||||
{
|
||||
redraw = true;
|
||||
#ifdef __IOS__
|
||||
// not implemented on ios
|
||||
// fallback to pick_image
|
||||
//dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [ios_view pick_photo:callback];
|
||||
//});
|
||||
#elif __OSX__
|
||||
//dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// //NSArray* fileTypes = [NSArray arrayWithObjects:@"ppi", @"PPI", nil];
|
||||
// NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:types.size()];
|
||||
// for (const auto& t : types)
|
||||
// [fileTypes addObject:[NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]];
|
||||
// std::string path = [osx_view pick_file:fileTypes];
|
||||
// if (!path.empty())
|
||||
// callback(path);
|
||||
//});
|
||||
#elif __ANDROID__
|
||||
//android_pick_file(callback);
|
||||
#elif _WIN32
|
||||
std::string filter = "Supported Files (";
|
||||
bool first_type = true;
|
||||
for (auto& t : types)
|
||||
{
|
||||
filter.append(std::string(first_type ? "" : " ,") + "*." + t);
|
||||
first_type = false;
|
||||
}
|
||||
filter.append(")");
|
||||
filter.push_back(0);
|
||||
first_type = true;
|
||||
for (auto& t : types)
|
||||
{
|
||||
filter.append(std::string(first_type ? "" : ";") + "*." + t);
|
||||
first_type = false;
|
||||
}
|
||||
filter.push_back(0);
|
||||
std::string path = win32_save_file(filter.c_str());
|
||||
if (!path.empty())
|
||||
callback(path);
|
||||
#endif
|
||||
}
|
||||
|
||||
void App::pick_dir(std::function<void(std::string path)> callback)
|
||||
{
|
||||
redraw = true;
|
||||
|
||||
20
src/main.cpp
20
src/main.cpp
@@ -278,6 +278,26 @@ std::string win32_open_file(const char* filter)
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string win32_save_file(const char* filter)
|
||||
{
|
||||
OPENFILENAMEA ofn;
|
||||
char fileName[MAX_PATH] = "";
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||
ofn.hwndOwner = hWnd;
|
||||
ofn.lpstrFilter = filter;
|
||||
ofn.lpstrFile = fileName;
|
||||
ofn.nMaxFile = MAX_PATH;
|
||||
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
|
||||
ofn.lpstrDefExt = "";
|
||||
ofn.lpstrInitialDir = "";
|
||||
if (GetSaveFileNameA(&ofn) != NULL)
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string win32_open_dir()
|
||||
{
|
||||
BROWSEINFOA bi;
|
||||
|
||||
Reference in New Issue
Block a user