fix: opening a doc async did not update the layers list, added on_complete callback to update the layers panel

This commit is contained in:
2017-11-07 07:37:21 +00:00
parent 33ea544f0b
commit 3e546affc9
7 changed files with 34 additions and 20 deletions

View File

@@ -1241,22 +1241,23 @@ void ui::Canvas::project_save_thread(std::string file_path)
App::I.async_end();
}
void ui::Canvas::project_open(std::string file_path)
void ui::Canvas::project_open(std::string file_path, std::function<void()> on_complete)
{
std::thread t(&ui::Canvas::project_open_thread, this, file_path);
std::thread t([=] {
project_open_thread(file_path);
if (on_complete)
on_complete();
});
t.detach();
//project_open_thread(data_path);
}
void ui::Canvas::project_open_thread(std::string file_path)
{
// static char name[128];
// sprintf(name, "%s/latlong.pano", data_path.c_str());
FILE* fp = fopen(file_path.c_str(), "rb");
if (!fp)
{
LOG("cannot write project to %s", file_path.c_str());
return;
return; // should probably return a bool
}
gl_state gl;
@@ -1306,6 +1307,9 @@ void ui::Canvas::project_open_thread(std::string file_path)
m_order.clear();
App::I.async_end();
std::vector<int> tmp_order;
std::vector<Layer> tmp_layers;
for (int i = 0; i < n_layers; i++)
{
int n_order;
@@ -1354,13 +1358,16 @@ void ui::Canvas::project_open_thread(std::string file_path)
}
App::I.async_start();
m_layers.emplace_back();
m_layers.back().create(m_width, m_height, name.c_str());
m_layers.back().restore(snap);
m_order.push_back(n_order);
tmp_layers.emplace_back();
tmp_layers.back().create(m_width, m_height, name.c_str());
tmp_layers.back().restore(snap);
tmp_order.push_back(n_order);
App::I.async_end();
}
std::swap(tmp_order, m_order);
std::swap(tmp_layers, m_layers);
fclose(fp);
LOG("project restore from %s", file_path.c_str());