2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_BrowserWindow)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
auto pBrowserWindow::directory(BrowserWindow::State& state) -> string {
|
2013-03-19 08:48:50 +00:00
|
|
|
string result;
|
|
|
|
|
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2013-03-19 08:48:50 +00:00
|
|
|
if(state.title) [panel setTitle:[NSString stringWithUTF8String:state.title]];
|
|
|
|
[panel setCanChooseDirectories:YES];
|
|
|
|
[panel setCanChooseFiles:NO];
|
|
|
|
if([panel runModalForDirectory:[NSString stringWithUTF8String:state.path] file:nil] == NSOKButton) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSArray* names = [panel filenames];
|
|
|
|
const char* name = [[names objectAtIndex:0] UTF8String];
|
2013-03-19 08:48:50 +00:00
|
|
|
if(name) result = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pBrowserWindow::open(BrowserWindow::State& state) -> string {
|
2013-03-15 13:11:33 +00:00
|
|
|
string result;
|
|
|
|
|
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSMutableArray* filters = [[NSMutableArray alloc] init];
|
|
|
|
for(auto& rule : state.filters) {
|
2016-05-16 09:51:12 +00:00
|
|
|
string pattern = rule.split("(", 1L)(1).trimRight(")", 1L);
|
|
|
|
if(pattern) [filters addObject:[NSString stringWithUTF8String:pattern]];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2013-03-19 08:48:50 +00:00
|
|
|
if(state.title) [panel setTitle:[NSString stringWithUTF8String:state.title]];
|
2013-03-15 13:11:33 +00:00
|
|
|
[panel setCanChooseDirectories:NO];
|
|
|
|
[panel setCanChooseFiles:YES];
|
|
|
|
[panel setAllowedFileTypes:filters];
|
2013-03-19 08:48:50 +00:00
|
|
|
if([panel runModalForDirectory:[NSString stringWithUTF8String:state.path] file:nil] == NSOKButton) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSArray* names = [panel filenames];
|
|
|
|
const char* name = [[names objectAtIndex:0] UTF8String];
|
2013-03-19 08:48:50 +00:00
|
|
|
if(name) result = name;
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
[filters release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pBrowserWindow::save(BrowserWindow::State& state) -> string {
|
2013-03-15 13:11:33 +00:00
|
|
|
string result;
|
|
|
|
|
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSMutableArray* filters = [[NSMutableArray alloc] init];
|
|
|
|
for(auto& rule : state.filters) {
|
2016-05-16 09:51:12 +00:00
|
|
|
string pattern = rule.split("(", 1L)(1).trimRight(")", 1L);
|
|
|
|
if(pattern) [filters addObject:[NSString stringWithUTF8String:pattern]];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
NSSavePanel* panel = [NSSavePanel savePanel];
|
2013-03-19 08:48:50 +00:00
|
|
|
if(state.title) [panel setTitle:[NSString stringWithUTF8String:state.title]];
|
2013-03-15 13:11:33 +00:00
|
|
|
[panel setAllowedFileTypes:filters];
|
2013-03-19 08:48:50 +00:00
|
|
|
if([panel runModalForDirectory:[NSString stringWithUTF8String:state.path] file:nil] == NSOKButton) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSArray* names = [panel filenames];
|
|
|
|
const char* name = [[names objectAtIndex:0] UTF8String];
|
2013-03-19 08:48:50 +00:00
|
|
|
if(name) result = name;
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
[filters release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
|
|
|
|
#endif
|