Plan save-as file writes in app core
This commit is contained in:
@@ -403,7 +403,8 @@ Known local toolchain state:
|
|||||||
states.
|
states.
|
||||||
- `pano_cli plan-document-file` exposes `pp_app_core` document-name
|
- `pano_cli plan-document-file` exposes `pp_app_core` document-name
|
||||||
validation, legacy `.ppi` path construction, and overwrite-prompt decisions
|
validation, legacy `.ppi` path construction, and overwrite-prompt decisions
|
||||||
as JSON and is covered for save-now and existing-target overwrite states.
|
as JSON through the same combined save-file plan consumed by the live save-as
|
||||||
|
dialog; it is covered for save-now and existing-target overwrite states.
|
||||||
- `pano_cli plan-document-version` exposes `pp_app_core` save-version suffix
|
- `pano_cli plan-document-version` exposes `pp_app_core` save-version suffix
|
||||||
parsing, candidate path generation, collision skipping, and no-slot failure
|
parsing, candidate path generation, collision skipping, and no-slot failure
|
||||||
behavior as JSON and is covered for first-version and existing-path skip
|
behavior as JSON and is covered for first-version and existing-path skip
|
||||||
@@ -426,8 +427,8 @@ Known local toolchain state:
|
|||||||
- `pp_app_core_document_session_tests` covers clean and dirty app session,
|
- `pp_app_core_document_session_tests` covers clean and dirty app session,
|
||||||
document-open action planning, save-request, save-before-workflow,
|
document-open action planning, save-request, save-before-workflow,
|
||||||
new-document target/resolution/overwrite planning, document file target,
|
new-document target/resolution/overwrite planning, document file target,
|
||||||
overwrite, and save-version target decisions without requiring a window,
|
combined save-file overwrite planning, and save-version target decisions
|
||||||
canvas, or message box.
|
without requiring a window, canvas, or message box.
|
||||||
- `pp_ui_core` consumes vcpkg tinyxml2 only when `PP_USE_VCPKG_TINYXML2=ON`
|
- `pp_ui_core` consumes vcpkg tinyxml2 only when `PP_USE_VCPKG_TINYXML2=ON`
|
||||||
through the vcpkg preset; default and Android validation still use the
|
through the vcpkg preset; default and Android validation still use the
|
||||||
retained vendored fallback tracked by DEBT-0012.
|
retained vendored fallback tracked by DEBT-0012.
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ same app-core new-document target, legacy resolution-index mapping, and
|
|||||||
overwrite decision used by the live new-document dialog, including invalid
|
overwrite decision used by the live new-document dialog, including invalid
|
||||||
resolution rejection. `pano_cli plan-document-file` exposes the same app-core
|
resolution rejection. `pano_cli plan-document-file` exposes the same app-core
|
||||||
document-name validation, legacy `.ppi` path construction, and overwrite
|
document-name validation, legacy `.ppi` path construction, and overwrite
|
||||||
prompt decision used by save-as dialogs.
|
prompt decision used by save-as dialogs through one combined save-file plan.
|
||||||
`pano_cli plan-document-version` exposes the save-version suffix parsing,
|
`pano_cli plan-document-version` exposes the save-version suffix parsing,
|
||||||
candidate generation, collision skipping, and no-slot failure behavior used by
|
candidate generation, collision skipping, and no-slot failure behavior used by
|
||||||
the live save-version dialog.
|
the live save-version dialog.
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ struct DocumentVersionTarget {
|
|||||||
std::string path;
|
std::string path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DocumentFileSavePlan {
|
||||||
|
DocumentFileTarget target;
|
||||||
|
DocumentFileWriteDecision write_decision = DocumentFileWriteDecision::save_now;
|
||||||
|
};
|
||||||
|
|
||||||
struct NewDocumentPlan {
|
struct NewDocumentPlan {
|
||||||
DocumentFileTarget target;
|
DocumentFileTarget target;
|
||||||
int resolution = 0;
|
int resolution = 0;
|
||||||
@@ -182,6 +187,23 @@ struct NewDocumentPlan {
|
|||||||
: DocumentFileWriteDecision::save_now;
|
: DocumentFileWriteDecision::save_now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ExistsPredicate>
|
||||||
|
[[nodiscard]] pp::foundation::Result<DocumentFileSavePlan> plan_document_file_save(
|
||||||
|
std::string_view work_directory,
|
||||||
|
std::string_view document_name,
|
||||||
|
ExistsPredicate&& exists)
|
||||||
|
{
|
||||||
|
auto target = make_document_file_target(work_directory, document_name);
|
||||||
|
if (!target) {
|
||||||
|
return pp::foundation::Result<DocumentFileSavePlan>::failure(target.status());
|
||||||
|
}
|
||||||
|
|
||||||
|
DocumentFileSavePlan plan;
|
||||||
|
plan.target = std::move(target.value());
|
||||||
|
plan.write_decision = plan_document_file_write(exists(plan.target.path));
|
||||||
|
return pp::foundation::Result<DocumentFileSavePlan>::success(std::move(plan));
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr pp::foundation::Result<int> document_resolution_from_index(int index) noexcept
|
[[nodiscard]] constexpr pp::foundation::Result<int> document_resolution_from_index(int index) noexcept
|
||||||
{
|
{
|
||||||
constexpr std::array<int, 6> resolutions{ 512, 1024, 1536, 2048, 4096, 8192 };
|
constexpr std::array<int, 6> resolutions{ 512, 1024, 1536, 2048, 4096, 8192 };
|
||||||
@@ -205,15 +227,18 @@ template <typename ExistsPredicate>
|
|||||||
return pp::foundation::Result<NewDocumentPlan>::failure(resolution.status());
|
return pp::foundation::Result<NewDocumentPlan>::failure(resolution.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto target = make_document_file_target(work_directory, document_name);
|
auto save_plan = plan_document_file_save(
|
||||||
if (!target) {
|
work_directory,
|
||||||
return pp::foundation::Result<NewDocumentPlan>::failure(target.status());
|
document_name,
|
||||||
|
std::forward<ExistsPredicate>(exists));
|
||||||
|
if (!save_plan) {
|
||||||
|
return pp::foundation::Result<NewDocumentPlan>::failure(save_plan.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
NewDocumentPlan plan;
|
NewDocumentPlan plan;
|
||||||
plan.target = std::move(target.value());
|
plan.target = std::move(save_plan.value().target);
|
||||||
plan.resolution = resolution.value();
|
plan.resolution = resolution.value();
|
||||||
plan.write_decision = plan_document_file_write(exists(plan.target.path));
|
plan.write_decision = save_plan.value().write_decision;
|
||||||
return pp::foundation::Result<NewDocumentPlan>::success(std::move(plan));
|
return pp::foundation::Result<NewDocumentPlan>::success(std::move(plan));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -361,32 +361,36 @@ void App::dialog_save()
|
|||||||
dialog->btn_ok->on_click = [this, dialog](Node*)
|
dialog->btn_ok->on_click = [this, dialog](Node*)
|
||||||
{
|
{
|
||||||
std::string name = dialog->input->m_text;
|
std::string name = dialog->input->m_text;
|
||||||
const auto target = pp::app::make_document_file_target(work_path, name);
|
const auto plan = pp::app::plan_document_file_save(
|
||||||
if (!target)
|
work_path,
|
||||||
|
name,
|
||||||
|
[](const std::string& path) {
|
||||||
|
return Asset::exist(path);
|
||||||
|
});
|
||||||
|
if (!plan)
|
||||||
{
|
{
|
||||||
message_box("Warning", "You need to specify a name to file.");
|
message_box("Warning", "You need to specify a name to file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto action = [this, dialog, target = target.value()] {
|
auto action = [this, dialog, plan = plan.value()] {
|
||||||
canvas->m_canvas->project_save(target.path);
|
canvas->m_canvas->project_save(plan.target.path);
|
||||||
doc_name = target.name;
|
doc_name = plan.target.name;
|
||||||
doc_path = target.path;
|
doc_path = plan.target.path;
|
||||||
doc_dir = target.directory;
|
doc_dir = plan.target.directory;
|
||||||
title_update();
|
title_update();
|
||||||
dialog->destroy();
|
dialog->destroy();
|
||||||
App::I->hideKeyboard();
|
App::I->hideKeyboard();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto write_decision = pp::app::plan_document_file_write(Asset::exist(target.value().path));
|
if (plan.value().write_decision == pp::app::DocumentFileWriteDecision::prompt_overwrite)
|
||||||
if (write_decision == pp::app::DocumentFileWriteDecision::prompt_overwrite)
|
|
||||||
{
|
{
|
||||||
// ask confirm is file already exist
|
// ask confirm is file already exist
|
||||||
auto msgbox = new NodeMessageBox();
|
auto msgbox = new NodeMessageBox();
|
||||||
msgbox->set_manager(&layout);
|
msgbox->set_manager(&layout);
|
||||||
msgbox->init();
|
msgbox->init();
|
||||||
msgbox->m_title->set_text("Warning");
|
msgbox->m_title->set_text("Warning");
|
||||||
msgbox->m_message->set_text(("Are you sure you want to overwrite " + target.value().name + "?").c_str());
|
msgbox->m_message->set_text(("Are you sure you want to overwrite " + plan.value().target.name + "?").c_str());
|
||||||
msgbox->btn_ok->on_click = [this, msgbox, action](Node*) {
|
msgbox->btn_ok->on_click = [this, msgbox, action](Node*) {
|
||||||
action();
|
action();
|
||||||
msgbox->destroy();
|
msgbox->destroy();
|
||||||
|
|||||||
@@ -175,6 +175,33 @@ void document_file_write_prompts_only_for_existing_targets(pp::tests::Harness& h
|
|||||||
== pp::app::DocumentFileWriteDecision::prompt_overwrite);
|
== pp::app::DocumentFileWriteDecision::prompt_overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void document_file_save_plan_combines_target_and_write_decision(pp::tests::Harness& harness)
|
||||||
|
{
|
||||||
|
const auto plan = pp::app::plan_document_file_save(
|
||||||
|
"D:/Paint",
|
||||||
|
"demo",
|
||||||
|
[](const std::string& path) {
|
||||||
|
return path == "D:/Paint/demo.ppi";
|
||||||
|
});
|
||||||
|
PP_EXPECT(harness, plan);
|
||||||
|
PP_EXPECT(harness, plan.value().target.name == "demo");
|
||||||
|
PP_EXPECT(harness, plan.value().target.directory == "D:/Paint");
|
||||||
|
PP_EXPECT(harness, plan.value().target.path == "D:/Paint/demo.ppi");
|
||||||
|
PP_EXPECT(
|
||||||
|
harness,
|
||||||
|
plan.value().write_decision == pp::app::DocumentFileWriteDecision::prompt_overwrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
void document_file_save_plan_rejects_empty_name(pp::tests::Harness& harness)
|
||||||
|
{
|
||||||
|
const auto plan = pp::app::plan_document_file_save(
|
||||||
|
"D:/Paint",
|
||||||
|
"",
|
||||||
|
[](const std::string&) { return false; });
|
||||||
|
PP_EXPECT(harness, !plan);
|
||||||
|
PP_EXPECT(harness, plan.status().code == pp::foundation::StatusCode::invalid_argument);
|
||||||
|
}
|
||||||
|
|
||||||
void document_resolution_index_maps_legacy_choices(pp::tests::Harness& harness)
|
void document_resolution_index_maps_legacy_choices(pp::tests::Harness& harness)
|
||||||
{
|
{
|
||||||
const auto first = pp::app::document_resolution_from_index(0);
|
const auto first = pp::app::document_resolution_from_index(0);
|
||||||
@@ -320,6 +347,10 @@ int main()
|
|||||||
harness.run("document file target rejects empty name", document_file_target_rejects_empty_name);
|
harness.run("document file target rejects empty name", document_file_target_rejects_empty_name);
|
||||||
harness.run("document file target builds legacy ppi path", document_file_target_builds_legacy_ppi_path);
|
harness.run("document file target builds legacy ppi path", document_file_target_builds_legacy_ppi_path);
|
||||||
harness.run("document file write prompts only for existing targets", document_file_write_prompts_only_for_existing_targets);
|
harness.run("document file write prompts only for existing targets", document_file_write_prompts_only_for_existing_targets);
|
||||||
|
harness.run(
|
||||||
|
"document file save plan combines target and write decision",
|
||||||
|
document_file_save_plan_combines_target_and_write_decision);
|
||||||
|
harness.run("document file save plan rejects empty name", document_file_save_plan_rejects_empty_name);
|
||||||
harness.run("document resolution index maps legacy choices", document_resolution_index_maps_legacy_choices);
|
harness.run("document resolution index maps legacy choices", document_resolution_index_maps_legacy_choices);
|
||||||
harness.run("document resolution index rejects out of range", document_resolution_index_rejects_out_of_range);
|
harness.run("document resolution index rejects out of range", document_resolution_index_rejects_out_of_range);
|
||||||
harness.run(
|
harness.run(
|
||||||
|
|||||||
@@ -1345,20 +1345,24 @@ int plan_document_file(int argc, char** argv)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto target = pp::app::make_document_file_target(args.work_directory, args.name);
|
const auto plan = pp::app::plan_document_file_save(
|
||||||
if (!target) {
|
args.work_directory,
|
||||||
print_error("plan-document-file", target.status().message);
|
args.name,
|
||||||
|
[&args](const std::string&) {
|
||||||
|
return args.target_exists;
|
||||||
|
});
|
||||||
|
if (!plan) {
|
||||||
|
print_error("plan-document-file", plan.status().message);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto write_decision = pp::app::plan_document_file_write(args.target_exists);
|
|
||||||
std::cout << "{\"ok\":true,\"command\":\"plan-document-file\""
|
std::cout << "{\"ok\":true,\"command\":\"plan-document-file\""
|
||||||
<< ",\"target\":{\"name\":\"" << json_escape(target.value().name)
|
<< ",\"target\":{\"name\":\"" << json_escape(plan.value().target.name)
|
||||||
<< "\",\"directory\":\"" << json_escape(target.value().directory)
|
<< "\",\"directory\":\"" << json_escape(plan.value().target.directory)
|
||||||
<< "\",\"path\":\"" << json_escape(target.value().path)
|
<< "\",\"path\":\"" << json_escape(plan.value().target.path)
|
||||||
<< "\",\"exists\":" << json_bool(args.target_exists)
|
<< "\",\"exists\":" << json_bool(args.target_exists)
|
||||||
<< "},\"decision\":\""
|
<< "},\"decision\":\""
|
||||||
<< document_file_write_decision_name(write_decision)
|
<< document_file_write_decision_name(plan.value().write_decision)
|
||||||
<< "\"}\n";
|
<< "\"}\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user