Centralize legacy document session bridge
This commit is contained in:
143
src/legacy_document_session_services.cpp
Normal file
143
src/legacy_document_session_services.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "legacy_document_session_services.h"
|
||||
|
||||
#include "app.h"
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
class LegacyCloseRequestServices final : public pp::app::CloseRequestServices {
|
||||
public:
|
||||
LegacyCloseRequestServices(App& app, bool& dialog_already_opened) noexcept
|
||||
: app_(app)
|
||||
, dialog_already_opened_(dialog_already_opened)
|
||||
{
|
||||
}
|
||||
|
||||
void request_close_now() override
|
||||
{
|
||||
}
|
||||
|
||||
void show_unsaved_close_prompt() override
|
||||
{
|
||||
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");
|
||||
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;
|
||||
};
|
||||
dialog_already_opened_ = true;
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
bool& dialog_already_opened_;
|
||||
};
|
||||
|
||||
class LegacyDocumentSaveServices final : public pp::app::DocumentSaveServices {
|
||||
public:
|
||||
explicit LegacyDocumentSaveServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void show_save_dialog() override
|
||||
{
|
||||
app_.dialog_save();
|
||||
}
|
||||
|
||||
void save_existing_document() override
|
||||
{
|
||||
Canvas::I->project_save();
|
||||
}
|
||||
|
||||
void save_document_version() override
|
||||
{
|
||||
app_.dialog_save_ver();
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
class LegacyDocumentWorkflowServices final : public pp::app::DocumentWorkflowServices {
|
||||
public:
|
||||
LegacyDocumentWorkflowServices(App& app, std::function<void()> action) noexcept
|
||||
: app_(app)
|
||||
, action_(std::move(action))
|
||||
{
|
||||
}
|
||||
|
||||
void continue_workflow_now() override
|
||||
{
|
||||
action_();
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
});
|
||||
m->destroy();
|
||||
};
|
||||
m->btn_cancel->on_click = [m, action](Node*) {
|
||||
action();
|
||||
m->destroy();
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
std::function<void()> action_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
pp::foundation::Status execute_legacy_close_request_decision(
|
||||
App& app,
|
||||
pp::app::CloseRequestDecision decision,
|
||||
bool& dialog_already_opened)
|
||||
{
|
||||
LegacyCloseRequestServices services(app, dialog_already_opened);
|
||||
return pp::app::execute_close_request_decision(decision, services);
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_document_save_decision(
|
||||
App& app,
|
||||
pp::app::DocumentSaveDecision decision)
|
||||
{
|
||||
LegacyDocumentSaveServices services(app);
|
||||
return pp::app::execute_document_save_decision(decision, services);
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_document_workflow_decision(
|
||||
App& app,
|
||||
pp::app::DocumentWorkflowDecision decision,
|
||||
std::function<void()> action)
|
||||
{
|
||||
LegacyDocumentWorkflowServices services(app, std::move(action));
|
||||
return pp::app::execute_document_workflow_decision(decision, services);
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
Reference in New Issue
Block a user