yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
file_dialog.mm
Go to the documentation of this file.
2
3#include <string>
4#include <vector>
5#include "imgui/imgui.h"
6
7#if defined(__APPLE__) && defined(__MACH__)
8/* Apple OSX and iOS (Darwin). */
9#include <TargetConditionals.h>
10
11#import <CoreText/CoreText.h>
12
13#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
14/* iOS in Xcode simulator */
15#import <UIKit/UIKit.h>
16#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
17
19
20namespace {
21static std::string selectedFile;
22
23void ShowOpenFileDialogImpl(void (^completionHandler)(std::string)) {
24 AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
25 [appDelegate PresentDocumentPickerWithCompletionHandler:^(NSString *filePath) {
26 selectedFile = std::string([filePath UTF8String]);
27 completionHandler(selectedFile);
28 }];
29}
30
31std::string ShowOpenFileDialogSync() {
32 __block std::string result;
33
34 ShowOpenFileDialogImpl(^(std::string filePath) {
35 result = filePath;
36 });
37
38 return result;
39}
40}
41
43 return ShowOpenFileDialogSync();
44}
45
47
49 const std::string &folder) {
50 return {};
51}
52
54 const std::string &folder) {
55 return {};
56}
57
58#elif TARGET_OS_MAC == 1
59/* macOS */
60
61#import <Cocoa/Cocoa.h>
62
64 NSOpenPanel* openPanel = [NSOpenPanel openPanel];
65 [openPanel setCanChooseFiles:YES];
66 [openPanel setCanChooseDirectories:NO];
67 [openPanel setAllowsMultipleSelection:NO];
68
69 if ([openPanel runModal] == NSModalResponseOK) {
70 NSURL* url = [[openPanel URLs] objectAtIndex:0];
71 NSString* path = [url path];
72 return std::string([path UTF8String]);
73 }
74
75 return "";
76}
77
79 NSOpenPanel* openPanel = [NSOpenPanel openPanel];
80 [openPanel setCanChooseFiles:NO];
81 [openPanel setCanChooseDirectories:YES];
82 [openPanel setAllowsMultipleSelection:NO];
83
84 if ([openPanel runModal] == NSModalResponseOK) {
85 NSURL* url = [[openPanel URLs] objectAtIndex:0];
86 NSString* path = [url path];
87 return std::string([path UTF8String]);
88 }
89
90 return "";
91}
92
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()]];
99 NSString* file;
100 while (file = [enumerator nextObject]) {
101 if ([file hasPrefix:@"."]) {
102 continue;
103 }
104 filenames.push_back(std::string([file UTF8String]));
105 }
106 return filenames;
107}
108
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()]];
115 NSString* file;
116 while (file = [enumerator nextObject]) {
117 if ([file hasPrefix:@"."]) {
118 continue;
119 }
120 BOOL isDirectory;
121 NSString* path =
122 [NSString stringWithFormat:@"%@/%@", [NSString stringWithUTF8String:folder.c_str()], file];
123 [fileManager fileExistsAtPath:path isDirectory:&isDirectory];
124 if (isDirectory) {
125 subdirectories.push_back(std::string([file UTF8String]));
126 }
127 }
128 return subdirectories;
129}
130#else
131// Unsupported platform
132#endif // TARGET_OS_MAC
133
134#endif // __APPLE__ && __MACH__
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)