Centralize legacy document open bridge

This commit is contained in:
2026-06-04 13:20:14 +02:00
parent 1984b71a0a
commit d980b81bd7
9 changed files with 336 additions and 64 deletions

View File

@@ -0,0 +1,101 @@
#include "pch.h"
#include "legacy_document_open_services.h"
#include "app.h"
#include "legacy_history_services.h"
#include "node_panel_brush.h"
#include "node_panel_layer.h"
namespace pp::panopainter {
namespace {
void open_legacy_project(App& app, const pp::app::DocumentOpenRoute& route)
{
app.doc_name = route.name;
app.doc_dir = route.directory;
app.doc_path = route.path;
app.canvas->reset_camera();
app.layers->clear();
app.canvas->m_canvas->project_open(route.path, [&app](bool success) {
if (success)
{
app.title_update();
for (std::size_t layer_index = 0; layer_index < app.canvas->m_canvas->m_layers.size(); ++layer_index)
{
auto layer = app.layers->add_layer(app.canvas->m_canvas->m_layers[layer_index]->m_name.c_str(), false);
layer->m_visibility->set_value(app.canvas->m_canvas->m_layers[layer_index]->m_visible);
}
}
else
{
app.message_box(
"Open Document Error",
"There was an error opening the document.\n"
"It may be inaccessible or corrupted.");
}
});
pp::panopainter::clear_legacy_history();
}
class LegacyDocumentOpenServices final : public pp::app::DocumentOpenServices {
public:
explicit LegacyDocumentOpenServices(App& app) noexcept
: app_(app)
{
}
void prompt_import_abr(const pp::app::DocumentOpenRoute& route) override
{
auto* app = &app_;
auto mb = app_.message_box("Import ABR", "Would you like to import the brushes?", true);
mb->on_submit = [app, path = route.path](Node* target) {
std::thread(&NodePanelBrushPreset::import_abr, app->presets, path).detach();
target->destroy();
};
}
void prompt_import_ppbr(const pp::app::DocumentOpenRoute& route) override
{
auto* app = &app_;
auto mb = app_.message_box("Import PPBR", "Would you like to import the brushes?", true);
mb->on_submit = [app, path = route.path](Node* target) {
std::thread(&NodePanelBrushPreset::import_ppbr, app->presets, path).detach();
target->destroy();
};
}
void open_project_now(const pp::app::DocumentOpenRoute& route) override
{
open_legacy_project(app_, route);
}
void prompt_discard_unsaved_project(const pp::app::DocumentOpenRoute& route) override
{
auto* app = &app_;
auto mb = app_.message_box(
"Unsaved document",
"Do you want to close the unsaved document before opening the file?",
true);
mb->on_submit = [app, route](Node* target) {
open_legacy_project(*app, route);
target->destroy();
};
}
private:
App& app_;
};
} // namespace
pp::foundation::Status execute_legacy_document_open_plan(
App& app,
pp::app::DocumentOpenPlanAction action,
const pp::app::DocumentOpenRoute& route)
{
LegacyDocumentOpenServices services(app);
return pp::app::execute_document_open_plan(action, route, services);
}
} // namespace pp::panopainter