Add export menu service boundary
This commit is contained in:
@@ -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