Integrate dialog export and Apple service teams
This commit is contained in:
128
src/platform_apple/apple_platform_services.cpp
Normal file
128
src/platform_apple/apple_platform_services.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
||||
44
src/platform_apple/apple_platform_services.h
Normal file
44
src/platform_apple/apple_platform_services.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "platform_api/platform_services.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace pp::platform::apple {
|
||||
|
||||
struct AppleDocumentPickerBridge {
|
||||
std::function<void(PickedPathCallback callback)> pick_image;
|
||||
std::function<void(std::vector<std::string> file_types, PickedPathCallback callback)> pick_file;
|
||||
std::function<void(std::vector<std::string> file_types, PickedPathCallback callback)> pick_save_file;
|
||||
std::function<void(PickedPathCallback callback)> pick_directory;
|
||||
std::function<std::string(std::string_view path)> format_working_directory_path;
|
||||
};
|
||||
|
||||
class AppleDocumentPlatformServices {
|
||||
public:
|
||||
explicit AppleDocumentPlatformServices(
|
||||
PlatformFamily family,
|
||||
AppleDocumentPickerBridge bridge = {});
|
||||
|
||||
[[nodiscard]] std::vector<std::string> document_browse_roots(
|
||||
std::string_view work_path,
|
||||
std::string_view data_path) const;
|
||||
|
||||
void pick_image(PickedPathCallback callback) const;
|
||||
void pick_file(std::vector<std::string> file_types, PickedPathCallback callback) const;
|
||||
void pick_save_file(std::vector<std::string> file_types, PickedPathCallback callback) const;
|
||||
void pick_directory(PickedPathCallback callback) const;
|
||||
|
||||
[[nodiscard]] bool supports_working_directory_picker() const;
|
||||
[[nodiscard]] std::string format_working_directory_path(std::string_view path) const;
|
||||
|
||||
private:
|
||||
PlatformFamily family_;
|
||||
AppleDocumentPickerBridge bridge_;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user