Add export menu service boundary
This commit is contained in:
@@ -62,6 +62,21 @@ struct DocumentExportMenuPlan {
|
||||
bool opens_dialog = true;
|
||||
};
|
||||
|
||||
class DocumentExportMenuServices {
|
||||
public:
|
||||
virtual ~DocumentExportMenuServices() = default;
|
||||
|
||||
virtual void show_jpeg_dialog() = 0;
|
||||
virtual void show_png_dialog() = 0;
|
||||
virtual void show_layers_dialog() = 0;
|
||||
virtual void show_cube_faces_dialog() = 0;
|
||||
virtual void show_depth_dialog() = 0;
|
||||
virtual void show_animation_frames_dialog() = 0;
|
||||
virtual void show_animation_mp4_dialog() = 0;
|
||||
virtual void show_timelapse_dialog() = 0;
|
||||
virtual void show_license_disabled() = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] constexpr DocumentExportStartDecision plan_document_export_start(
|
||||
bool requires_license,
|
||||
bool license_valid,
|
||||
@@ -226,4 +241,43 @@ struct DocumentExportMenuPlan {
|
||||
return pp::foundation::Result<DocumentExportSuggestedName>::success(std::move(target));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_document_export_menu_plan(
|
||||
const DocumentExportMenuPlan& plan,
|
||||
DocumentExportMenuServices& services)
|
||||
{
|
||||
switch (plan.action) {
|
||||
case DocumentExportMenuAction::show_jpeg_dialog:
|
||||
services.show_jpeg_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_png_dialog:
|
||||
services.show_png_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_layers_dialog:
|
||||
services.show_layers_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_cube_faces_dialog:
|
||||
services.show_cube_faces_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_depth_dialog:
|
||||
services.show_depth_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_animation_frames_dialog:
|
||||
services.show_animation_frames_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_animation_mp4_dialog:
|
||||
services.show_animation_mp4_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_timelapse_dialog:
|
||||
services.show_timelapse_dialog();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::show_license_disabled:
|
||||
services.show_license_disabled();
|
||||
return pp::foundation::Status::success();
|
||||
case DocumentExportMenuAction::unavailable_no_canvas:
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
return pp::foundation::Status::invalid_argument("unknown document export menu action");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,46 +85,40 @@ bool apply_brush_preset_plan(App& app, const std::shared_ptr<Brush>& brush)
|
||||
|
||||
bool apply_document_export_menu_plan(App& app, pp::app::DocumentExportMenuKind kind)
|
||||
{
|
||||
class LegacyDocumentExportMenuServices final : public pp::app::DocumentExportMenuServices {
|
||||
public:
|
||||
explicit LegacyDocumentExportMenuServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void show_jpeg_dialog() override { app_.dialog_export(".jpg"); }
|
||||
void show_png_dialog() override { app_.dialog_export(".png"); }
|
||||
void show_layers_dialog() override { app_.dialog_export_layers(); }
|
||||
void show_cube_faces_dialog() override { app_.dialog_export_cube_faces(); }
|
||||
void show_depth_dialog() override { app_.dialog_export_depth(); }
|
||||
void show_animation_frames_dialog() override { app_.dialog_export_anim_frames(); }
|
||||
void show_animation_mp4_dialog() override { app_.dialog_export_mp4(); }
|
||||
void show_timelapse_dialog() override { app_.dialog_timelapse_export(); }
|
||||
void show_license_disabled() override
|
||||
{
|
||||
app_.message_box("License", "This function is disabled in demo mode.");
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
const auto requires_license = pp::app::document_export_menu_requires_license(kind);
|
||||
const auto plan = pp::app::plan_document_export_menu_action(
|
||||
kind,
|
||||
app.canvas != nullptr,
|
||||
!requires_license || app.check_license());
|
||||
|
||||
switch (plan.action)
|
||||
{
|
||||
case pp::app::DocumentExportMenuAction::show_jpeg_dialog:
|
||||
app.dialog_export(".jpg");
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_png_dialog:
|
||||
app.dialog_export(".png");
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_layers_dialog:
|
||||
app.dialog_export_layers();
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_cube_faces_dialog:
|
||||
app.dialog_export_cube_faces();
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_depth_dialog:
|
||||
app.dialog_export_depth();
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_animation_frames_dialog:
|
||||
app.dialog_export_anim_frames();
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_animation_mp4_dialog:
|
||||
app.dialog_export_mp4();
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_timelapse_dialog:
|
||||
app.dialog_timelapse_export();
|
||||
return true;
|
||||
case pp::app::DocumentExportMenuAction::show_license_disabled:
|
||||
app.message_box("License", "This function is disabled in demo mode.");
|
||||
return false;
|
||||
case pp::app::DocumentExportMenuAction::unavailable_no_canvas:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
LegacyDocumentExportMenuServices services(app);
|
||||
const auto status = pp::app::execute_document_export_menu_plan(plan, services);
|
||||
if (!status.ok())
|
||||
LOG("Document export menu action failed: %s", status.message);
|
||||
return status.ok() && plan.opens_dialog;
|
||||
}
|
||||
|
||||
class LegacyFileMenuServices final : public pp::app::FileMenuServices {
|
||||
|
||||
Reference in New Issue
Block a user