fix iOS save picker
This commit is contained in:
@@ -236,41 +236,29 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
void App::pick_file_save(const std::string& type, std::function<void(std::string)> writer,
|
||||
std::function<void(bool saved)> callback)
|
||||
void App::pick_file_save(const std::string& type, const std::string& default_name,
|
||||
std::function<void(std::string)> writer, std::function<void(const std::string& path, bool saved)> callback)
|
||||
{
|
||||
redraw = true;
|
||||
auto mb = input_box("Insert", "File name");
|
||||
std::string placeholder = "name." + type;
|
||||
mb->m_field_text->set_text(placeholder.c_str());
|
||||
mb->on_submit = [this, writer, type, callback, mb] (Node* target, std::string name) {
|
||||
std::string ext = "." + type;
|
||||
std::string path = data_path + "/" + name;
|
||||
if (name.find(ext) == std::string::npos)
|
||||
path += ext;
|
||||
std::thread([=]{
|
||||
writer(path);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[ios_view pick_file_save:path];
|
||||
});
|
||||
mb->destroy();
|
||||
callback(true);
|
||||
}).detach();
|
||||
};
|
||||
mb->btn_cancel->on_click = [=] (Node* target) {
|
||||
callback(false);
|
||||
mb->destroy();
|
||||
};
|
||||
std::string ext = "." + type;
|
||||
std::string path = tmp_path + "/" + default_name + ext;
|
||||
std::thread([=]{
|
||||
writer(path);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[ios_view pick_file_save:path];
|
||||
});
|
||||
callback(path, true);
|
||||
}).detach();
|
||||
}
|
||||
#elif __WEB__
|
||||
void App::pick_file_save(const std::string& type, std::function<void(std::string)> writer,
|
||||
std::function<void(bool saved)> callback)
|
||||
void App::pick_file_save(const std::string& type, const std::string& default_name,
|
||||
std::function<void(std::string)> writer, std::function<void(const std::string& path, bool saved)> callback)
|
||||
{
|
||||
redraw = true;
|
||||
auto path = data_path + "/file-save." + type;
|
||||
auto path = data_path + "/" + default_name + "." + type;
|
||||
LOG("App::pick_file_save %s", path.c_str());
|
||||
writer(path);
|
||||
webgl_pick_file_save(path, "file." + type, callback);
|
||||
webgl_pick_file_save(path, default_name + "." + type, callback);
|
||||
}
|
||||
#else
|
||||
void App::pick_file_save(std::vector<std::string> types, std::function<void(std::string)> callback)
|
||||
|
||||
Reference in New Issue
Block a user