implement file picker in iOS with .ext to UTI filtering
This commit is contained in:
@@ -105,8 +105,7 @@ void App::showKeyboard()
|
||||
redraw = true;
|
||||
#ifdef __IOS__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//[ios_view registerForKeyboardNotifications];
|
||||
[ios_view becomeFirstResponder];
|
||||
[ios_view show_keyboard];
|
||||
});
|
||||
#elif __ANDROID__
|
||||
displayKeyboard(true);
|
||||
@@ -119,8 +118,7 @@ void App::hideKeyboard()
|
||||
redraw = true;
|
||||
#ifdef __IOS__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[ios_view resignFirstResponder];
|
||||
// [ios_view unregisterForKeyboardNotifications];
|
||||
[ios_view hide_keyboard];
|
||||
});
|
||||
#elif __ANDROID__
|
||||
displayKeyboard(false);
|
||||
@@ -154,14 +152,14 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
|
||||
{
|
||||
redraw = true;
|
||||
#ifdef __IOS__
|
||||
// not implemented on ios
|
||||
// fallback to pick_image
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[ios_view pick_photo:callback];
|
||||
NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:types.size()];
|
||||
for (const auto& t : types)
|
||||
[fileTypes addObject:[NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]];
|
||||
[ios_view pick_file:fileTypes then: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]];
|
||||
@@ -198,11 +196,9 @@ void App::pick_file_save(std::vector<std::string> types, std::function<void (std
|
||||
{
|
||||
redraw = true;
|
||||
#ifdef __IOS__
|
||||
// not implemented on ios
|
||||
// fallback to pick_image
|
||||
//dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [ios_view pick_photo:callback];
|
||||
//});
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [ios_view pick_file_save:callback];
|
||||
// });
|
||||
#elif __OSX__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//NSArray* fileTypes = [NSArray arrayWithObjects:@"ppi", @"PPI", nil];
|
||||
|
||||
@@ -525,36 +525,19 @@ void App::init_menu_file()
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-import"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
pick_file({ "JPG", "PNG", "ABR" }, [this](std::string path){
|
||||
std::string name, base, ext;
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
|
||||
std::smatch m;
|
||||
if (!std::regex_search(path, m, r))
|
||||
return;
|
||||
base = m[1].str();
|
||||
name = m[2].str();
|
||||
ext = m[3].str();
|
||||
|
||||
if (str_iequals(ext, "abr"))
|
||||
pick_image([this](std::string path){
|
||||
Image img;
|
||||
img.load_file(path);
|
||||
if (img.width == img.height / 6 || img.width == img.height * 2)
|
||||
{
|
||||
std::thread([this,path] { presets->import_abr(path); }).detach();
|
||||
Canvas::I->import_equirectangular(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Image img;
|
||||
img.load_file(path);
|
||||
if (img.width == img.height / 6 || img.width == img.height * 2)
|
||||
{
|
||||
Canvas::I->import_equirectangular(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto m = static_cast<CanvasModeTransform*>(canvas->m_canvas->modes[(int)kCanvasMode::Import][0]);
|
||||
m->m_action = CanvasModeTransform::ActionType::Import;
|
||||
m->m_source_image = std::move(img);
|
||||
Canvas::set_mode(kCanvasMode::Import);
|
||||
}
|
||||
async_redraw();
|
||||
auto m = static_cast<CanvasModeTransform*>(canvas->m_canvas->modes[(int)kCanvasMode::Import][0]);
|
||||
m->m_action = CanvasModeTransform::ActionType::Import;
|
||||
m->m_source_image = std::move(img);
|
||||
Canvas::set_mode(kCanvasMode::Import);
|
||||
}
|
||||
});
|
||||
popup->mouse_release();
|
||||
|
||||
Reference in New Issue
Block a user