7#if defined(__APPLE__) && defined(__MACH__)
9#include <Foundation/Foundation.h>
10#include <TargetConditionals.h>
12#import <CoreText/CoreText.h>
14#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
16#import <UIKit/UIKit.h>
17#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
22static std::string selectedFile;
24void ShowOpenFileDialogImpl(
void (^completionHandler)(std::string)) {
26 [appDelegate PresentDocumentPickerWithCompletionHandler:^(NSString *filePath) {
27 selectedFile = std::string([filePath UTF8String]);
28 completionHandler(selectedFile);
32std::string ShowOpenFileDialogSync() {
33 __block std::string result;
35 ShowOpenFileDialogImpl(^(std::string filePath) {
48 const std::string &folder) {
53 const std::string &folder) {
58 NSBundle* bundle = [NSBundle mainBundle];
59 NSString* resourceDirectoryPath = [bundle bundlePath];
60 NSString* path = [resourceDirectoryPath stringByAppendingString:
@"/"];
61 return [path UTF8String];
64#elif TARGET_OS_MAC == 1
67#import <Cocoa/Cocoa.h>
70 NSOpenPanel* openPanel = [NSOpenPanel openPanel];
71 [openPanel setCanChooseFiles:YES];
72 [openPanel setCanChooseDirectories:NO];
73 [openPanel setAllowsMultipleSelection:NO];
75 if ([openPanel runModal] == NSModalResponseOK) {
76 NSURL* url = [[openPanel URLs] objectAtIndex:0];
77 NSString* path = [url path];
78 return std::string([path UTF8String]);
85 NSOpenPanel* openPanel = [NSOpenPanel openPanel];
86 [openPanel setCanChooseFiles:NO];
87 [openPanel setCanChooseDirectories:YES];
88 [openPanel setAllowsMultipleSelection:NO];
90 if ([openPanel runModal] == NSModalResponseOK) {
91 NSURL* url = [[openPanel URLs] objectAtIndex:0];
92 NSString* path = [url path];
93 return std::string([path UTF8String]);
100 const std::string& folder) {
101 std::vector<std::string> filenames;
102 NSFileManager* fileManager = [NSFileManager defaultManager];
103 NSDirectoryEnumerator* enumerator =
104 [fileManager enumeratorAtPath:[NSString stringWithUTF8String:folder.c_str()]];
106 while (file = [enumerator nextObject]) {
107 if ([file hasPrefix:
@"."]) {
110 filenames.push_back(std::string([file UTF8String]));
116 const std::string& folder) {
117 std::vector<std::string> subdirectories;
118 NSFileManager* fileManager = [NSFileManager defaultManager];
119 NSDirectoryEnumerator* enumerator =
120 [fileManager enumeratorAtPath:[NSString stringWithUTF8String:folder.c_str()]];
122 while (file = [enumerator nextObject]) {
123 if ([file hasPrefix:
@"."]) {
128 [NSString stringWithFormat:
@"%@/%@", [NSString stringWithUTF8String:folder.c_str()], file];
129 [fileManager fileExistsAtPath:path isDirectory:&isDirectory];
131 subdirectories.push_back(std::string([file UTF8String]));
134 return subdirectories;
138 NSBundle* bundle = [NSBundle mainBundle];
139 NSString* resourceDirectoryPath = [bundle bundlePath];
140 NSString* path = [resourceDirectoryPath stringByAppendingString:
@"/"];
141 return [path UTF8String];
static std::vector< std::string > GetFilesInFolder(const std::string &folder_path)
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path.
static std::vector< std::string > GetSubdirectoriesInFolder(const std::string &folder_path)
std::string GetBundleResourcePath()
GetBundleResourcePath returns the path to the bundle resource directory. Specific to MacOS.