Plan document session prompts
This commit is contained in:
@@ -24,6 +24,7 @@ struct AppMessageDialogPlan {
|
||||
std::string title;
|
||||
std::string message;
|
||||
std::string ok_caption = "Ok";
|
||||
std::string cancel_caption = "Cancel";
|
||||
bool show_cancel = false;
|
||||
};
|
||||
|
||||
@@ -48,12 +49,15 @@ struct AppInputDialogPlan {
|
||||
[[nodiscard]] inline AppMessageDialogPlan plan_app_message_dialog(
|
||||
std::string_view title,
|
||||
std::string_view message,
|
||||
bool show_cancel)
|
||||
bool show_cancel,
|
||||
std::string_view ok_caption = "Ok",
|
||||
std::string_view cancel_caption = "Cancel")
|
||||
{
|
||||
return {
|
||||
std::string(title),
|
||||
std::string(message),
|
||||
"Ok",
|
||||
std::string(ok_caption),
|
||||
std::string(cancel_caption),
|
||||
show_cancel,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_core/app_dialog.h"
|
||||
#include "app_core/document_route.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
@@ -55,6 +56,14 @@ enum class DocumentOpenPlanAction {
|
||||
prompt_import_ppbr,
|
||||
};
|
||||
|
||||
enum class DocumentSessionPromptKind {
|
||||
close_unsaved_document,
|
||||
save_before_workflow_continue,
|
||||
new_document_overwrite,
|
||||
document_file_overwrite,
|
||||
document_save_error,
|
||||
};
|
||||
|
||||
class DocumentOpenServices {
|
||||
public:
|
||||
virtual ~DocumentOpenServices() = default;
|
||||
@@ -135,6 +144,47 @@ public:
|
||||
virtual void prompt_overwrite_new_document(const NewDocumentPlan& plan) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline AppMessageDialogPlan plan_document_session_prompt(
|
||||
DocumentSessionPromptKind kind,
|
||||
std::string_view document_name = {})
|
||||
{
|
||||
switch (kind) {
|
||||
case DocumentSessionPromptKind::close_unsaved_document:
|
||||
return plan_app_message_dialog(
|
||||
"Unsaved document",
|
||||
"Do you want to close without saving?",
|
||||
true,
|
||||
"Yes",
|
||||
"No");
|
||||
case DocumentSessionPromptKind::save_before_workflow_continue:
|
||||
return plan_app_message_dialog(
|
||||
"Unsaved document",
|
||||
"Would you like to save this document before closing?",
|
||||
true,
|
||||
"Yes",
|
||||
"No");
|
||||
case DocumentSessionPromptKind::new_document_overwrite:
|
||||
return plan_app_message_dialog(
|
||||
"Warning",
|
||||
"A document with this name already exists, continue?",
|
||||
true);
|
||||
case DocumentSessionPromptKind::document_file_overwrite:
|
||||
{
|
||||
std::string message = "Are you sure you want to overwrite ";
|
||||
message += document_name;
|
||||
message += "?";
|
||||
return plan_app_message_dialog("Warning", message, true);
|
||||
}
|
||||
case DocumentSessionPromptKind::document_save_error:
|
||||
return plan_app_message_dialog(
|
||||
"Saving Error",
|
||||
"There was a problem saving the document",
|
||||
false);
|
||||
}
|
||||
|
||||
return plan_app_message_dialog("Warning", "", false);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr ProjectOpenDecision plan_project_open(bool has_unsaved_changes) noexcept
|
||||
{
|
||||
return has_unsaved_changes
|
||||
|
||||
@@ -134,7 +134,9 @@ std::shared_ptr<NodeMessageBox> App::message_box(const std::string &title, const
|
||||
m->m_title->set_text(plan.title.c_str());
|
||||
m->m_message->set_text(plan.message.c_str());
|
||||
m->btn_ok->m_text->set_text(plan.ok_caption.c_str());
|
||||
if (!plan.show_cancel)
|
||||
if (plan.show_cancel)
|
||||
m->btn_cancel->m_text->set_text(plan.cancel_caption.c_str());
|
||||
else
|
||||
m->btn_cancel->destroy();
|
||||
layout[main_id]->add_child(m);
|
||||
return m;
|
||||
|
||||
@@ -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