2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
2013-03-19 08:48:50 +00:00
|
|
|
string pBrowserWindow::directory(BrowserWindow::State &state) {
|
|
|
|
string result;
|
|
|
|
|
|
|
|
@autoreleasepool {
|
|
|
|
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
|
|
|
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) {
|
|
|
|
NSArray *names = [panel filenames];
|
|
|
|
const char *name = [[names objectAtIndex:0] UTF8String];
|
|
|
|
if(name) result = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string pBrowserWindow::open(BrowserWindow::State &state) {
|
2013-03-15 13:11:33 +00:00
|
|
|
string result;
|
|
|
|
|
|
|
|
@autoreleasepool {
|
|
|
|
NSMutableArray *filters = [[NSMutableArray alloc] init];
|
2013-03-19 08:48:50 +00:00
|
|
|
for(auto &rule : state.filters) {
|
2013-03-15 13:11:33 +00:00
|
|
|
string pattern = rule.split<1>("(")(1).rtrim<1>(")");
|
|
|
|
if(!pattern.empty()) [filters addObject:[NSString stringWithUTF8String:pattern]];
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
NSArray *names = [panel filenames];
|
|
|
|
const char *name = [[names objectAtIndex:0] UTF8String];
|
|
|
|
if(name) result = name;
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
[filters release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:48:50 +00:00
|
|
|
string pBrowserWindow::save(BrowserWindow::State &state) {
|
2013-03-15 13:11:33 +00:00
|
|
|
string result;
|
|
|
|
|
|
|
|
@autoreleasepool {
|
|
|
|
NSMutableArray *filters = [[NSMutableArray alloc] init];
|
2013-03-19 08:48:50 +00:00
|
|
|
for(auto &rule : state.filters) {
|
2013-03-15 13:11:33 +00:00
|
|
|
string pattern = rule.split<1>("(")(1).rtrim<1>(")");
|
|
|
|
if(!pattern.empty()) [filters addObjects:[NSString stringWithUTF8String:pattern]];
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
NSArray *names = [panel filenames];
|
|
|
|
const char *name = [[names objectAtIndex:0] UTF8String];
|
|
|
|
if(name) result = name;
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
[filters release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|