Route prepared file targets through platform services

This commit is contained in:
2026-06-04 16:58:05 +02:00
parent dc369c89b0
commit cabfa44729
9 changed files with 122 additions and 25 deletions

View File

@@ -210,6 +210,20 @@ public:
callback(directory_path);
}
[[nodiscard]] pp::platform::PreparedFileTarget prepare_writable_file(
std::string_view type,
std::string_view default_name,
std::string_view data_path,
std::string_view temporary_path) override
{
++prepare_writable_file_requests;
writable_file_type.assign(type);
writable_file_default_name.assign(default_name);
writable_file_data_path.assign(data_path);
writable_file_temporary_path.assign(temporary_path);
return writable_file_target;
}
void save_prepared_file(
std::string_view path,
std::string_view suggested_name,
@@ -255,6 +269,7 @@ public:
int pick_file_requests = 0;
int pick_save_file_requests = 0;
int pick_directory_requests = 0;
int prepare_writable_file_requests = 0;
int save_prepared_file_requests = 0;
bool cursor_visible = false;
bool keyboard_visible = false;
@@ -271,6 +286,10 @@ public:
std::string exported_image_path;
std::string browse_work_path;
std::string browse_data_path;
std::string writable_file_type;
std::string writable_file_default_name;
std::string writable_file_data_path;
std::string writable_file_temporary_path;
std::string picker_path = "D:/Paint/import.png";
std::string save_path = "D:/Paint/export.ppi";
std::string directory_path = "D:/Paint";
@@ -286,6 +305,11 @@ public:
"D:/Paint/work",
"D:/Paint/Inbox",
};
pp::platform::PreparedFileTarget writable_file_target{
"D:/Paint/tmp/export.mp4",
"export.mp4",
true,
};
private:
std::string clipboard_value_;
@@ -542,6 +566,23 @@ void platform_services_dispatch_prepared_file_save(pp::tests::Harness& harness)
PP_EXPECT(harness, saved);
}
void platform_services_dispatch_writable_file_target(pp::tests::Harness& harness)
{
FakePlatformServices fake("unused");
pp::platform::PlatformServices& services = fake;
const auto target = services.prepare_writable_file("mp4", "export", "D:/Paint", "D:/Paint/tmp");
PP_EXPECT(harness, fake.prepare_writable_file_requests == 1);
PP_EXPECT(harness, fake.writable_file_type == "mp4");
PP_EXPECT(harness, fake.writable_file_default_name == "export");
PP_EXPECT(harness, fake.writable_file_data_path == "D:/Paint");
PP_EXPECT(harness, fake.writable_file_temporary_path == "D:/Paint/tmp");
PP_EXPECT(harness, target.path == "D:/Paint/tmp/export.mp4");
PP_EXPECT(harness, target.suggested_name == "export.mp4");
PP_EXPECT(harness, target.write_on_background_thread);
}
}
int main()
@@ -564,5 +605,6 @@ int main()
harness.run("platform services dispatch file actions", platform_services_dispatch_file_actions);
harness.run("platform services dispatch picker callbacks", platform_services_dispatch_picker_callbacks);
harness.run("platform services dispatch prepared file save", platform_services_dispatch_prepared_file_save);
harness.run("platform services dispatch writable file target", platform_services_dispatch_writable_file_target);
return harness.finish();
}