129 lines
3.3 KiB
C++
129 lines
3.3 KiB
C++
#include "platform_apple/apple_platform_services.h"
|
|
|
|
#include "app_core/document_platform_io.h"
|
|
#include "platform_api/platform_policy.h"
|
|
|
|
#include <array>
|
|
#include <utility>
|
|
|
|
namespace pp::platform::apple {
|
|
namespace {
|
|
|
|
[[nodiscard]] std::vector<std::string> apple_image_file_types()
|
|
{
|
|
static constexpr std::array<std::string_view, 5> kFileTypes = {
|
|
"png",
|
|
"PNG",
|
|
"jpg",
|
|
"JPG",
|
|
"jpeg",
|
|
};
|
|
|
|
return { kFileTypes.begin(), kFileTypes.end() };
|
|
}
|
|
|
|
void invoke_picked_path_if_selected(
|
|
const std::string& path,
|
|
const PickedPathCallback& callback)
|
|
{
|
|
if (pp::app::plan_picked_path(path) == pp::app::PickedPathAction::invoke_callback)
|
|
callback(path);
|
|
}
|
|
|
|
}
|
|
|
|
AppleDocumentPlatformServices::AppleDocumentPlatformServices(
|
|
PlatformFamily family,
|
|
AppleDocumentPickerBridge bridge)
|
|
: family_(family)
|
|
, bridge_(std::move(bridge))
|
|
{
|
|
}
|
|
|
|
std::vector<std::string> AppleDocumentPlatformServices::document_browse_roots(
|
|
std::string_view work_path,
|
|
std::string_view data_path) const
|
|
{
|
|
return platform_document_browse_roots(family_, work_path, data_path);
|
|
}
|
|
|
|
void AppleDocumentPlatformServices::pick_image(PickedPathCallback callback) const
|
|
{
|
|
if (family_ == PlatformFamily::ios)
|
|
{
|
|
if (bridge_.pick_image)
|
|
bridge_.pick_image(std::move(callback));
|
|
return;
|
|
}
|
|
|
|
if (family_ == PlatformFamily::macos && bridge_.pick_file)
|
|
{
|
|
bridge_.pick_file(
|
|
apple_image_file_types(),
|
|
[callback = std::move(callback)](std::string path) {
|
|
invoke_picked_path_if_selected(path, callback);
|
|
});
|
|
}
|
|
}
|
|
|
|
void AppleDocumentPlatformServices::pick_file(
|
|
std::vector<std::string> file_types,
|
|
PickedPathCallback callback) const
|
|
{
|
|
if (!bridge_.pick_file)
|
|
return;
|
|
|
|
if (family_ == PlatformFamily::ios)
|
|
{
|
|
bridge_.pick_file(std::move(file_types), std::move(callback));
|
|
return;
|
|
}
|
|
|
|
if (family_ == PlatformFamily::macos)
|
|
{
|
|
bridge_.pick_file(
|
|
std::move(file_types),
|
|
[callback = std::move(callback)](std::string path) {
|
|
invoke_picked_path_if_selected(path, callback);
|
|
});
|
|
}
|
|
}
|
|
|
|
void AppleDocumentPlatformServices::pick_save_file(
|
|
std::vector<std::string> file_types,
|
|
PickedPathCallback callback) const
|
|
{
|
|
if (family_ == PlatformFamily::macos && bridge_.pick_save_file)
|
|
{
|
|
bridge_.pick_save_file(
|
|
std::move(file_types),
|
|
[callback = std::move(callback)](std::string path) {
|
|
invoke_picked_path_if_selected(path, callback);
|
|
});
|
|
}
|
|
}
|
|
|
|
void AppleDocumentPlatformServices::pick_directory(PickedPathCallback callback) const
|
|
{
|
|
if (family_ == PlatformFamily::macos && bridge_.pick_directory)
|
|
{
|
|
bridge_.pick_directory([callback = std::move(callback)](std::string path) {
|
|
invoke_picked_path_if_selected(path, callback);
|
|
});
|
|
}
|
|
}
|
|
|
|
bool AppleDocumentPlatformServices::supports_working_directory_picker() const
|
|
{
|
|
return platform_supports_working_directory_picker(family_);
|
|
}
|
|
|
|
std::string AppleDocumentPlatformServices::format_working_directory_path(std::string_view path) const
|
|
{
|
|
if (family_ == PlatformFamily::macos && bridge_.format_working_directory_path)
|
|
return bridge_.format_working_directory_path(path);
|
|
return std::string(path);
|
|
}
|
|
|
|
}
|