Extract file menu action planning

This commit is contained in:
2026-06-03 11:56:14 +02:00
parent 65b262207c
commit 6dac909869
8 changed files with 474 additions and 34 deletions

149
src/app_core/file_menu.h Normal file
View File

@@ -0,0 +1,149 @@
#pragma once
#include "app_core/document_export.h"
#include "app_core/document_session.h"
#include "foundation/result.h"
#include <string_view>
namespace pp::app {
enum class FileMenuCommand {
new_document,
import_image,
open_project,
browse_cloud,
save,
save_as,
save_version,
export_jpeg,
export_submenu,
share,
resize,
cloud_upload,
cloud_browse,
};
enum class FileMenuAction {
show_new_document_dialog,
pick_image_for_import,
pick_project_file,
show_cloud_browser_dialog,
save_document,
show_export_jpeg_dialog,
show_export_submenu,
share_document,
show_resize_dialog,
upload_to_cloud,
browse_cloud_documents,
};
struct FileMenuPlan {
FileMenuCommand command = FileMenuCommand::new_document;
FileMenuAction action = FileMenuAction::show_new_document_dialog;
DocumentSaveIntent save_intent = DocumentSaveIntent::save;
DocumentExportMenuKind export_kind = DocumentExportMenuKind::jpeg;
};
[[nodiscard]] constexpr FileMenuPlan plan_file_menu_command(FileMenuCommand command) noexcept
{
FileMenuPlan plan;
plan.command = command;
switch (command) {
case FileMenuCommand::new_document:
plan.action = FileMenuAction::show_new_document_dialog;
break;
case FileMenuCommand::import_image:
plan.action = FileMenuAction::pick_image_for_import;
break;
case FileMenuCommand::open_project:
plan.action = FileMenuAction::pick_project_file;
break;
case FileMenuCommand::browse_cloud:
plan.action = FileMenuAction::show_cloud_browser_dialog;
break;
case FileMenuCommand::save:
plan.action = FileMenuAction::save_document;
plan.save_intent = DocumentSaveIntent::save;
break;
case FileMenuCommand::save_as:
plan.action = FileMenuAction::save_document;
plan.save_intent = DocumentSaveIntent::save_as;
break;
case FileMenuCommand::save_version:
plan.action = FileMenuAction::save_document;
plan.save_intent = DocumentSaveIntent::save_version;
break;
case FileMenuCommand::export_jpeg:
plan.action = FileMenuAction::show_export_jpeg_dialog;
plan.export_kind = DocumentExportMenuKind::jpeg;
break;
case FileMenuCommand::export_submenu:
plan.action = FileMenuAction::show_export_submenu;
break;
case FileMenuCommand::share:
plan.action = FileMenuAction::share_document;
break;
case FileMenuCommand::resize:
plan.action = FileMenuAction::show_resize_dialog;
break;
case FileMenuCommand::cloud_upload:
plan.action = FileMenuAction::upload_to_cloud;
break;
case FileMenuCommand::cloud_browse:
plan.action = FileMenuAction::browse_cloud_documents;
break;
}
return plan;
}
[[nodiscard]] inline pp::foundation::Result<FileMenuCommand> parse_file_menu_command(
std::string_view command) noexcept
{
if (command == "new" || command == "new-document") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::new_document);
}
if (command == "import" || command == "import-image") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::import_image);
}
if (command == "open" || command == "open-project") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::open_project);
}
if (command == "browse") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::browse_cloud);
}
if (command == "save") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::save);
}
if (command == "save-as") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::save_as);
}
if (command == "save-version") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::save_version);
}
if (command == "export" || command == "export-jpeg") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::export_jpeg);
}
if (command == "export-submenu") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::export_submenu);
}
if (command == "share") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::share);
}
if (command == "resize") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::resize);
}
if (command == "cloud-upload") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::cloud_upload);
}
if (command == "cloud-browse") {
return pp::foundation::Result<FileMenuCommand>::success(FileMenuCommand::cloud_browse);
}
return pp::foundation::Result<FileMenuCommand>::failure(
pp::foundation::Status::invalid_argument("unknown file menu command"));
}
} // namespace pp::app