add more checks on unsaved documents
This commit is contained in:
@@ -19,8 +19,8 @@ std::shared_ptr<NodeProgressBar> App::show_progress(const std::string& title)
|
||||
|
||||
void App::dialog_newdoc()
|
||||
{
|
||||
if (canvas)
|
||||
{
|
||||
auto show_dialog = [this] {
|
||||
async_start();
|
||||
auto dialog = std::make_shared<NodeDialogNewDoc>();
|
||||
dialog->m_manager = &layout;
|
||||
dialog->init();
|
||||
@@ -30,7 +30,7 @@ void App::dialog_newdoc()
|
||||
|
||||
layout[main_id]->add_child(dialog);
|
||||
layout[main_id]->update();
|
||||
|
||||
|
||||
App::I.showKeyboard();
|
||||
|
||||
dialog->btn_ok->on_click = [this, dialog](Node*)
|
||||
@@ -39,7 +39,7 @@ void App::dialog_newdoc()
|
||||
std::string path = data_path + "/" + name + ".pano";
|
||||
|
||||
auto action = [this, dialog, name] {
|
||||
std::array<int, 4> resolutions{512, 1024, 1536, 2048};
|
||||
std::array<int, 4> resolutions{ 512, 1024, 1536, 2048 };
|
||||
int res = resolutions[dialog->m_resolution->m_current_index];
|
||||
doc_name = name;
|
||||
title_update();
|
||||
@@ -50,7 +50,7 @@ void App::dialog_newdoc()
|
||||
canvas->m_canvas->resize(res, res);
|
||||
canvas->reset_camera();
|
||||
ActionManager::clear();
|
||||
|
||||
|
||||
canvas->m_canvas->layer_add("Default");
|
||||
layers->add_layer("Default");
|
||||
|
||||
@@ -83,13 +83,40 @@ void App::dialog_newdoc()
|
||||
dialog->destroy();
|
||||
App::I.hideKeyboard();
|
||||
};
|
||||
async_end();
|
||||
};
|
||||
|
||||
if (canvas)
|
||||
{
|
||||
if (ui::Canvas::I->m_unsaved)
|
||||
{
|
||||
auto m = layout[main_id]->add_child<NodeMessageBox>();
|
||||
m->m_title->set_text("Unsaved document");
|
||||
m->m_message->set_text("Would you like to save this document before closing?");
|
||||
m->btn_ok->m_text->set_text("Yes");
|
||||
m->btn_cancel->m_text->set_text("No");
|
||||
m->btn_ok->on_click = [this, m, show_dialog](Node*) {
|
||||
ui::Canvas::I->project_save([this, m, show_dialog] {
|
||||
show_dialog();
|
||||
});
|
||||
m->destroy();
|
||||
};
|
||||
m->btn_cancel->on_click = [this, m, show_dialog](Node*) {
|
||||
show_dialog();
|
||||
m->destroy();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
show_dialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void App::dialog_open()
|
||||
{
|
||||
if (canvas)
|
||||
{
|
||||
auto show_dialog = [this] {
|
||||
async_start();
|
||||
// load thumbnail test
|
||||
auto dialog = std::make_shared<NodeDialogOpen>();
|
||||
dialog->m_manager = &layout;
|
||||
@@ -117,13 +144,40 @@ void App::dialog_open()
|
||||
dialog->destroy();
|
||||
ActionManager::clear();
|
||||
};
|
||||
async_end();
|
||||
};
|
||||
|
||||
if (canvas)
|
||||
{
|
||||
if (ui::Canvas::I->m_unsaved)
|
||||
{
|
||||
auto m = layout[main_id]->add_child<NodeMessageBox>();
|
||||
m->m_title->set_text("Unsaved document");
|
||||
m->m_message->set_text("Would you like to save this document before closing?");
|
||||
m->btn_ok->m_text->set_text("Yes");
|
||||
m->btn_cancel->m_text->set_text("No");
|
||||
m->btn_ok->on_click = [this,m,show_dialog](Node*){
|
||||
ui::Canvas::I->project_save([this,m,show_dialog] {
|
||||
show_dialog();
|
||||
});
|
||||
m->destroy();
|
||||
};
|
||||
m->btn_cancel->on_click = [this,m,show_dialog](Node*) {
|
||||
show_dialog();
|
||||
m->destroy();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
show_dialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void App::dialog_browse()
|
||||
{
|
||||
if (canvas)
|
||||
{
|
||||
auto show_dialog = [this] {
|
||||
async_start();
|
||||
// load thumbnail test
|
||||
auto dialog = std::make_shared<NodeDialogBrowse>();
|
||||
dialog->m_manager = &layout;
|
||||
@@ -151,6 +205,33 @@ void App::dialog_browse()
|
||||
dialog->destroy();
|
||||
ActionManager::clear();
|
||||
};
|
||||
async_end();
|
||||
};
|
||||
|
||||
if (canvas)
|
||||
{
|
||||
if (ui::Canvas::I->m_unsaved)
|
||||
{
|
||||
auto m = layout[main_id]->add_child<NodeMessageBox>();
|
||||
m->m_title->set_text("Unsaved document");
|
||||
m->m_message->set_text("Would you like to save this document before closing?");
|
||||
m->btn_ok->m_text->set_text("Yes");
|
||||
m->btn_cancel->m_text->set_text("No");
|
||||
m->btn_ok->on_click = [this, m, show_dialog](Node*) {
|
||||
ui::Canvas::I->project_save([this, m, show_dialog] {
|
||||
show_dialog();
|
||||
});
|
||||
m->destroy();
|
||||
};
|
||||
m->btn_cancel->on_click = [this, m, show_dialog](Node*) {
|
||||
show_dialog();
|
||||
m->destroy();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
show_dialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1357,17 +1357,40 @@ void ui::Canvas::export_cubes(std::string data_path)
|
||||
#endif
|
||||
}
|
||||
|
||||
void ui::Canvas::project_save(std::string file_path)
|
||||
void ui::Canvas::project_save(std::function<void()> on_complete)
|
||||
{
|
||||
if (!App::I.check_license())
|
||||
return;
|
||||
std::thread t(&ui::Canvas::project_save_thread, this, file_path);
|
||||
t.detach();
|
||||
if (App::I.check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
project_save_thread(App::I.data_path + "/" + App::I.doc_name + ".pano");
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void ui::Canvas::project_save(std::string file_path, std::function<void()> on_complete)
|
||||
{
|
||||
if (App::I.check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
project_save_thread(file_path);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void ui::Canvas::project_save_thread(std::string file_path)
|
||||
{
|
||||
gl_state gl;
|
||||
|
||||
// already saved, nothing to do
|
||||
if (!m_unsaved)
|
||||
return;
|
||||
|
||||
// static char name[128];
|
||||
// sprintf(name, "%s/latlong.pano", data_path.c_str());
|
||||
FILE* fp = fopen(file_path.c_str(), "wb");
|
||||
|
||||
@@ -144,7 +144,8 @@ public:
|
||||
void export_equirectangular_thread(std::string file_path);
|
||||
void export_anim(std::string data_path);
|
||||
void export_cubes(std::string data_path);
|
||||
void project_save(std::string file_path);
|
||||
void project_save(std::function<void()> on_complete = nullptr);
|
||||
void project_save(std::string file_path, std::function<void()> on_complete = nullptr);
|
||||
void project_save_thread(std::string file_path);
|
||||
void project_open(std::string file_path, std::function<void()> on_complete = nullptr);
|
||||
void project_open_thread(std::string file_path);
|
||||
|
||||
Reference in New Issue
Block a user