implement save as, save version and file existence check on save
This commit is contained in:
@@ -21,21 +21,46 @@ void App::dialog_newdoc()
|
||||
|
||||
dialog->btn_ok->on_click = [this, dialog](Node*)
|
||||
{
|
||||
doc_name = dialog->input->m_string;
|
||||
if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
|
||||
docname->set_text(("Panodoc: " + doc_name).c_str());
|
||||
|
||||
layers->clear();
|
||||
canvas->m_canvas->m_layers.clear();
|
||||
canvas->m_canvas->m_order.clear();
|
||||
canvas->reset_camera();
|
||||
ActionManager::clear();
|
||||
|
||||
canvas->m_canvas->layer_add("Default");
|
||||
layers->add_layer("Default");
|
||||
|
||||
dialog->destroy();
|
||||
App::I.hideKeyboard();
|
||||
std::string name = dialog->input->m_string;
|
||||
std::string path = data_path + "/" + name + ".pano";
|
||||
|
||||
auto action = [this, dialog, name] {
|
||||
doc_name = name;
|
||||
if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
|
||||
docname->set_text(("Panodoc: " + doc_name).c_str());
|
||||
|
||||
layers->clear();
|
||||
canvas->m_canvas->m_layers.clear();
|
||||
canvas->m_canvas->m_order.clear();
|
||||
canvas->reset_camera();
|
||||
ActionManager::clear();
|
||||
|
||||
canvas->m_canvas->layer_add("Default");
|
||||
layers->add_layer("Default");
|
||||
|
||||
dialog->destroy();
|
||||
App::I.hideKeyboard();
|
||||
};
|
||||
|
||||
if (Asset::exist(path, false))
|
||||
{
|
||||
// ask confirm is file already exist
|
||||
auto msgbox = new NodeMessageBox();
|
||||
msgbox->m_manager = &layout;
|
||||
msgbox->init();
|
||||
msgbox->m_title->set_text("Warning");
|
||||
msgbox->m_message->set_text("A document with this name already exists, continue?");
|
||||
msgbox->btn_ok->on_click = [this, msgbox, action](Node*) {
|
||||
action();
|
||||
msgbox->destroy();
|
||||
};
|
||||
layout[main_id]->add_child(msgbox);
|
||||
}
|
||||
else
|
||||
{
|
||||
action();
|
||||
}
|
||||
|
||||
};
|
||||
dialog->btn_cancel->on_click = [this, dialog](Node*)
|
||||
{
|
||||
@@ -120,23 +145,58 @@ void App::dialog_save()
|
||||
|
||||
App::I.showKeyboard();
|
||||
|
||||
layout[main_id]->add_child(dialog);
|
||||
layout[main_id]->update();
|
||||
|
||||
dialog->btn_ok->on_click = [this, dialog](Node*)
|
||||
{
|
||||
doc_name = dialog->input->m_string;
|
||||
if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
|
||||
docname->set_text(("Panodoc: " + doc_name).c_str());
|
||||
canvas->m_canvas->project_save(data_path + "/" + doc_name + ".pano");
|
||||
dialog->destroy();
|
||||
App::I.hideKeyboard();
|
||||
std::string name = dialog->input->m_string;
|
||||
std::string path = data_path + "/" + name + ".pano";
|
||||
|
||||
if (name.empty())
|
||||
{
|
||||
auto msgbox = new NodeMessageBox();
|
||||
msgbox->m_manager = &layout;
|
||||
msgbox->init();
|
||||
msgbox->m_title->set_text("Warning");
|
||||
msgbox->m_message->set_text("You need to specify a name to file.");
|
||||
layout[main_id]->add_child(msgbox);
|
||||
return;
|
||||
}
|
||||
|
||||
auto action = [this, dialog, name, path] {
|
||||
doc_name = name;
|
||||
if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
|
||||
docname->set_text(("Panodoc: " + doc_name).c_str());
|
||||
canvas->m_canvas->project_save(path);
|
||||
dialog->destroy();
|
||||
App::I.hideKeyboard();
|
||||
};
|
||||
|
||||
if (Asset::exist(path, false))
|
||||
{
|
||||
// ask confirm is file already exist
|
||||
auto msgbox = new NodeMessageBox();
|
||||
msgbox->m_manager = &layout;
|
||||
msgbox->init();
|
||||
msgbox->m_title->set_text("Warning");
|
||||
msgbox->m_message->set_text(("Are you sure you want to overwrite " + name + "?").c_str());
|
||||
msgbox->btn_ok->on_click = [this, msgbox, action](Node*) {
|
||||
action();
|
||||
msgbox->destroy();
|
||||
};
|
||||
layout[main_id]->add_child(msgbox);
|
||||
}
|
||||
else
|
||||
{
|
||||
action();
|
||||
}
|
||||
};
|
||||
dialog->btn_cancel->on_click = [this, dialog](Node*)
|
||||
{
|
||||
dialog->destroy();
|
||||
App::I.hideKeyboard();
|
||||
};
|
||||
|
||||
layout[main_id]->add_child(dialog);
|
||||
layout[main_id]->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user