diff --git a/src/app.h b/src/app.h index 5ec9e37..03a27f8 100644 --- a/src/app.h +++ b/src/app.h @@ -159,6 +159,7 @@ public: bool clipboard_set_text(const std::string& s); void pick_image(std::function callback); void pick_file(std::vector types, std::function callback); + void pick_file_save(std::vector types, std::function callback); void pick_dir(std::function callback); void display_file(std::string path); void share_file(std::string path); diff --git a/src/app_events.cpp b/src/app_events.cpp index 7929db8..663fea7 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -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 types, std::function types, std::function 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* 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 callback) { redraw = true; diff --git a/src/main.cpp b/src/main.cpp index 63d3327..69d5c1c 100644 --- a/src/main.cpp +++ b/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;