add file picker to osx
This commit is contained in:
@@ -97,6 +97,32 @@
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
- (std::string)pick_file_save:(NSArray<NSString*>*)types
|
||||
{
|
||||
NSSavePanel *panel = [NSSavePanel savePanel];
|
||||
[panel setCanCreateDirectories:YES];
|
||||
|
||||
[panel setAllowedFileTypes:types];
|
||||
|
||||
[self removeTrackingArea:trackingArea];
|
||||
if (!cursor_visible)
|
||||
[NSCursor unhide];
|
||||
|
||||
NSInteger clicked = [panel runModal];
|
||||
|
||||
[self addTrackingArea:trackingArea];
|
||||
if (!cursor_visible)
|
||||
[NSCursor hide];
|
||||
|
||||
std::string ret;
|
||||
if (clicked == NSFileHandlingPanelOKButton)
|
||||
{
|
||||
NSURL *url = [panel URL];
|
||||
LOG("selected file: %s", [[url path] cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
ret = [[url path] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
- (std::string)pick_dir
|
||||
{
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
- (void)async_unlock;
|
||||
- (void)async_swap;
|
||||
- (std::string)pick_file:(NSArray<NSString*>*)types;
|
||||
- (std::string)pick_file_save:(NSArray<NSString*>*)types;
|
||||
- (std::string)pick_dir;
|
||||
- (void)share_file:(NSString*)file_path;
|
||||
- (void)hockeyapp_crash;
|
||||
|
||||
@@ -204,15 +204,15 @@ void App::pick_file_save(std::vector<std::string> types, std::function<void (std
|
||||
// [ios_view pick_photo:callback];
|
||||
//});
|
||||
#elif __OSX__
|
||||
//dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// //NSArray* fileTypes = [NSArray arrayWithObjects:@"ppi", @"PPI", nil];
|
||||
// NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:types.size()];
|
||||
// for (const auto& t : types)
|
||||
// [fileTypes addObject:[NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]];
|
||||
// std::string path = [osx_view pick_file:fileTypes];
|
||||
// if (!path.empty())
|
||||
// callback(path);
|
||||
//});
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//NSArray* fileTypes = [NSArray arrayWithObjects:@"ppi", @"PPI", nil];
|
||||
NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:types.size()];
|
||||
for (const auto& t : types)
|
||||
[fileTypes addObject:[NSString stringWithCString:t.c_str() encoding:NSUTF8StringEncoding]];
|
||||
std::string path = [osx_view pick_file_save:fileTypes];
|
||||
if (!path.empty())
|
||||
callback(path);
|
||||
});
|
||||
#elif __ANDROID__
|
||||
//android_pick_file(callback);
|
||||
#elif _WIN32
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
NodeBorder* m_progress;
|
||||
NodeBorder* m_body;
|
||||
int m_total = 0;
|
||||
std::atomic_int m_count = 0;
|
||||
std::atomic_int m_count{0};
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void init() override;
|
||||
void increment() noexcept;
|
||||
|
||||
Reference in New Issue
Block a user