Plan display file actions in app core

This commit is contained in:
2026-06-03 03:38:14 +02:00
parent 712c28068d
commit 4af55a7d3f
9 changed files with 116 additions and 4 deletions

View File

@@ -170,6 +170,10 @@ struct PlanPickedPathArgs {
std::string path;
};
struct PlanDisplayFileArgs {
std::string path;
};
struct SimulateAppSessionArgs {
bool has_canvas = true;
bool new_document = false;
@@ -515,6 +519,18 @@ const char* picked_path_action_name(pp::app::PickedPathAction action) noexcept
return "ignore-empty-path";
}
const char* display_file_action_name(pp::app::DisplayFileAction action) noexcept
{
switch (action) {
case pp::app::DisplayFileAction::ignore_empty_path:
return "ignore-empty-path";
case pp::app::DisplayFileAction::open_external_file:
return "open-external-file";
}
return "ignore-empty-path";
}
pp::foundation::Result<float> parse_float_arg(std::string_view text)
{
float value = 0.0F;
@@ -557,6 +573,7 @@ void print_help()
<< " plan-recording-session [--running] [--frame-count N] [--platform-deletes-recorded-files]\n"
<< " plan-share-file [--path FILE]\n"
<< " plan-picked-path [--path FILE]\n"
<< " plan-display-file [--path FILE]\n"
<< " load-project --path FILE\n"
<< " parse-layout --path FILE\n"
<< " record-render [--width N] [--height N] [--exercise-clear]\n"
@@ -1964,6 +1981,43 @@ int plan_picked_path(int argc, char** argv)
return 0;
}
pp::foundation::Status parse_plan_display_file_args(
int argc,
char** argv,
PlanDisplayFileArgs& args)
{
for (int i = 2; i < argc; ++i) {
const std::string_view key(argv[i]);
if (key == "--path") {
if (i + 1 >= argc) {
return pp::foundation::Status::invalid_argument("missing value for option");
}
args.path = argv[++i];
} else {
return pp::foundation::Status::invalid_argument("unknown option");
}
}
return pp::foundation::Status::success();
}
int plan_display_file(int argc, char** argv)
{
PlanDisplayFileArgs args;
const auto status = parse_plan_display_file_args(argc, argv, args);
if (!status.ok()) {
print_error("plan-display-file", status.message);
return 2;
}
const auto decision = pp::app::plan_display_file(args.path);
std::cout << "{\"ok\":true,\"command\":\"plan-display-file\""
<< ",\"state\":{\"path\":\"" << json_escape(args.path)
<< "\"},\"decision\":\"" << display_file_action_name(decision)
<< "\"}\n";
return 0;
}
pp::foundation::Status parse_plan_export_target_args(
int argc,
char** argv,
@@ -4139,6 +4193,10 @@ int main(int argc, char** argv)
return plan_picked_path(argc, argv);
}
if (command == "plan-display-file") {
return plan_display_file(argc, argv);
}
if (command == "load-project") {
return load_project(argc, argv);
}