looper/backends/ui/imgui/file_browser_osx.mm
Zachary Hall 51d4ed39ab
Some checks failed
Build / build-gentoo (push) Failing after 14s
Build / download-system-deps (push) Successful in 3m28s
Build / get-source-code (push) Successful in 9m18s
Build / build-deb (push) Failing after 3m41s
Build / build-appimage (push) Successful in 4m12s
Build / build-android (push) Failing after 2m47s
Build / build-windows (push) Failing after 7m10s
Add support for macOS
- Remove unused OpenMP from playback backend
  - Fix update_assets on macOS
  - Add support for Objective C++ on macOS
  - Add macOS-specific code into the Dear ImGui backend
  - Add macOS .app packaging
  - Add support for global menus, and include support for macOS global menu into the Dear ImGui backend
2025-02-09 10:13:46 -08:00

52 lines
1.9 KiB
Text

#include <Foundation/Foundation.h>
#include <Cocoa/Cocoa.h>
#include <UniformTypeIdentifiers/UTCoreTypes.h>
#include <vector>
#include <string>
extern "C++" {
UTType *GetUTIFromExtension(NSString *extension) {
return [UTType typeWithFilenameExtension:extension];
}
NSMutableArray *ConvertExtensions(std::vector<std::string> input) {
NSMutableArray *arr = [[[NSMutableArray alloc] init] autorelease];
for (auto &str : input) {
UTType *maybeUTI = GetUTIFromExtension([NSString stringWithUTF8String:str.c_str()]);
if (maybeUTI != nil) {
[arr addObject:maybeUTI];
}
}
return arr;
}
const char *OpenDialog(std::vector<std::string> fileTypes, std::string initialDirectory) {
NSMutableArray *arr = ConvertExtensions(fileTypes);
NSOpenPanel* openFileDialog = [[[NSOpenPanel alloc] init] autorelease];
[openFileDialog setCanChooseFiles:YES];
[openFileDialog setCanChooseDirectories:NO];
[openFileDialog setAllowsMultipleSelection:NO];
[openFileDialog setAllowedContentTypes:arr];
[openFileDialog setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:initialDirectory.c_str()]]];
NSModalResponse response = [openFileDialog runModal];
if (response == NSModalResponseOK) {
return [[(NSURL*)[[openFileDialog URLs] objectAtIndex:0] path] UTF8String];
} else {
return nullptr;
}
}
const char *SaveDialog(std::vector<std::string> fileTypes, std::string initialDirectory) {
NSSavePanel *panel = [[[NSSavePanel alloc] init] autorelease];
[panel setCanCreateDirectories:YES];
NSMutableArray *arr = ConvertExtensions(fileTypes);
[panel setAllowedContentTypes:arr];
[panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:initialDirectory.c_str()]]];
NSModalResponse response = [panel runModal];
if (response == NSModalResponseOK) {
return [[[panel URL] path] UTF8String];
} else {
return nullptr;
}
}
}