From 062fdaa982469fb4a0f341e559077ff56db10904 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 5 Jun 2026 07:36:56 +0200 Subject: [PATCH] Plan app dialog factories --- CMakeLists.txt | 1 + docs/modernization/build-inventory.md | 4 + docs/modernization/debt.md | 8 +- docs/modernization/roadmap.md | 16 +++ src/app_core/app_dialog.h | 78 ++++++++++++++ src/app_dialogs.cpp | 31 ++++-- tests/CMakeLists.txt | 35 +++++++ tests/app_core/app_dialog_tests.cpp | 68 ++++++++++++ tools/pano_cli/main.cpp | 145 ++++++++++++++++++++++++++ 9 files changed, 374 insertions(+), 12 deletions(-) create mode 100644 src/app_core/app_dialog.h create mode 100644 tests/app_core/app_dialog_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b9ff6ef..2c241b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,6 +240,7 @@ target_link_libraries(pp_platform_api add_library(pp_app_core STATIC src/app_core/about_menu.h + src/app_core/app_dialog.h src/app_core/app_frame.h src/app_core/app_input.h src/app_core/app_preferences.h diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index a4ba3ce..80f6a0f 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -832,6 +832,10 @@ Known local toolchain state: timelapse start/stop/no-op decisions, VR mode success/failure dispatch, simple stored preferences, and `AppPreferenceServices` execution dispatch for options-menu side effects. +- `pp_app_core_app_dialog_tests` covers app-level progress/message/input dialog + metadata planning, progress initialization, negative progress-total clamping, + message cancel-button policy, input OK-caption propagation, and malformed + empty OK-caption rejection without requiring legacy `Node*` dialogs. - `pp_app_core_app_startup_tests` covers startup run-counter increment planning, optional auto-timelapse/license/VR-controller decisions, negative and overflow run-counter rejection, stable full startup dispatch ordering, diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 69b1696..a1c5f04 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -145,6 +145,11 @@ agent or engineer to remove them without reconstructing context from chat. progress-callback, and zero/overrun progress cases for automation. CURL ownership, response/error handling, progress UI, cloud dialog/document execution, and injected network service work remain open under DEBT-0038. +- 2026-06-05: DEBT-0058 was opened. App-level progress, message, and input + dialog metadata now lives in tested `pp_app_core` planning consumed by + `App::show_progress`, `App::message_box`, `App::input_box`, and + `pano_cli plan-app-dialog`, but retained `Node*` dialog creation, layout + insertion, callback wiring, and lifetime ownership remain in the legacy app. - 2026-06-04: DEBT-0036 was narrowed again. Canvas stroke commit, thumbnail, and object-draw history paths now query saved blend state through tested `pp_renderer_gl` capability-state dispatch; CanvasLayer equirect @@ -163,7 +168,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`, `App::rec_loop`, `App::update_ui_observer`, `App::render_task*`, `App::ui_task*`, `App::render_thread_*`, `App::ui_thread_*`, file-menu save actions, `NodeCanvas` canvas 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/menu/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/worker 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 and renderer diagnostic decisions, app frame/UI-observer decisions, app thread/task orchestration decisions, document resize decisions, layer rename/menu decisions, Tools menu/panel decisions, About menu/diagnostic decisions, main toolbar/status decisions, `pano_cli classify-open`, `pano_cli plan-open-route`, `pano_cli plan-file-menu`, `pano_cli plan-new-document`, `pano_cli plan-document-file`, `pano_cli plan-document-version`, `pano_cli plan-export-start`, `pano_cli plan-export-menu`, `pano_cli plan-export-target`, `pano_cli plan-recording-session`, `pano_cli plan-app-preferences`, `pano_cli plan-app-status`, `pano_cli plan-app-thread`, `pano_cli plan-tools-menu`, `pano_cli plan-tools-panel`, `pano_cli plan-about-menu`, `pano_cli plan-main-toolbar`, `pano_cli plan-document-resize`, `pano_cli plan-layer-rename`, `pano_cli plan-layer-menu`, `pano_cli plan-canvas-hotkey`, `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/thread/share/platform-I/O/display/keyboard/cloud/resize/layer/tools/about/toolbar/canvas-command contracts, but document creation/loading, brush import execution, saving, export execution, tools/options UI execution, Tools panel creation/execution, About dialog/diagnostic execution, toolbar/status dialog/history/canvas execution, status/display UI rendering, renderer diagnostic capability adaptation, app task/thread execution, UI observer parent walking/callback execution, document resize execution, layer rename/menu execution, settings persistence, platform share service execution, picker service execution, display-file service execution, keyboard service execution, recording/MP4/PBO 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_file_menu_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_recording_tests`; `pp_app_core_app_frame_tests`; `pp_app_core_app_preferences_tests`; `pp_app_core_app_status_tests`; `pp_app_core_app_thread_tests`; `pp_app_core_tools_menu_tests`; `pp_app_core_about_menu_tests`; `pp_app_core_main_toolbar_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`; `pp_app_core_canvas_hotkey_tests`; `pano_cli classify-open --path D:/Paint/demo.ppi`; `pano_cli plan-open-route --path D:/Paint/demo.ppi --unsaved`; `pano_cli plan-file-menu --command save-as`; `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-menu --kind animation-mp4 --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-recording-session --running --no-encoder`; `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 --framebuffer-fetch --float32 --float32-linear --float16`; `pano_cli plan-app-frame`; `pano_cli plan-app-thread --kind ui-loop --live-reload`; `pano_cli plan-tools-menu --command shortcuts`; `pano_cli plan-tools-panel --panel layers`; `pano_cli plan-about-menu --command news --version-major 2 --version-minor 5 --version-fix 7`; `pano_cli plan-main-toolbar --command undo --undo-count 2`; `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-layer-menu --command merge --current-index 2 --lower-name Paint`; `pano_cli plan-canvas-hotkey --event key-up --key z --ctrl --undo-count 2`; `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`, `App::rec_loop`, `App::update_ui_observer`, `App::render_task*`, `App::ui_task*`, `App::render_thread_*`, `App::ui_thread_*`, file-menu save actions, `NodeCanvas` canvas 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/menu/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/worker 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 and renderer diagnostic decisions, app dialog metadata decisions, app frame/UI-observer decisions, app thread/task orchestration decisions, document resize decisions, layer rename/menu decisions, Tools menu/panel decisions, About menu/diagnostic decisions, main toolbar/status decisions, `pano_cli classify-open`, `pano_cli plan-open-route`, `pano_cli plan-file-menu`, `pano_cli plan-new-document`, `pano_cli plan-document-file`, `pano_cli plan-document-version`, `pano_cli plan-export-start`, `pano_cli plan-export-menu`, `pano_cli plan-export-target`, `pano_cli plan-recording-session`, `pano_cli plan-app-preferences`, `pano_cli plan-app-status`, `pano_cli plan-app-dialog`, `pano_cli plan-app-thread`, `pano_cli plan-tools-menu`, `pano_cli plan-tools-panel`, `pano_cli plan-about-menu`, `pano_cli plan-main-toolbar`, `pano_cli plan-document-resize`, `pano_cli plan-layer-rename`, `pano_cli plan-layer-menu`, `pano_cli plan-canvas-hotkey`, `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/dialog/thread/share/platform-I/O/display/keyboard/cloud/resize/layer/tools/about/toolbar/canvas-command contracts, but document creation/loading, brush import execution, saving, export execution, tools/options UI execution, Tools panel creation/execution, About dialog/diagnostic execution, toolbar/status dialog/history/canvas execution, app dialog node creation, status/display UI rendering, renderer diagnostic capability adaptation, app task/thread execution, UI observer parent walking/callback execution, document resize execution, layer rename/menu execution, settings persistence, platform share service execution, picker service execution, display-file service execution, keyboard service execution, recording/MP4/PBO 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_file_menu_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_recording_tests`; `pp_app_core_app_frame_tests`; `pp_app_core_app_preferences_tests`; `pp_app_core_app_status_tests`; `pp_app_core_app_dialog_tests`; `pp_app_core_app_thread_tests`; `pp_app_core_tools_menu_tests`; `pp_app_core_about_menu_tests`; `pp_app_core_main_toolbar_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`; `pp_app_core_canvas_hotkey_tests`; `pano_cli classify-open --path D:/Paint/demo.ppi`; `pano_cli plan-open-route --path D:/Paint/demo.ppi --unsaved`; `pano_cli plan-file-menu --command save-as`; `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-menu --kind animation-mp4 --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-recording-session --running --no-encoder`; `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 --framebuffer-fetch --float32 --float32-linear --float16`; `pano_cli plan-app-dialog --kind message --cancel`; `pano_cli plan-app-frame`; `pano_cli plan-app-thread --kind ui-loop --live-reload`; `pano_cli plan-tools-menu --command shortcuts`; `pano_cli plan-tools-panel --panel layers`; `pano_cli plan-about-menu --command news --version-major 2 --version-minor 5 --version-fix 7`; `pano_cli plan-main-toolbar --command undo --undo-count 2`; `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-layer-menu --command merge --current-index 2 --lower-name Paint`; `pano_cli plan-canvas-hotkey --event key-up --key z --ctrl --undo-count 2`; `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 | @@ -216,6 +221,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0055 | Open | Modernization | `src/app.h` now forward-declares retained iOS/macOS/Android/Linux/Web platform handles instead of including platform SDK headers, and full SDK includes are isolated in `src/platform_legacy/legacy_platform_services.cpp`, but the `App` singleton still stores those platform handles directly | Reduce central header platform coupling incrementally without rewriting non-Windows platform entrypoints before Phase 6 | Windows app build; Apple/Android/Linux/Web package smoke once platform root builds are active | Platform handles are owned by injected `pp_platform_*` shell state or services, and `App` has no platform SDK handle fields or platform conditional members | | DEBT-0056 | Open | Modernization | `src/asset.h` now forward-declares Android asset-manager types and uses `Asset::set_android_asset_manager` instead of public mutable manager state, but retained `Asset` still stores Android asset handles and `src/asset.cpp` still performs Android `AAssetManager` reads directly; the current `android-arm64` root preset is headless and does not expose `pp_legacy_assets_io` | Reduce legacy asset I/O header coupling without rewriting Android asset loading before the asset manager/storage boundary exists | Windows app build; `cmake --build --preset android-arm64 --target pp_assets`; Android package smoke once package builds consume shared targets | Android asset loading is owned by injected asset storage/platform services or `pp_assets` file providers, with no static Android asset manager on `Asset` | | DEBT-0057 | Open | Modernization | Default canvas allocation size now dispatches through `PlatformServices::default_canvas_resolution`, removing the `CANVAS_RES` platform macro from `src/canvas.h`, but WebGL's retained 512 default still lives in `src/platform_legacy/legacy_platform_services.cpp` until the Web shell owns injected services | Preserve WebGL memory behavior while moving canvas creation policy out of shared canvas headers and into the platform boundary | `pp_platform_api_tests`; `ctest --preset desktop-fast --build-config Debug -R pp_platform_api_tests`; Windows app build; WebGL package smoke once root Web build exists | Default canvas resolution is owned by injected `pp_platform_*` services for every supported platform, with no WebGL branch in the legacy fallback | +| DEBT-0058 | Open | Modernization | App-level progress/message/input dialog metadata now consumes pure `pp_app_core` through `App::show_progress`, `App::message_box`, `App::input_box`, `pano_cli plan-app-dialog`, and `pp_app_core_app_dialog_tests`, but live execution still creates retained `NodeProgressBar`, `NodeMessageBox`, and `NodeInputBox` instances directly in `src/app_dialogs.cpp` and inserts them into the legacy layout tree | Preserve current app-shell dialog behavior while moving shared dialog policy toward UI/app services | `pp_app_core_app_dialog_tests`; `pano_cli plan-app-dialog --kind progress --total -4`; `pano_cli plan-app-dialog --kind message --cancel`; `pano_cli plan-app-dialog --kind input --ok-caption Save`; `ctest --preset desktop-fast --build-config Debug`; Windows app build | Progress/message/input dialog creation, callback wiring, layout insertion, lifetime ownership, and headless automation are owned by injected app/UI services with `App` methods acting only as adapters | ## Closed Debt diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index e2c9929..8be7f52 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -198,6 +198,13 @@ and floating-point render targets; `App::title_update`, `App::update_memory_usage`, `App::update_rec_frames`, resolution helpers, `App::initLayout`, and `pano_cli plan-app-status` consume those contracts while legacy UI nodes still render the strings and status lights. +App-level progress, message, and input dialog metadata now also lives in +`pp_app_core` through `plan_app_progress_dialog`, +`plan_app_message_dialog`, and `plan_app_input_dialog`; `App::show_progress`, +`App::message_box`, `App::input_box`, and `pano_cli plan-app-dialog` consume +those plans before retained `NodeProgressBar`, `NodeMessageBox`, and +`NodeInputBox` creation. Legacy dialog node lifetime/layout ownership remains +tracked under `DEBT-0058`. Frame-level app decisions for the initial surface size, redraw/animation update gating, layout ticking, resize render-target recreation, canvas-stroke drawing, VR UI drawing, main UI drawing, UI observer clipping/on-screen transition/scissor @@ -1691,6 +1698,15 @@ Results: - Focused preference CTest coverage passed for `pp_app_core_app_preferences_tests` and the app-preferences CLI smoke tests after the live bridge split, including VR mode failed-start status coverage. +- `PanoPainter`, `pp_app_core_app_dialog_tests`, and `pano_cli` built after + progress/message/input dialog metadata moved into `pp_app_core` while live + `App` factories kept retained `Node*` creation. +- Focused app-dialog CTest coverage passed for + `pp_app_core_app_dialog_tests` and the `pano_cli_plan_app_dialog_*` smoke + tests, including negative progress-total clamping and rejected empty + input-dialog OK captions. +- Android arm64 headless `pp_app_core`, `pano_cli`, and + `pp_app_core_app_dialog_tests` built after the app-dialog planning slice. - `PanoPainter`, `pp_app_core_app_startup_tests`, and `pano_cli` built after startup preference/runtime execution and startup resource sequencing moved behind app startup services. diff --git a/src/app_core/app_dialog.h b/src/app_core/app_dialog.h new file mode 100644 index 0000000..9b63974 --- /dev/null +++ b/src/app_core/app_dialog.h @@ -0,0 +1,78 @@ +#pragma once + +#include "foundation/result.h" + +#include +#include + +namespace pp::app { + +enum class AppDialogKind { + progress, + message, + input, +}; + +struct AppProgressDialogPlan { + std::string title; + int total = 0; + int count = 0; + float progress_fraction = 0.0F; +}; + +struct AppMessageDialogPlan { + std::string title; + std::string message; + std::string ok_caption = "Ok"; + bool show_cancel = false; +}; + +struct AppInputDialogPlan { + std::string title; + std::string field_name; + std::string ok_caption = "Ok"; +}; + +[[nodiscard]] inline AppProgressDialogPlan plan_app_progress_dialog( + std::string_view title, + int total) noexcept +{ + return { + std::string(title), + total < 0 ? 0 : total, + 0, + 0.0F, + }; +} + +[[nodiscard]] inline AppMessageDialogPlan plan_app_message_dialog( + std::string_view title, + std::string_view message, + bool show_cancel) +{ + return { + std::string(title), + std::string(message), + "Ok", + show_cancel, + }; +} + +[[nodiscard]] inline pp::foundation::Result plan_app_input_dialog( + std::string_view title, + std::string_view field_name, + std::string_view ok_caption) +{ + if (ok_caption.empty()) { + return pp::foundation::Result::failure( + pp::foundation::Status::invalid_argument("input dialog ok caption must not be empty")); + } + + return pp::foundation::Result::success({ + std::string(title), + std::string(field_name), + std::string(ok_caption), + }); +} + +} // namespace pp::app diff --git a/src/app_dialogs.cpp b/src/app_dialogs.cpp index 9e18a06..8ba1799 100644 --- a/src/app_dialogs.cpp +++ b/src/app_dialogs.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "app.h" +#include "app_core/app_dialog.h" #include "app_core/document_layer.h" #include "app_core/document_resize.h" #include "app_core/document_export.h" @@ -108,30 +109,32 @@ void start_document_export_collection( std::shared_ptr App::show_progress(const std::string& title, int total /*= 0*/) { + const auto plan = pp::app::plan_app_progress_dialog(title, total); auto pb = std::make_shared(); pb->set_manager(&layout); pb->init(); pb->create(); pb->loaded(); - pb->m_progress->SetWidthP(0); - pb->m_title->set_text(title.c_str()); - pb->m_total = total; - pb->m_count = 0; + pb->m_progress->SetWidthP(plan.progress_fraction); + pb->m_title->set_text(plan.title.c_str()); + pb->m_total = plan.total; + pb->m_count = plan.count; layout[main_id]->add_child(pb); return pb; } std::shared_ptr App::message_box(const std::string &title, const std::string& text, bool cancel_button) { + const auto plan = pp::app::plan_app_message_dialog(title, text, cancel_button); auto m = std::make_shared(); m->set_manager(&layout); m->init(); m->create(); m->loaded(); - m->m_title->set_text(title.c_str()); - m->m_message->set_text(text.c_str()); - m->btn_ok->m_text->set_text("Ok"); - if (!cancel_button) + m->m_title->set_text(plan.title.c_str()); + m->m_message->set_text(plan.message.c_str()); + m->btn_ok->m_text->set_text(plan.ok_caption.c_str()); + if (!plan.show_cancel) m->btn_cancel->destroy(); layout[main_id]->add_child(m); return m; @@ -140,14 +143,20 @@ std::shared_ptr App::message_box(const std::string &title, const std::shared_ptr App::input_box(const std::string& title, const std::string& field_name, const std::string& ok_caption /*= "Ok"*/) { + const auto plan_result = pp::app::plan_app_input_dialog(title, field_name, ok_caption); + if (!plan_result) { + LOG("input dialog skipped: %s", plan_result.status().message); + return nullptr; + } + const auto& plan = plan_result.value(); auto m = std::make_shared(); m->set_manager(&layout); m->init(); m->create(); m->loaded(); - m->m_title->set_text(title.c_str()); - m->m_field_name->set_text(field_name.c_str()); - m->btn_ok->m_text->set_text(ok_caption.c_str()); + m->m_title->set_text(plan.title.c_str()); + m->m_field_name->set_text(plan.field_name.c_str()); + m->btn_ok->m_text->set_text(plan.ok_caption.c_str()); layout[main_id]->add_child(m); return m; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 85521fc..dab0d95 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -545,6 +545,16 @@ add_test(NAME pp_app_core_app_status_tests COMMAND pp_app_core_app_status_tests) set_tests_properties(pp_app_core_app_status_tests PROPERTIES LABELS "app;desktop-fast;fuzz") +add_executable(pp_app_core_app_dialog_tests + app_core/app_dialog_tests.cpp) +target_link_libraries(pp_app_core_app_dialog_tests PRIVATE + pp_app_core + pp_test_harness) + +add_test(NAME pp_app_core_app_dialog_tests COMMAND pp_app_core_app_dialog_tests) +set_tests_properties(pp_app_core_app_dialog_tests PROPERTIES + LABELS "app;desktop-fast;fuzz") + add_executable(pp_app_core_app_startup_tests app_core/app_startup_tests.cpp) target_link_libraries(pp_app_core_app_startup_tests PRIVATE @@ -948,6 +958,31 @@ if(TARGET pano_cli) LABELS "app;integration;desktop-fast;fuzz" PASS_REGULAR_EXPRESSION "\"command\":\"plan-cloud-transfer\".*\"action\":\"start-transfer\".*\"notify\":false.*\"fraction\":0") + add_test(NAME pano_cli_plan_app_dialog_progress_smoke + COMMAND pano_cli plan-app-dialog --kind progress --title Saving --total -4) + set_tests_properties(pano_cli_plan_app_dialog_progress_smoke PROPERTIES + LABELS "app;integration;desktop-fast;fuzz" + PASS_REGULAR_EXPRESSION "\"command\":\"plan-app-dialog\".*\"kind\":\"progress\".*\"title\":\"Saving\".*\"total\":0.*\"count\":0.*\"progressFraction\":0") + + add_test(NAME pano_cli_plan_app_dialog_message_smoke + COMMAND pano_cli plan-app-dialog --kind message --title Import --message Brushes --cancel) + set_tests_properties(pano_cli_plan_app_dialog_message_smoke PROPERTIES + LABELS "app;integration;desktop-fast" + PASS_REGULAR_EXPRESSION "\"command\":\"plan-app-dialog\".*\"kind\":\"message\".*\"title\":\"Import\".*\"message\":\"Brushes\".*\"okCaption\":\"Ok\".*\"showCancel\":true") + + add_test(NAME pano_cli_plan_app_dialog_input_smoke + COMMAND pano_cli plan-app-dialog --kind input --title Rename --field-name Layer --ok-caption Save) + set_tests_properties(pano_cli_plan_app_dialog_input_smoke PROPERTIES + LABELS "app;integration;desktop-fast" + PASS_REGULAR_EXPRESSION "\"command\":\"plan-app-dialog\".*\"kind\":\"input\".*\"title\":\"Rename\".*\"fieldName\":\"Layer\".*\"okCaption\":\"Save") + + add_test(NAME pano_cli_plan_app_dialog_rejects_empty_ok_caption + COMMAND pano_cli plan-app-dialog --kind input --ok-caption "") + set_tests_properties(pano_cli_plan_app_dialog_rejects_empty_ok_caption PROPERTIES + LABELS "app;integration;desktop-fast;fuzz" + WILL_FAIL TRUE + PASS_REGULAR_EXPRESSION "\"command\":\"plan-app-dialog\".*\"message\":\"input dialog ok caption") + add_test(NAME pano_cli_plan_recording_session_stopped_smoke COMMAND pano_cli plan-recording-session --frame-count 12) set_tests_properties(pano_cli_plan_recording_session_stopped_smoke PROPERTIES diff --git a/tests/app_core/app_dialog_tests.cpp b/tests/app_core/app_dialog_tests.cpp new file mode 100644 index 0000000..057a9a0 --- /dev/null +++ b/tests/app_core/app_dialog_tests.cpp @@ -0,0 +1,68 @@ +#include "app_core/app_dialog.h" +#include "test_harness.h" + +namespace { + +void progress_dialog_initializes_progress_state(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_app_progress_dialog("Saving", 12); + PP_EXPECT(harness, plan.title == "Saving"); + PP_EXPECT(harness, plan.total == 12); + PP_EXPECT(harness, plan.count == 0); + PP_EXPECT(harness, plan.progress_fraction == 0.0F); +} + +void progress_dialog_clamps_negative_total(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_app_progress_dialog("Broken", -4); + PP_EXPECT(harness, plan.total == 0); + PP_EXPECT(harness, plan.count == 0); + PP_EXPECT(harness, plan.progress_fraction == 0.0F); +} + +void message_dialog_preserves_cancel_policy(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_app_message_dialog("Import", "Import brushes?", true); + PP_EXPECT(harness, plan.title == "Import"); + PP_EXPECT(harness, plan.message == "Import brushes?"); + PP_EXPECT(harness, plan.ok_caption == "Ok"); + PP_EXPECT(harness, plan.show_cancel); +} + +void message_dialog_defaults_to_no_cancel(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_app_message_dialog("License", "Disabled", false); + PP_EXPECT(harness, plan.title == "License"); + PP_EXPECT(harness, plan.message == "Disabled"); + PP_EXPECT(harness, !plan.show_cancel); +} + +void input_dialog_preserves_ok_caption(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_app_input_dialog("Rename", "Layer", "Save"); + PP_EXPECT(harness, plan); + PP_EXPECT(harness, plan.value().title == "Rename"); + PP_EXPECT(harness, plan.value().field_name == "Layer"); + PP_EXPECT(harness, plan.value().ok_caption == "Save"); +} + +void input_dialog_rejects_empty_ok_caption(pp::tests::Harness& harness) +{ + const auto plan = pp::app::plan_app_input_dialog("Rename", "Layer", ""); + PP_EXPECT(harness, !plan); + PP_EXPECT(harness, plan.status().code == pp::foundation::StatusCode::invalid_argument); +} + +} + +int main() +{ + pp::tests::Harness harness; + harness.run("progress dialog initializes progress state", progress_dialog_initializes_progress_state); + harness.run("progress dialog clamps negative total", progress_dialog_clamps_negative_total); + harness.run("message dialog preserves cancel policy", message_dialog_preserves_cancel_policy); + harness.run("message dialog defaults to no cancel", message_dialog_defaults_to_no_cancel); + harness.run("input dialog preserves ok caption", input_dialog_preserves_ok_caption); + harness.run("input dialog rejects empty ok caption", input_dialog_rejects_empty_ok_caption); + return harness.finish(); +} diff --git a/tools/pano_cli/main.cpp b/tools/pano_cli/main.cpp index 57305f8..02de411 100644 --- a/tools/pano_cli/main.cpp +++ b/tools/pano_cli/main.cpp @@ -1,4 +1,5 @@ #include "app_core/about_menu.h" +#include "app_core/app_dialog.h" #include "app_core/app_preferences.h" #include "app_core/app_frame.h" #include "app_core/app_input.h" @@ -249,6 +250,16 @@ struct PlanAppPreferencesArgs { int cursor_mode = 0; }; +struct PlanAppDialogArgs { + pp::app::AppDialogKind kind = pp::app::AppDialogKind::progress; + std::string title = "Saving"; + std::string message = "Done"; + std::string field_name = "Name"; + std::string ok_caption = "Ok"; + int total = 0; + bool cancel = false; +}; + struct PlanAppStartupArgs { int run_counter = 0; bool auto_timelapse_enabled = true; @@ -1931,6 +1942,20 @@ const char* cloud_transfer_action_name(pp::app::CloudTransferAction action) noex return "reject-missing-source"; } +const char* app_dialog_kind_name(pp::app::AppDialogKind kind) noexcept +{ + switch (kind) { + case pp::app::AppDialogKind::progress: + return "progress"; + case pp::app::AppDialogKind::message: + return "message"; + case pp::app::AppDialogKind::input: + return "input"; + } + + return "progress"; +} + const char* recording_start_action_name(pp::app::RecordingStartAction action) noexcept { switch (action) { @@ -2147,6 +2172,7 @@ void print_help() << " plan-cloud-browse [--no-canvas] [--selected-file FILE]\n" << " plan-cloud-upload-all [--file-count N] [--no-progress-ui]\n" << " plan-cloud-transfer [--direction download|upload] [--source TEXT] [--destination FILE] [--progress] [--disable-tls-verification] [--progress-total N] [--progress-current N]\n" + << " plan-app-dialog --kind progress|message|input [--title TEXT] [--message TEXT] [--field-name TEXT] [--ok-caption TEXT] [--total N] [--cancel]\n" << " plan-recording-session [--running] [--frame-count N] [--platform-deletes-recorded-files] [--no-encoder] [--no-canvas]\n" << " 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-startup [--run-counter N] [--auto-timelapse-disabled] [--vr-controllers-disabled] [--license-invalid]\n" @@ -3675,6 +3701,121 @@ int plan_cloud_transfer(int argc, char** argv) return 0; } +pp::foundation::Status parse_plan_app_dialog_args( + int argc, + char** argv, + PlanAppDialogArgs& args) +{ + for (int i = 2; i < argc; ++i) { + const std::string_view key(argv[i]); + if (key == "--kind") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + const std::string_view value(argv[++i]); + if (value == "progress") { + args.kind = pp::app::AppDialogKind::progress; + } else if (value == "message") { + args.kind = pp::app::AppDialogKind::message; + } else if (value == "input") { + args.kind = pp::app::AppDialogKind::input; + } else { + return pp::foundation::Status::invalid_argument("unknown app dialog kind"); + } + } else if (key == "--title") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + args.title = argv[++i]; + } else if (key == "--message") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + args.message = argv[++i]; + } else if (key == "--field-name") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + args.field_name = argv[++i]; + } else if (key == "--ok-caption") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + args.ok_caption = argv[++i]; + } else if (key == "--total") { + if (i + 1 >= argc) { + return pp::foundation::Status::invalid_argument("missing value for option"); + } + const auto value = parse_i32_arg(argv[++i]); + if (!value) { + return value.status(); + } + args.total = value.value(); + } else if (key == "--cancel") { + args.cancel = true; + } else { + return pp::foundation::Status::invalid_argument("unknown option"); + } + } + + return pp::foundation::Status::success(); +} + +int plan_app_dialog(int argc, char** argv) +{ + PlanAppDialogArgs args; + const auto status = parse_plan_app_dialog_args(argc, argv, args); + if (!status.ok()) { + print_error("plan-app-dialog", status.message); + return 2; + } + + switch (args.kind) { + case pp::app::AppDialogKind::progress: + { + const auto plan = pp::app::plan_app_progress_dialog(args.title, args.total); + std::cout << "{\"ok\":true,\"command\":\"plan-app-dialog\"" + << ",\"kind\":\"" << app_dialog_kind_name(args.kind) + << "\",\"plan\":{\"title\":\"" << json_escape(plan.title) + << "\",\"total\":" << plan.total + << ",\"count\":" << plan.count + << ",\"progressFraction\":" << plan.progress_fraction + << "}}\n"; + return 0; + } + case pp::app::AppDialogKind::message: + { + const auto plan = pp::app::plan_app_message_dialog(args.title, args.message, args.cancel); + std::cout << "{\"ok\":true,\"command\":\"plan-app-dialog\"" + << ",\"kind\":\"" << app_dialog_kind_name(args.kind) + << "\",\"plan\":{\"title\":\"" << json_escape(plan.title) + << "\",\"message\":\"" << json_escape(plan.message) + << "\",\"okCaption\":\"" << json_escape(plan.ok_caption) + << "\",\"showCancel\":" << json_bool(plan.show_cancel) + << "}}\n"; + return 0; + } + case pp::app::AppDialogKind::input: + { + const auto plan = pp::app::plan_app_input_dialog(args.title, args.field_name, args.ok_caption); + if (!plan) { + print_error("plan-app-dialog", plan.status().message); + return 2; + } + std::cout << "{\"ok\":true,\"command\":\"plan-app-dialog\"" + << ",\"kind\":\"" << app_dialog_kind_name(args.kind) + << "\",\"plan\":{\"title\":\"" << json_escape(plan.value().title) + << "\",\"fieldName\":\"" << json_escape(plan.value().field_name) + << "\",\"okCaption\":\"" << json_escape(plan.value().ok_caption) + << "}}\n"; + return 0; + } + } + + print_error("plan-app-dialog", "unknown app dialog kind"); + return 2; +} + pp::foundation::Status parse_plan_recording_session_args( int argc, char** argv, @@ -10879,6 +11020,10 @@ int main(int argc, char** argv) return plan_cloud_transfer(argc, argv); } + if (command == "plan-app-dialog") { + return plan_app_dialog(argc, argv); + } + if (command == "plan-recording-session") { return plan_recording_session(argc, argv); }