Centralize legacy brush package export
This commit is contained in:
63
src/app_core/brush_package_export.h
Normal file
63
src/app_core/brush_package_export.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace pp::app {
|
||||
|
||||
struct BrushPackageExportRequest {
|
||||
std::string author;
|
||||
std::string email;
|
||||
std::string url;
|
||||
std::string description;
|
||||
std::string destination_path;
|
||||
bool export_data = false;
|
||||
bool has_header_image = false;
|
||||
};
|
||||
|
||||
class BrushPackageExportServices {
|
||||
public:
|
||||
virtual ~BrushPackageExportServices() = default;
|
||||
|
||||
virtual void export_brush_package(std::string_view path, const BrushPackageExportRequest& request) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status validate_brush_package_export_path(std::string_view path) noexcept
|
||||
{
|
||||
if (path.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("brush package export path must not be empty");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status validate_brush_package_export_request(
|
||||
std::string_view path,
|
||||
const BrushPackageExportRequest& request) noexcept
|
||||
{
|
||||
(void)request;
|
||||
const auto path_status = validate_brush_package_export_path(path);
|
||||
if (!path_status.ok()) {
|
||||
return path_status;
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_brush_package_export(
|
||||
std::string_view path,
|
||||
const BrushPackageExportRequest& request,
|
||||
BrushPackageExportServices& services)
|
||||
{
|
||||
const auto status = validate_brush_package_export_request(path, request);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
services.export_brush_package(path, request);
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
} // namespace pp::app
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "app_core/document_export.h"
|
||||
#include "app_core/document_session.h"
|
||||
#include "legacy_document_canvas_services.h"
|
||||
#include "legacy_brush_package_export_services.h"
|
||||
#include "legacy_document_export_services.h"
|
||||
#include "legacy_document_layer_services.h"
|
||||
#include "legacy_document_session_services.h"
|
||||
@@ -520,33 +521,34 @@ void App::dialog_ppbr_export()
|
||||
auto root = layout[main_id];
|
||||
auto dialog = root->add_child_ref<NodeDialogExportPPBR>();
|
||||
dialog->btn_ok->on_click = [this, dialog] (Node*) {
|
||||
NodePanelBrushPreset::PPBRInfo info;
|
||||
info.author = dialog->txt_author->m_text;
|
||||
info.url = dialog->txt_url->m_text;
|
||||
info.email = dialog->txt_email->m_text;
|
||||
info.descr = dialog->txt_descr->m_text;
|
||||
info.header_image = dialog->m_header_image;
|
||||
info.dest_path = dialog->m_dest_path;
|
||||
if (dialog->export_check)
|
||||
info.export_data = dialog->export_check->checked;
|
||||
const auto request = pp::panopainter::make_legacy_brush_package_export_request(*dialog);
|
||||
#if __IOS__ || __WEB__
|
||||
App::I->pick_file_save("ppbr", "exported-brushes",
|
||||
[this, dialog, info] (std::string path) {
|
||||
presets->export_ppbr(path, info);
|
||||
[this, dialog, request] (std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_export(
|
||||
*this,
|
||||
*dialog,
|
||||
request,
|
||||
path,
|
||||
pp::panopainter::LegacyBrushPackageExportMode::inline_export_only);
|
||||
if (!status.ok())
|
||||
LOG("PPBR export failed: %s", status.message);
|
||||
},
|
||||
[dialog] (const std::string& path, bool saved) {
|
||||
if (saved)
|
||||
dialog->destroy();
|
||||
(void)path;
|
||||
pp::panopainter::complete_legacy_brush_package_export(*dialog, saved);
|
||||
}
|
||||
);
|
||||
#else
|
||||
App::I->pick_file_save({ "ppbr" }, [this, dialog, info] (std::string path) {
|
||||
std::thread([this, path, dialog, info] {
|
||||
BT_SetTerminate();
|
||||
presets->export_ppbr(path, info);
|
||||
dialog->destroy();
|
||||
App::I->message_box("Export PPBR", "Brushes exported to:\n" + path);
|
||||
}).detach();
|
||||
App::I->pick_file_save({ "ppbr" }, [this, dialog, request] (std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_export(
|
||||
*this,
|
||||
*dialog,
|
||||
request,
|
||||
path,
|
||||
pp::panopainter::LegacyBrushPackageExportMode::desktop_async_close_and_message);
|
||||
if (!status.ok())
|
||||
LOG("PPBR export failed: %s", status.message);
|
||||
});
|
||||
#endif
|
||||
};
|
||||
|
||||
100
src/legacy_brush_package_export_services.cpp
Normal file
100
src/legacy_brush_package_export_services.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "legacy_brush_package_export_services.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "node_dialog_export_ppbr.h"
|
||||
#include "node_panel_brush.h"
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
NodePanelBrushPreset::PPBRInfo to_legacy_ppbr_info(
|
||||
const pp::app::BrushPackageExportRequest& request,
|
||||
const NodeDialogExportPPBR& dialog)
|
||||
{
|
||||
NodePanelBrushPreset::PPBRInfo info;
|
||||
info.author = request.author;
|
||||
info.email = request.email;
|
||||
info.url = request.url;
|
||||
info.descr = request.description;
|
||||
info.header_image = dialog.m_header_image;
|
||||
info.export_data = request.export_data;
|
||||
info.dest_path = request.destination_path;
|
||||
return info;
|
||||
}
|
||||
|
||||
class LegacyBrushPackageExportServices final : public pp::app::BrushPackageExportServices {
|
||||
public:
|
||||
LegacyBrushPackageExportServices(
|
||||
App& app,
|
||||
NodeDialogExportPPBR& dialog,
|
||||
LegacyBrushPackageExportMode mode) noexcept
|
||||
: app_(app)
|
||||
, dialog_(dialog)
|
||||
, mode_(mode)
|
||||
{
|
||||
}
|
||||
|
||||
void export_brush_package(std::string_view path, const pp::app::BrushPackageExportRequest& request) override
|
||||
{
|
||||
const auto path_string = std::string(path);
|
||||
const auto info = to_legacy_ppbr_info(request, dialog_);
|
||||
if (mode_ == LegacyBrushPackageExportMode::desktop_async_close_and_message) {
|
||||
auto* app = &app_;
|
||||
auto* dialog = &dialog_;
|
||||
std::thread([app, dialog, path_string, info] {
|
||||
BT_SetTerminate();
|
||||
app->presets->export_ppbr(path_string, info);
|
||||
dialog->destroy();
|
||||
app->message_box("Export PPBR", "Brushes exported to:\n" + path_string);
|
||||
}).detach();
|
||||
return;
|
||||
}
|
||||
|
||||
app_.presets->export_ppbr(path_string, info);
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
NodeDialogExportPPBR& dialog_;
|
||||
LegacyBrushPackageExportMode mode_ = LegacyBrushPackageExportMode::inline_export_only;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
pp::app::BrushPackageExportRequest make_legacy_brush_package_export_request(const NodeDialogExportPPBR& dialog)
|
||||
{
|
||||
pp::app::BrushPackageExportRequest request;
|
||||
request.author = dialog.txt_author ? dialog.txt_author->m_text : std::string();
|
||||
request.email = dialog.txt_email ? dialog.txt_email->m_text : std::string();
|
||||
request.url = dialog.txt_url ? dialog.txt_url->m_text : std::string();
|
||||
request.description = dialog.txt_descr ? dialog.txt_descr->m_text : std::string();
|
||||
request.destination_path = dialog.m_dest_path;
|
||||
request.export_data = dialog.export_check && dialog.export_check->checked;
|
||||
request.has_header_image = static_cast<bool>(dialog.m_header_image);
|
||||
return request;
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_brush_package_export(
|
||||
App& app,
|
||||
NodeDialogExportPPBR& dialog,
|
||||
const pp::app::BrushPackageExportRequest& request,
|
||||
std::string_view path,
|
||||
LegacyBrushPackageExportMode mode)
|
||||
{
|
||||
LegacyBrushPackageExportServices services(app, dialog, mode);
|
||||
return pp::app::execute_brush_package_export(path, request, services);
|
||||
}
|
||||
|
||||
void complete_legacy_brush_package_export(NodeDialogExportPPBR& dialog, bool saved)
|
||||
{
|
||||
if (saved) {
|
||||
dialog.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
30
src/legacy_brush_package_export_services.h
Normal file
30
src/legacy_brush_package_export_services.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_core/brush_package_export.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class App;
|
||||
class NodeDialogExportPPBR;
|
||||
|
||||
namespace pp::panopainter {
|
||||
|
||||
enum class LegacyBrushPackageExportMode {
|
||||
inline_export_only,
|
||||
desktop_async_close_and_message,
|
||||
};
|
||||
|
||||
[[nodiscard]] pp::app::BrushPackageExportRequest make_legacy_brush_package_export_request(
|
||||
const NodeDialogExportPPBR& dialog);
|
||||
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_brush_package_export(
|
||||
App& app,
|
||||
NodeDialogExportPPBR& dialog,
|
||||
const pp::app::BrushPackageExportRequest& request,
|
||||
std::string_view path,
|
||||
LegacyBrushPackageExportMode mode);
|
||||
|
||||
void complete_legacy_brush_package_export(NodeDialogExportPPBR& dialog, bool saved);
|
||||
|
||||
} // namespace pp::panopainter
|
||||
Reference in New Issue
Block a user