5#include "imgui/imgui.h"
7#if defined(__APPLE__) && defined(__MACH__)
9#include <TargetConditionals.h>
11#import <CoreText/CoreText.h>
13#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
15#import <UIKit/UIKit.h>
16#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
21static std::string selectedFile;
23void ShowOpenFileDialogImpl(
void (^completionHandler)(std::string)) {
25 [appDelegate PresentDocumentPickerWithCompletionHandler:^(NSString *filePath) {
26 selectedFile = std::string([filePath UTF8String]);
27 completionHandler(selectedFile);
31std::string ShowOpenFileDialogSync() {
32 __block std::string result;
34 ShowOpenFileDialogImpl(^(std::string filePath) {
43 return ShowOpenFileDialogSync();
49 const std::string &folder) {
54 const std::string &folder) {
58#elif TARGET_OS_MAC == 1
61#import <Cocoa/Cocoa.h>
64 NSOpenPanel* openPanel = [NSOpenPanel openPanel];
65 [openPanel setCanChooseFiles:YES];
66 [openPanel setCanChooseDirectories:NO];
67 [openPanel setAllowsMultipleSelection:NO];
69 if ([openPanel runModal] == NSModalResponseOK) {
70 NSURL* url = [[openPanel URLs] objectAtIndex:0];
71 NSString* path = [url path];
72 return std::string([path UTF8String]);
79 NSOpenPanel* openPanel = [NSOpenPanel openPanel];
80 [openPanel setCanChooseFiles:NO];
81 [openPanel setCanChooseDirectories:YES];
82 [openPanel setAllowsMultipleSelection:NO];
84 if ([openPanel runModal] == NSModalResponseOK) {
85 NSURL* url = [[openPanel URLs] objectAtIndex:0];
86 NSString* path = [url path];
87 return std::string([path UTF8String]);
94 const std::string& folder) {
95 std::vector<std::string> filenames;
96 NSFileManager* fileManager = [NSFileManager defaultManager];
97 NSDirectoryEnumerator* enumerator =
98 [fileManager enumeratorAtPath:[NSString stringWithUTF8String:folder.c_str()]];
100 while (file = [enumerator nextObject]) {
101 if ([file hasPrefix:
@"."]) {
104 filenames.push_back(std::string([file UTF8String]));
110 const std::string& folder) {
111 std::vector<std::string> subdirectories;
112 NSFileManager* fileManager = [NSFileManager defaultManager];
113 NSDirectoryEnumerator* enumerator =
114 [fileManager enumeratorAtPath:[NSString stringWithUTF8String:folder.c_str()]];
116 while (file = [enumerator nextObject]) {
117 if ([file hasPrefix:
@"."]) {
122 [NSString stringWithFormat:
@"%@/%@", [NSString stringWithUTF8String:folder.c_str()], file];
123 [fileManager fileExistsAtPath:path isDirectory:&isDirectory];
125 subdirectories.push_back(std::string([file UTF8String]));
128 return subdirectories;
static std::vector< std::string > GetSubdirectoriesInFolder(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 > GetFilesInFolder(const std::string &folder_path)