Skip to content

Instantly share code, notes, and snippets.

@vade
Created September 25, 2011 00:23
Show Gist options
  • Save vade/1240039 to your computer and use it in GitHub Desktop.
Save vade/1240039 to your computer and use it in GitHub Desktop.
- (IBAction)filemenu_addToLibrary:(id)sender{
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
[openPanel setAllowsMultipleSelection:YES];
[openPanel setCanChooseFiles:YES];
[openPanel setCanCreateDirectories:NO];
[openPanel setCanChooseDirectories:YES];
NSInteger result = [openPanel runModal];
if(result != NSOKButton){
return;
}
double max = [[openPanel URLs] count];
[importProgress setMaxValue:max];
[[NSApplication sharedApplication] beginSheet:importSheet
modalForWindow:libraryWindow
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
for(NSURL* aURL in [openPanel URLs])
{
NSString* aPath = [aURL path];
[aPath retain];
DLog(@"importing: %@", aPath);
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.database addGamesFromPath:aPath toCollection:nil searchSubfolders:YES];
});
[importCurrentItem setStringValue:aPath];
[importProgress incrementBy:1.0];
[importSheet display];
[aPath release];
}
DLog(@"Finished Importing");
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
[importSheet close];
NSLog(@"Finished Importing");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment