Centralize legacy brush package import
This commit is contained in:
56
src/app_core/brush_package_import.h
Normal file
56
src/app_core/brush_package_import.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace pp::app {
|
||||
|
||||
enum class BrushPackageImportKind {
|
||||
abr,
|
||||
ppbr,
|
||||
};
|
||||
|
||||
class BrushPackageImportServices {
|
||||
public:
|
||||
virtual ~BrushPackageImportServices() = default;
|
||||
|
||||
virtual void import_brush_package(BrushPackageImportKind kind, std::string_view path) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline const char* brush_package_import_kind_name(BrushPackageImportKind kind) noexcept
|
||||
{
|
||||
switch (kind) {
|
||||
case BrushPackageImportKind::abr:
|
||||
return "abr";
|
||||
case BrushPackageImportKind::ppbr:
|
||||
return "ppbr";
|
||||
}
|
||||
|
||||
return "abr";
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status validate_brush_package_import_path(std::string_view path) noexcept
|
||||
{
|
||||
if (path.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("brush package import path must not be empty");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_brush_package_import(
|
||||
BrushPackageImportKind kind,
|
||||
std::string_view path,
|
||||
BrushPackageImportServices& services)
|
||||
{
|
||||
const auto status = validate_brush_package_import_path(path);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
services.import_brush_package(kind, path);
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
} // namespace pp::app
|
||||
48
src/legacy_brush_package_import_services.cpp
Normal file
48
src/legacy_brush_package_import_services.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "legacy_brush_package_import_services.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "node_panel_brush.h"
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
class LegacyBrushPackageImportServices final : public pp::app::BrushPackageImportServices {
|
||||
public:
|
||||
explicit LegacyBrushPackageImportServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void import_brush_package(pp::app::BrushPackageImportKind kind, std::string_view path) override
|
||||
{
|
||||
auto presets = app_.presets;
|
||||
const auto path_string = std::string(path);
|
||||
if (kind == pp::app::BrushPackageImportKind::abr) {
|
||||
std::thread(&NodePanelBrushPreset::import_abr, presets, path_string).detach();
|
||||
return;
|
||||
}
|
||||
|
||||
std::thread(&NodePanelBrushPreset::import_ppbr, presets, path_string).detach();
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
pp::foundation::Status execute_legacy_brush_package_import(
|
||||
App& app,
|
||||
pp::app::BrushPackageImportKind kind,
|
||||
std::string_view path)
|
||||
{
|
||||
LegacyBrushPackageImportServices services(app);
|
||||
return pp::app::execute_brush_package_import(kind, path, services);
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
17
src/legacy_brush_package_import_services.h
Normal file
17
src/legacy_brush_package_import_services.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_core/brush_package_import.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class App;
|
||||
|
||||
namespace pp::panopainter {
|
||||
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_brush_package_import(
|
||||
App& app,
|
||||
pp::app::BrushPackageImportKind kind,
|
||||
std::string_view path);
|
||||
|
||||
} // namespace pp::panopainter
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "legacy_document_open_services.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "legacy_brush_package_import_services.h"
|
||||
#include "legacy_history_services.h"
|
||||
#include "log.h"
|
||||
#include "node_panel_brush.h"
|
||||
#include "node_panel_layer.h"
|
||||
|
||||
@@ -50,7 +52,12 @@ public:
|
||||
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();
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_import(
|
||||
*app,
|
||||
pp::app::BrushPackageImportKind::abr,
|
||||
path);
|
||||
if (!status.ok())
|
||||
LOG("ABR import failed: %s", status.message);
|
||||
target->destroy();
|
||||
};
|
||||
}
|
||||
@@ -60,7 +67,12 @@ public:
|
||||
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();
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_import(
|
||||
*app,
|
||||
pp::app::BrushPackageImportKind::ppbr,
|
||||
path);
|
||||
if (!status.ok())
|
||||
LOG("PPBR import failed: %s", status.message);
|
||||
target->destroy();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user