Add document resize service boundary
This commit is contained in:
@@ -21,6 +21,15 @@ struct DocumentResizePlan {
|
||||
bool clears_history = false;
|
||||
};
|
||||
|
||||
class DocumentResizeServices {
|
||||
public:
|
||||
virtual ~DocumentResizeServices() = default;
|
||||
|
||||
virtual void resize_document(int width, int height) = 0;
|
||||
virtual void update_title() = 0;
|
||||
virtual void clear_history() = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline DocumentResizeDialogState make_document_resize_dialog_state(
|
||||
int current_resolution)
|
||||
{
|
||||
@@ -54,4 +63,20 @@ struct DocumentResizePlan {
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_document_resize_plan(
|
||||
const DocumentResizePlan& plan,
|
||||
DocumentResizeServices& services)
|
||||
{
|
||||
if (plan.width <= 0 || plan.height <= 0) {
|
||||
return pp::foundation::Status::out_of_range("resize dimensions must be positive");
|
||||
}
|
||||
|
||||
services.resize_document(plan.width, plan.height);
|
||||
services.update_title();
|
||||
if (plan.clears_history) {
|
||||
services.clear_history();
|
||||
}
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -550,6 +550,33 @@ void App::dialog_export_depth()
|
||||
|
||||
void App::dialog_resize()
|
||||
{
|
||||
class LegacyDocumentResizeServices final : public pp::app::DocumentResizeServices {
|
||||
public:
|
||||
explicit LegacyDocumentResizeServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void resize_document(int width, int height) override
|
||||
{
|
||||
if (app_.canvas)
|
||||
app_.canvas->m_canvas->resize(width, height);
|
||||
}
|
||||
|
||||
void update_title() override
|
||||
{
|
||||
app_.title_update();
|
||||
}
|
||||
|
||||
void clear_history() override
|
||||
{
|
||||
ActionManager::clear();
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
auto dialog = std::make_shared<NodeDialogResize>();
|
||||
dialog->set_manager(&layout);
|
||||
dialog->init();
|
||||
@@ -567,10 +594,10 @@ void App::dialog_resize()
|
||||
dialog->destroy();
|
||||
return;
|
||||
}
|
||||
if (canvas)
|
||||
canvas->m_canvas->resize(plan.value().width, plan.value().height);
|
||||
App::I->title_update();
|
||||
ActionManager::clear();
|
||||
LegacyDocumentResizeServices services(*this);
|
||||
const auto status = pp::app::execute_document_resize_plan(plan.value(), services);
|
||||
if (!status.ok())
|
||||
LOG("Document resize failed: %s", status.message);
|
||||
dialog->destroy();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user