Extract file menu action planning
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "app_core/document_canvas.h"
|
||||
#include "app_core/document_export.h"
|
||||
#include "app_core/document_import.h"
|
||||
#include "app_core/file_menu.h"
|
||||
#include "app_core/app_status.h"
|
||||
#include "app_core/history_ui.h"
|
||||
#include "settings.h"
|
||||
@@ -123,6 +124,72 @@ bool apply_document_export_menu_plan(App& app, pp::app::DocumentExportMenuKind k
|
||||
return false;
|
||||
}
|
||||
|
||||
void apply_file_menu_plan(App& app, pp::app::FileMenuCommand command)
|
||||
{
|
||||
const auto plan = pp::app::plan_file_menu_command(command);
|
||||
switch (plan.action)
|
||||
{
|
||||
case pp::app::FileMenuAction::show_new_document_dialog:
|
||||
app.dialog_newdoc();
|
||||
break;
|
||||
case pp::app::FileMenuAction::pick_image_for_import:
|
||||
{
|
||||
auto* app_ptr = &app;
|
||||
app.pick_image([app_ptr](std::string path) {
|
||||
Image img;
|
||||
img.load_file(path);
|
||||
const auto import_plan = pp::app::plan_document_image_import(img.width, img.height);
|
||||
if (!import_plan)
|
||||
return;
|
||||
|
||||
if (import_plan.value().imports_equirectangular)
|
||||
{
|
||||
Canvas::I->import_equirectangular(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto m = static_cast<CanvasModeTransform*>(app_ptr->canvas->m_canvas->modes[(int)kCanvasMode::Import][0]);
|
||||
m->m_action = CanvasModeTransform::ActionType::Import;
|
||||
m->m_source_image = std::move(img);
|
||||
Canvas::set_mode(kCanvasMode::Import);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case pp::app::FileMenuAction::pick_project_file:
|
||||
{
|
||||
auto* app_ptr = &app;
|
||||
app.pick_file({ "ppi" }, [app_ptr](std::string path) {
|
||||
app_ptr->open_document(path);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case pp::app::FileMenuAction::show_cloud_browser_dialog:
|
||||
app.dialog_browse();
|
||||
break;
|
||||
case pp::app::FileMenuAction::save_document:
|
||||
app.save_document(plan.save_intent);
|
||||
break;
|
||||
case pp::app::FileMenuAction::show_export_jpeg_dialog:
|
||||
apply_document_export_menu_plan(app, plan.export_kind);
|
||||
break;
|
||||
case pp::app::FileMenuAction::show_export_submenu:
|
||||
break;
|
||||
case pp::app::FileMenuAction::share_document:
|
||||
app.share_file(app.doc_path);
|
||||
break;
|
||||
case pp::app::FileMenuAction::show_resize_dialog:
|
||||
app.dialog_resize();
|
||||
break;
|
||||
case pp::app::FileMenuAction::upload_to_cloud:
|
||||
app.cloud_upload();
|
||||
break;
|
||||
case pp::app::FileMenuAction::browse_cloud_documents:
|
||||
app.cloud_browse();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void App::title_update()
|
||||
@@ -783,70 +850,49 @@ void App::init_menu_file()
|
||||
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-newdoc"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
dialog_newdoc();
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::new_document);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-import"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
pick_image([this](std::string path){
|
||||
Image img;
|
||||
img.load_file(path);
|
||||
const auto import_plan = pp::app::plan_document_image_import(img.width, img.height);
|
||||
if (!import_plan)
|
||||
return;
|
||||
|
||||
if (import_plan.value().imports_equirectangular)
|
||||
{
|
||||
Canvas::I->import_equirectangular(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto m = static_cast<CanvasModeTransform*>(canvas->m_canvas->modes[(int)kCanvasMode::Import][0]);
|
||||
m->m_action = CanvasModeTransform::ActionType::Import;
|
||||
m->m_source_image = std::move(img);
|
||||
Canvas::set_mode(kCanvasMode::Import);
|
||||
}
|
||||
});
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::import_image);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-open"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
//dialog_open();
|
||||
pick_file({"ppi"}, [this](std::string path){
|
||||
open_document(path);
|
||||
});
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::open_project);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-browse"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
dialog_browse();
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::browse_cloud);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-save"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
save_document(pp::app::DocumentSaveIntent::save);
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::save);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-save-as"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
save_document(pp::app::DocumentSaveIntent::save_as);
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::save_as);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-save-ver"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
save_document(pp::app::DocumentSaveIntent::save_version);
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::save_version);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-export"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
apply_document_export_menu_plan(*this, pp::app::DocumentExportMenuKind::jpeg);
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::export_jpeg);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
@@ -912,25 +958,25 @@ void App::init_menu_file()
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-share"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
share_file(doc_path);
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::share);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-resize"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
dialog_resize();
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::resize);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-cloud-upload"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
cloud_upload();
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::cloud_upload);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-cloud-browse"))
|
||||
b->on_click = [this, popup](Node*) {
|
||||
cloud_browse();
|
||||
apply_file_menu_plan(*this, pp::app::FileMenuCommand::cloud_browse);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user