diff --git a/CMakeLists.txt b/CMakeLists.txt index 5059ea8..d110f26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,6 +227,7 @@ add_library(pp_app_core STATIC src/app_core/app_status.h src/app_core/document_cloud.h src/app_core/document_export.cpp + src/app_core/document_layer.h src/app_core/document_platform_io.h src/app_core/document_recording.h src/app_core/document_resize.h diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 30d1ca9..06e3433 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -22,7 +22,7 @@ agent or engineer to remove them without reconstructing context from chat. | --- | --- | --- | --- | --- | --- | --- | | DEBT-0001 | Open | Modernization | Existing platform build files remain alongside new CMake | Required for incremental migration without losing platform coverage | Existing platform builds plus new CMake configure | Remove after all platform builds consume shared CMake targets | | DEBT-0002 | Open | Modernization | Vendored SDK and patched libraries retained initially | Some dependencies are SDK-only, patched, or have platform-specific binaries | Dependency inventory and platform build smoke tests | Replace with vcpkg packages or document permanent vendored status after triplet evaluation | -| DEBT-0003 | Open | Modernization | Existing singletons remain during initial split; `App::open_document`, `App::request_close`, `App::share_file`, `App::cloud_upload`, `App::cloud_upload_all`, `App::cloud_browse`, `App::rec_start`, `App::rec_stop`, `App::rec_clear`, `App::rec_export`, file-menu save actions, `NodeCanvas` save hotkeys, new/open/browse dirty-document workflow prompts, new-document target/resolution/overwrite decisions, save-as document file naming and overwrite decisions, save-version target decisions, export start/target naming/path decisions, share-file saved-path decisions, file/image/save/directory picker selected-path decisions, display-file external-open decisions, virtual-keyboard visibility decisions, recording lifecycle/export progress decisions, cloud-upload prompt/save-before-upload decisions, cloud-browse availability and selected-download decisions, bulk cloud-upload progress decisions, tools/options app preference decisions, app status/display decisions, `pano_cli classify-open`, `pano_cli plan-open-route`, `pano_cli plan-new-document`, `pano_cli plan-document-file`, `pano_cli plan-document-version`, `pano_cli plan-export-start`, `pano_cli plan-export-target`, `pano_cli plan-recording-session`, `pano_cli plan-app-preferences`, `pano_cli plan-app-status`, `pano_cli plan-share-file`, `pano_cli plan-picked-path`, `pano_cli plan-display-file`, `pano_cli plan-keyboard-visibility`, `pano_cli plan-cloud-upload`, `pano_cli plan-cloud-browse`, `pano_cli plan-cloud-upload-all`, and `pano_cli simulate-app-session` now consume pure `pp_app_core` route/session/export/recording/preferences/status/share/platform-I/O/display/keyboard/cloud contracts, but document creation/loading, brush import execution, saving, export execution, tools/options UI execution, status/display UI rendering, settings persistence, platform share service execution, picker service execution, display-file service execution, keyboard service execution, recording/MP4 execution, cloud upload execution, and cloud browse/download execution still reach legacy `Canvas::I`/UI/network/video/platform singletons | Avoid behavior changes while introducing component boundaries | App launch and component tests; `pp_app_core_document_route_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_recording_tests`; `pp_app_core_app_preferences_tests`; `pp_app_core_app_status_tests`; `pp_app_core_document_sharing_tests`; `pp_app_core_document_platform_io_tests`; `pp_app_core_document_cloud_tests`; `pp_app_core_document_session_tests`; `pano_cli classify-open --path D:/Paint/demo.ppi`; `pano_cli plan-open-route --path D:/Paint/demo.ppi --unsaved`; `pano_cli plan-new-document --work-dir D:/Paint --name demo --resolution-index 3 --target-exists`; `pano_cli plan-document-file --work-dir D:/Paint --name demo --target-exists`; `pano_cli plan-document-version --directory D:/Paint --doc-name demo.01 --existing-path D:/Paint/demo.02.ppi`; `pano_cli plan-export-start --requires-license --demo`; `pano_cli plan-export-target --kind file --work-dir D:/Paint --doc-name demo --extension .png`; `pano_cli plan-recording-session --running --frame-count 12`; `pano_cli plan-app-preferences --ui-scale 1.5 --display-density 2 --current-scale 1.6 --scale-option 1 --scale-option 1.5 --rtl`; `pano_cli plan-app-status --doc-name demo --unsaved --resolution 2048 --resolution-index 3 --zoom 1.25 --history-bytes 1572864 --recording-running --encoder-available --encoded-frames 12`; `pano_cli plan-share-file --path D:/Paint/demo.ppi`; `pano_cli plan-picked-path --path D:/Paint/demo.ppi`; `pano_cli plan-display-file --path D:/Paint/export.png`; `pano_cli plan-keyboard-visibility --visible`; `pano_cli plan-cloud-upload --new-document --unsaved`; `pano_cli plan-cloud-browse --selected-file demo.ppi`; `pano_cli plan-cloud-upload-all --file-count 3`; `pano_cli simulate-app-session --unsaved --save-intent save-dirty-version`; `pano_cli simulate-app-session --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | Replace singleton reaches with context/service injection at component boundaries | +| DEBT-0003 | Open | Modernization | Existing singletons remain during initial split; `App::open_document`, `App::request_close`, `App::share_file`, `App::cloud_upload`, `App::cloud_upload_all`, `App::cloud_browse`, `App::rec_start`, `App::rec_stop`, `App::rec_clear`, `App::rec_export`, file-menu save actions, `NodeCanvas` save hotkeys, new/open/browse dirty-document workflow prompts, new-document target/resolution/overwrite decisions, save-as document file naming and overwrite decisions, save-version target decisions, export start/target naming/path decisions, share-file saved-path decisions, file/image/save/directory picker selected-path decisions, display-file external-open decisions, virtual-keyboard visibility decisions, recording lifecycle/export progress decisions, cloud-upload prompt/save-before-upload decisions, cloud-browse availability and selected-download decisions, bulk cloud-upload progress decisions, tools/options app preference decisions, app status/display decisions, document resize decisions, layer rename decisions, `pano_cli classify-open`, `pano_cli plan-open-route`, `pano_cli plan-new-document`, `pano_cli plan-document-file`, `pano_cli plan-document-version`, `pano_cli plan-export-start`, `pano_cli plan-export-target`, `pano_cli plan-recording-session`, `pano_cli plan-app-preferences`, `pano_cli plan-app-status`, `pano_cli plan-document-resize`, `pano_cli plan-layer-rename`, `pano_cli plan-share-file`, `pano_cli plan-picked-path`, `pano_cli plan-display-file`, `pano_cli plan-keyboard-visibility`, `pano_cli plan-cloud-upload`, `pano_cli plan-cloud-browse`, `pano_cli plan-cloud-upload-all`, and `pano_cli simulate-app-session` now consume pure `pp_app_core` route/session/export/recording/preferences/status/share/platform-I/O/display/keyboard/cloud/resize/layer contracts, but document creation/loading, brush import execution, saving, export execution, tools/options UI execution, status/display UI rendering, document resize execution, layer rename execution, settings persistence, platform share service execution, picker service execution, display-file service execution, keyboard service execution, recording/MP4 execution, cloud upload execution, and cloud browse/download execution still reach legacy `Canvas::I`/UI/network/video/platform singletons | Avoid behavior changes while introducing component boundaries | App launch and component tests; `pp_app_core_document_route_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_recording_tests`; `pp_app_core_app_preferences_tests`; `pp_app_core_app_status_tests`; `pp_app_core_document_resize_tests`; `pp_app_core_document_layer_tests`; `pp_app_core_document_sharing_tests`; `pp_app_core_document_platform_io_tests`; `pp_app_core_document_cloud_tests`; `pp_app_core_document_session_tests`; `pano_cli classify-open --path D:/Paint/demo.ppi`; `pano_cli plan-open-route --path D:/Paint/demo.ppi --unsaved`; `pano_cli plan-new-document --work-dir D:/Paint --name demo --resolution-index 3 --target-exists`; `pano_cli plan-document-file --work-dir D:/Paint --name demo --target-exists`; `pano_cli plan-document-version --directory D:/Paint --doc-name demo.01 --existing-path D:/Paint/demo.02.ppi`; `pano_cli plan-export-start --requires-license --demo`; `pano_cli plan-export-target --kind file --work-dir D:/Paint --doc-name demo --extension .png`; `pano_cli plan-recording-session --running --frame-count 12`; `pano_cli plan-app-preferences --ui-scale 1.5 --display-density 2 --current-scale 1.6 --scale-option 1 --scale-option 1.5 --rtl`; `pano_cli plan-app-status --doc-name demo --unsaved --resolution 2048 --resolution-index 3 --zoom 1.25 --history-bytes 1572864 --recording-running --encoder-available --encoded-frames 12`; `pano_cli plan-document-resize --current-resolution 2048 --selected-resolution-index 4`; `pano_cli plan-layer-rename --old-name Base --new-name Paint`; `pano_cli plan-share-file --path D:/Paint/demo.ppi`; `pano_cli plan-picked-path --path D:/Paint/demo.ppi`; `pano_cli plan-display-file --path D:/Paint/export.png`; `pano_cli plan-keyboard-visibility --visible`; `pano_cli plan-cloud-upload --new-document --unsaved`; `pano_cli plan-cloud-browse --selected-file demo.ppi`; `pano_cli plan-cloud-upload-all --file-count 3`; `pano_cli simulate-app-session --unsaved --save-intent save-dirty-version`; `pano_cli simulate-app-session --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | Replace singleton reaches with context/service injection at component boundaries | | DEBT-0004 | Open | Modernization | Android, Linux, WebGL, Apple, and AppX build files remain platform-specific until root CMake alignment reaches them | Prevent platform regressions during incremental migration; raw Windows `.sln/.vcxproj` files were removed on 2026-05-31 by user decision | `cmake --preset windows-msvc-default`; platform-specific configure/build smoke checks as each platform is migrated | Root CMake owns every platform source list and package path | | DEBT-0005 | Open | Modernization | Temporary local CTest harness is used before Catch2 is wired through vcpkg | `vcpkg` is not currently on PATH, but headless tests need to run now | `ctest --preset desktop-fast --build-config Debug` | Replace `tests/test_harness.h` tests with Catch2 tests once vcpkg toolchain/presets are validated | | DEBT-0007 | Open | Modernization | `vcpkg.json` and `windows-msvc-vcpkg-headless` are validated for the headless Windows component matrix, but app targets still use vendored libraries and Android/Apple triplets are not proven | Dependency migration must stay incremental while SDK/patched/vendor dependencies remain in use | `$env:VCPKG_ROOT="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg"; cmake --preset windows-msvc-vcpkg-headless`; `ctest --preset desktop-fast-vcpkg --build-config Debug` | Component targets consume vcpkg packages where reliable and desktop app, Android, and Apple triplets are validated or explicitly documented as permanent vendor exceptions | @@ -38,6 +38,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0017 | Open | Modernization | Startup storage path preparation, `App::clipboard_get_text`, `App::clipboard_set_text`, `App::show_cursor`, `App::hide_cursor`, `App::showKeyboard`, `App::hideKeyboard`, `App::display_file`, `App::share_file`, native app/window close, UI-thread lifecycle hooks, render-context acquire/release/present hooks, render-target binding hooks, render platform hint hooks, render debug callback hooks, render-capture frame hooks, recording cleanup, live asset/layout reload policy, diagnostic stacktrace/crash hooks, per-frame platform hooks, `App::pick_image`, `App::pick_file`, the non-writer `App::pick_file_save`, `App::pick_dir`, and prepared-file save/download handoff now call the SDK-free `pp::platform::PlatformServices` interface, and Windows injects `WindowsPlatformServices` from `src/platform_windows/windows_platform_services.*`; non-Windows live implementations still use `src/platform_legacy/legacy_platform_services.*`, a named fallback adapter that forwards to retained Apple/Android/Linux/Web bridge functions and retained no-op branches | Preserve behavior while moving platform execution behind a testable service boundary before platform shell implementations are injected | `pp_platform_api_tests`; `pp_app_core_document_platform_io_tests`; `ctest --preset desktop-fast --build-config Debug`; `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -Preset windows-msvc-default -Configuration Debug` | Replace `src/platform_legacy/legacy_platform_services.*` with injected `pp_platform_*` service implementations owned by each non-Windows platform shell | | DEBT-0019 | Open | Modernization | MSVC warning C4100 is muted globally through `pp_project_warnings` with `/wd4100` | Legacy callbacks, virtual hooks, serializer methods, and platform/API compatibility functions carry many intentionally unused parameters during the component split; muting this keeps stricter warning builds focused on higher-signal migration issues | `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter`; `ctest --preset desktop-fast --build-config Debug` | Remove `/wd4100`, mark intentionally unused parameters with names/comments or `[[maybe_unused]]`, and make the Windows app and headless tests pass without C4100 warnings | | DEBT-0020 | Open | Modernization | Document resize dialog state and selected-resolution planning now consume pure `pp_app_core` through `NodeDialogResize`, `App::dialog_resize`, and `pano_cli plan-document-resize`, but live resize execution still calls legacy `Canvas::resize` and clears legacy `ActionManager` history directly | Preserve existing layer/frame GPU resize behavior while the document model and canvas execution boundary are extracted incrementally | `pp_app_core_document_resize_tests`; `pano_cli plan-document-resize --current-resolution 2048 --selected-resolution-index 4`; `ctest --preset desktop-fast --build-config Debug` | Document resize execution is owned by a document/app boundary with legacy `Canvas` acting only as an adapter or removed entirely | +| DEBT-0021 | Open | Modernization | Layer rename planning now consumes pure `pp_app_core` through `App::dialog_layer_rename` and `pano_cli plan-layer-rename`, but live rename execution still mutates legacy `Canvas` layer state, `NodeLayer`, and `ActionManager` undo entries directly | Preserve existing UI/canvas behavior while document layer commands and undo history are extracted incrementally | `pp_app_core_document_layer_tests`; `pano_cli plan-layer-rename --old-name Base --new-name Paint`; `ctest --preset desktop-fast --build-config Debug` | Layer rename execution is owned by the document/app command boundary with legacy `Canvas`/UI nodes acting only as adapters or removed entirely | ## Closed Debt diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 1d10f49a..4637440 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -481,6 +481,9 @@ before retained platform clipboard bridges continue. `pano_cli plan-document-resize` exposes the app-core resize dialog state and selected-resolution commit plan used by the live document resize dialog before legacy `Canvas` resize execution and `ActionManager` history clearing continue. +`pano_cli plan-layer-rename` exposes the app-core layer rename decision used by +the live layer rename dialog before legacy `Canvas` layer mutation and +`ActionManager` undo wiring continue. `pp_platform_api` now owns a headless `PlatformServices` interface for startup storage path preparation, clipboard text, cursor visibility, virtual-keyboard visibility, UI-thread lifecycle hooks, render-context @@ -1087,6 +1090,12 @@ Results: - `pano_cli_plan_document_resize_smoke` and `pano_cli_plan_document_resize_rejects_invalid_selection` passed and expose live document-resize planning as JSON automation. +- `pp_app_core_document_layer_tests` passed, covering changed layer rename, + unchanged no-op rename, empty-name rejection, and overlong-name rejection. +- `pano_cli_plan_layer_rename_smoke`, + `pano_cli_plan_layer_rename_no_op_smoke`, and + `pano_cli_plan_layer_rename_rejects_empty_name` passed and expose live + layer-rename planning as JSON automation. - `pp_app_core_document_sharing_tests` passed, covering saved-path gating before platform share execution. - `pano_cli_plan_share_file_unsaved_smoke` and diff --git a/src/app_core/document_layer.h b/src/app_core/document_layer.h new file mode 100644 index 0000000..04b1155 --- /dev/null +++ b/src/app_core/document_layer.h @@ -0,0 +1,48 @@ +#pragma once + +#include "foundation/result.h" + +#include +#include +#include +#include + +namespace pp::app { + +inline constexpr std::size_t document_layer_name_max_length = 128; + +enum class DocumentLayerRenameAction { + no_op_same_name, + rename_and_record_undo, +}; + +struct DocumentLayerRenamePlan { + std::string old_name; + std::string new_name; + DocumentLayerRenameAction action = DocumentLayerRenameAction::no_op_same_name; +}; + +[[nodiscard]] inline pp::foundation::Result plan_document_layer_rename( + std::string_view old_name, + std::string_view requested_name) +{ + if (requested_name.empty()) { + return pp::foundation::Result::failure( + pp::foundation::Status::invalid_argument("layer name must not be empty")); + } + + if (requested_name.size() > document_layer_name_max_length) { + return pp::foundation::Result::failure( + pp::foundation::Status::out_of_range("layer name length exceeds the configured limit")); + } + + DocumentLayerRenamePlan plan; + plan.old_name = std::string(old_name); + plan.new_name = std::string(requested_name); + plan.action = old_name == requested_name + ? DocumentLayerRenameAction::no_op_same_name + : DocumentLayerRenameAction::rename_and_record_undo; + return pp::foundation::Result::success(std::move(plan)); +} + +} diff --git a/src/app_dialogs.cpp b/src/app_dialogs.cpp index 635f4ea..bfee383 100644 --- a/src/app_dialogs.cpp +++ b/src/app_dialogs.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "app.h" #include "action.h" +#include "app_core/document_layer.h" #include "app_core/document_resize.h" #include "app_core/document_export.h" #include "app_core/document_session.h" @@ -605,6 +606,17 @@ void App::dialog_layer_rename() dialog->btn_ok->on_click = [this,dialog](Node*) { + const auto old_name = layers->m_current_layer->m_label_text; + const auto plan = pp::app::plan_document_layer_rename(old_name, dialog->get_name()); + if (!plan) + return; + if (plan.value().action == pp::app::DocumentLayerRenameAction::no_op_same_name) + { + dialog->destroy(); + App::I->hideKeyboard(); + return; + } + struct ActionLayerRename : public Action { std::string m_old_name; @@ -628,9 +640,13 @@ void App::dialog_layer_rename() }; auto layer_node = std::static_pointer_cast(layers->m_current_layer->shared_from_this()); auto* layer = canvas->m_canvas->m_layers[canvas->m_canvas->m_current_layer_idx].get(); - ActionManager::add(new ActionLayerRename(layers->m_current_layer->m_label_text, dialog->get_name(), layer_node, layer)); - layer_node->set_name(dialog->get_name().c_str()); - layer->m_name = dialog->get_name(); + ActionManager::add(new ActionLayerRename( + plan.value().old_name, + plan.value().new_name, + layer_node, + layer)); + layer_node->set_name(plan.value().new_name.c_str()); + layer->m_name = plan.value().new_name; dialog->destroy(); App::I->hideKeyboard(); }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 50f1817..c499485 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -318,6 +318,16 @@ add_test(NAME pp_app_core_document_recording_tests COMMAND pp_app_core_document_ set_tests_properties(pp_app_core_document_recording_tests PROPERTIES LABELS "app;desktop-fast;fuzz") +add_executable(pp_app_core_document_layer_tests + app_core/document_layer_tests.cpp) +target_link_libraries(pp_app_core_document_layer_tests PRIVATE + pp_app_core + pp_test_harness) + +add_test(NAME pp_app_core_document_layer_tests COMMAND pp_app_core_document_layer_tests) +set_tests_properties(pp_app_core_document_layer_tests PROPERTIES + LABELS "app;desktop-fast;fuzz") + add_executable(pp_app_core_document_resize_tests app_core/document_resize_tests.cpp) target_link_libraries(pp_app_core_document_resize_tests PRIVATE @@ -690,6 +700,24 @@ if(TARGET pano_cli) LABELS "app;integration;desktop-fast;fuzz" WILL_FAIL TRUE) + add_test(NAME pano_cli_plan_layer_rename_smoke + COMMAND pano_cli plan-layer-rename --old-name Base --new-name Paint) + set_tests_properties(pano_cli_plan_layer_rename_smoke PROPERTIES + LABELS "app;integration;desktop-fast" + PASS_REGULAR_EXPRESSION "\"command\":\"plan-layer-rename\".*\"oldName\":\"Base\".*\"newName\":\"Paint\".*\"action\":\"rename-and-record-undo\"") + + add_test(NAME pano_cli_plan_layer_rename_no_op_smoke + COMMAND pano_cli plan-layer-rename --old-name Ink --new-name Ink) + set_tests_properties(pano_cli_plan_layer_rename_no_op_smoke PROPERTIES + LABELS "app;integration;desktop-fast" + PASS_REGULAR_EXPRESSION "\"command\":\"plan-layer-rename\".*\"oldName\":\"Ink\".*\"newName\":\"Ink\".*\"action\":\"no-op-same-name\"") + + add_test(NAME pano_cli_plan_layer_rename_rejects_empty_name + COMMAND pano_cli plan-layer-rename --old-name Ink --new-name "") + set_tests_properties(pano_cli_plan_layer_rename_rejects_empty_name PROPERTIES + LABELS "app;integration;desktop-fast;fuzz" + WILL_FAIL TRUE) + add_test(NAME pano_cli_plan_share_file_unsaved_smoke COMMAND pano_cli plan-share-file) set_tests_properties(pano_cli_plan_share_file_unsaved_smoke PROPERTIES diff --git a/tests/app_core/document_layer_tests.cpp b/tests/app_core/document_layer_tests.cpp new file mode 100644 index 0000000..d496ef9 --- /dev/null +++ b/tests/app_core/document_layer_tests.cpp @@ -0,0 +1,63 @@ +#include "app_core/document_layer.h" +#include "test_harness.h" + +#include + +namespace { + +void layer_rename_records_changed_name(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_document_layer_rename("Base", "Paint"); + PP_EXPECT(harness, plan); + if (plan) { + PP_EXPECT(harness, plan.value().old_name == "Base"); + PP_EXPECT(harness, plan.value().new_name == "Paint"); + PP_EXPECT( + harness, + plan.value().action == pp::app::DocumentLayerRenameAction::rename_and_record_undo); + } +} + +void layer_rename_ignores_unchanged_name(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_document_layer_rename("Ink", "Ink"); + PP_EXPECT(harness, plan); + if (plan) { + PP_EXPECT(harness, plan.value().old_name == "Ink"); + PP_EXPECT(harness, plan.value().new_name == "Ink"); + PP_EXPECT( + harness, + plan.value().action == pp::app::DocumentLayerRenameAction::no_op_same_name); + } +} + +void layer_rename_rejects_empty_name(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_document_layer_rename("Ink", ""); + PP_EXPECT(harness, !plan); + if (!plan) { + PP_EXPECT(harness, plan.status().code == pp::foundation::StatusCode::invalid_argument); + } +} + +void layer_rename_rejects_overlong_name(pp::tests::Harness& harness) +{ + const std::string too_long(pp::app::document_layer_name_max_length + 1U, 'x'); + const auto plan = pp::app::plan_document_layer_rename("Ink", too_long); + PP_EXPECT(harness, !plan); + if (!plan) { + PP_EXPECT(harness, plan.status().code == pp::foundation::StatusCode::out_of_range); + } +} + +} + +int main() +{ + pp::tests::Harness harness; + harness.run("layer rename records changed name", layer_rename_records_changed_name); + harness.run("layer rename ignores unchanged name", layer_rename_ignores_unchanged_name); + harness.run("layer rename rejects empty name", layer_rename_rejects_empty_name); + harness.run("layer rename rejects overlong name", layer_rename_rejects_overlong_name); + return harness.finish(); +} diff --git a/tools/pano_cli/main.cpp b/tools/pano_cli/main.cpp index caf5254..cd02f28 100644 --- a/tools/pano_cli/main.cpp +++ b/tools/pano_cli/main.cpp @@ -2,6 +2,7 @@ #include "app_core/app_status.h" #include "app_core/document_export.h" #include "app_core/document_cloud.h" +#include "app_core/document_layer.h" #include "app_core/document_platform_io.h" #include "app_core/document_recording.h" #include "app_core/document_resize.h" @@ -219,6 +220,11 @@ struct PlanDocumentResizeArgs { int selected_resolution_index = 0; }; +struct PlanLayerRenameArgs { + std::string old_name = "Layer 1"; + std::string new_name; +}; + struct SimulateAppSessionArgs { bool has_canvas = true; bool new_document = false; @@ -452,6 +458,18 @@ const char* document_workflow_decision_name(pp::app::DocumentWorkflowDecision de return "unavailable"; } +const char* document_layer_rename_action_name(pp::app::DocumentLayerRenameAction action) noexcept +{ + switch (action) { + case pp::app::DocumentLayerRenameAction::no_op_same_name: + return "no-op-same-name"; + case pp::app::DocumentLayerRenameAction::rename_and_record_undo: + return "rename-and-record-undo"; + } + + return "no-op-same-name"; +} + const char* document_file_write_decision_name(pp::app::DocumentFileWriteDecision decision) noexcept { switch (decision) { @@ -689,6 +707,7 @@ void print_help() << " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n" << " plan-app-status [--doc-name NAME] [--unsaved] [--resolution N] [--resolution-index N] [--zoom N] [--history-bytes N] [--recording-running] [--encoder-available] [--encoded-frames N]\n" << " plan-document-resize [--current-resolution N] [--selected-resolution-index N]\n" + << " plan-layer-rename --old-name NAME --new-name NAME\n" << " plan-share-file [--path FILE]\n" << " plan-picked-path [--path FILE]\n" << " plan-display-file [--path FILE]\n" @@ -2283,6 +2302,55 @@ int plan_document_resize(int argc, char** argv) return 0; } +pp::foundation::Status parse_plan_layer_rename_args( + int argc, + char** argv, + PlanLayerRenameArgs& args) +{ + for (int i = 2; i < argc; ++i) { + const std::string_view key(argv[i]); + if (key == "--old-name" || key == "--new-name") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + if (key == "--old-name") { + args.old_name = argv[++i]; + } else { + args.new_name = argv[++i]; + } + } else { + return pp::foundation::Status::invalid_argument("unknown option"); + } + } + + return pp::foundation::Status::success(); +} + +int plan_layer_rename(int argc, char** argv) +{ + PlanLayerRenameArgs args; + const auto status = parse_plan_layer_rename_args(argc, argv, args); + if (!status.ok()) { + print_error("plan-layer-rename", status.message); + return 2; + } + + const auto plan = pp::app::plan_document_layer_rename(args.old_name, args.new_name); + if (!plan) { + print_error("plan-layer-rename", plan.status().message); + return 2; + } + + std::cout << "{\"ok\":true,\"command\":\"plan-layer-rename\"" + << ",\"state\":{\"oldName\":\"" << json_escape(args.old_name) + << "\",\"newName\":\"" << json_escape(args.new_name) + << "\"},\"plan\":{\"oldName\":\"" << json_escape(plan.value().old_name) + << "\",\"newName\":\"" << json_escape(plan.value().new_name) + << "\",\"action\":\"" << document_layer_rename_action_name(plan.value().action) + << "\"}}\n"; + return 0; +} + pp::foundation::Status parse_plan_share_file_args( int argc, char** argv, @@ -4687,6 +4755,10 @@ int main(int argc, char** argv) return plan_document_resize(argc, argv); } + if (command == "plan-layer-rename") { + return plan_layer_rename(argc, argv); + } + if (command == "plan-share-file") { return plan_share_file(argc, argv); }