Plan document session prompts
This commit is contained in:
@@ -12,6 +12,20 @@
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
void apply_legacy_message_box_plan(
|
||||
NodeMessageBox& msgbox,
|
||||
const pp::app::AppMessageDialogPlan& plan)
|
||||
{
|
||||
msgbox.m_title->set_text(plan.title.c_str());
|
||||
msgbox.m_message->set_text(plan.message.c_str());
|
||||
msgbox.btn_ok->m_text->set_text(plan.ok_caption.c_str());
|
||||
if (plan.show_cancel) {
|
||||
msgbox.btn_cancel->m_text->set_text(plan.cancel_caption.c_str());
|
||||
} else {
|
||||
msgbox.btn_cancel->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void create_legacy_new_document(
|
||||
App& app,
|
||||
const pp::app::NewDocumentPlan& plan,
|
||||
@@ -58,8 +72,10 @@ public:
|
||||
auto msgbox = new NodeMessageBox();
|
||||
msgbox->set_manager(&app_.layout);
|
||||
msgbox->init();
|
||||
msgbox->m_title->set_text("Warning");
|
||||
msgbox->m_message->set_text("A document with this name already exists, continue?");
|
||||
apply_legacy_message_box_plan(
|
||||
*msgbox,
|
||||
pp::app::plan_document_session_prompt(
|
||||
pp::app::DocumentSessionPromptKind::new_document_overwrite));
|
||||
auto* app = &app_;
|
||||
auto dialog = dialog_;
|
||||
msgbox->btn_ok->on_click = [app, msgbox, dialog, plan](Node*) {
|
||||
@@ -106,8 +122,11 @@ public:
|
||||
auto msgbox = new NodeMessageBox();
|
||||
msgbox->set_manager(&app_.layout);
|
||||
msgbox->init();
|
||||
msgbox->m_title->set_text("Warning");
|
||||
msgbox->m_message->set_text(("Are you sure you want to overwrite " + plan.target.name + "?").c_str());
|
||||
apply_legacy_message_box_plan(
|
||||
*msgbox,
|
||||
pp::app::plan_document_session_prompt(
|
||||
pp::app::DocumentSessionPromptKind::document_file_overwrite,
|
||||
plan.target.name));
|
||||
auto* app = &app_;
|
||||
auto dialog = dialog_;
|
||||
msgbox->btn_ok->on_click = [app, msgbox, dialog, plan](Node*) {
|
||||
@@ -159,14 +178,14 @@ public:
|
||||
auto* app = &app_;
|
||||
auto* dialog_already_opened = &dialog_already_opened_;
|
||||
auto* m = app_.layout[app_.main_id]->add_child<NodeMessageBox>();
|
||||
m->m_title->set_text("Unsaved document");
|
||||
m->m_message->set_text("Do you want to close without saving?");
|
||||
m->btn_ok->m_text->set_text("Yes");
|
||||
apply_legacy_message_box_plan(
|
||||
*m,
|
||||
pp::app::plan_document_session_prompt(
|
||||
pp::app::DocumentSessionPromptKind::close_unsaved_document));
|
||||
m->btn_ok->on_click = [app](Node*) {
|
||||
app->request_app_close();
|
||||
Canvas::I->m_unsaved = false;
|
||||
};
|
||||
m->btn_cancel->m_text->set_text("No");
|
||||
m->btn_cancel->on_click = [dialog_already_opened, m](Node*) {
|
||||
m->destroy();
|
||||
*dialog_already_opened = false;
|
||||
@@ -221,18 +240,21 @@ public:
|
||||
void prompt_save_before_continue() override
|
||||
{
|
||||
auto m = app_.layout[app_.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");
|
||||
apply_legacy_message_box_plan(
|
||||
*m,
|
||||
pp::app::plan_document_session_prompt(
|
||||
pp::app::DocumentSessionPromptKind::save_before_workflow_continue));
|
||||
auto* app = &app_;
|
||||
auto action = action_;
|
||||
m->btn_ok->on_click = [app, m, action](Node*) {
|
||||
Canvas::I->project_save([app, m, action](bool success) {
|
||||
if (success)
|
||||
action();
|
||||
else
|
||||
app->message_box("Saving Error", "There was a problem saving the document");
|
||||
else {
|
||||
const auto plan = pp::app::plan_document_session_prompt(
|
||||
pp::app::DocumentSessionPromptKind::document_save_error);
|
||||
app->message_box(plan.title, plan.message, plan.show_cancel);
|
||||
}
|
||||
});
|
||||
m->destroy();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user