Archived
1

Added "Show in Browser" functionality

This commit is contained in:
Kim Wittenburg
2012-06-17 22:24:54 +02:00
parent cf3b960d85
commit 1295f22371
7 changed files with 252 additions and 34 deletions

View File

@@ -9,7 +9,7 @@
#import "MainController.h"
@implementation MainController {
NSMutableArray *data;
NSMutableArray *loadedResults;
id<LyricsHoster> currentHoster;
BOOL lyricsSelected;
NSInteger selectedSavePanelButton;
@@ -35,7 +35,7 @@
-(id)init {
iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
data = [[NSMutableArray alloc] init];
loadedResults = [[NSMutableArray alloc] init];
currentHoster = [[Magistrix alloc] init];
return [super init];
}
@@ -43,11 +43,11 @@
#pragma mark -
#pragma mark Outline view Data Source and Delegate
-(NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
return item == nil ? [data count] : 0;
return item == nil ? [loadedResults count] : 0;
}
-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
return [data objectAtIndex:index];
return [loadedResults objectAtIndex:index];
}
-(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
@@ -108,14 +108,14 @@
NSRunAlertPanel(NSLocalizedString(@"Hoster.messages.noResults.title", @""), NSLocalizedString(@"Hoster.messages.noResults.detail", @""), NSLocalizedString(@"OK", @""), nil, nil);
return;
}
[data addObjectsFromArray:nextResults];
[loadedResults addObjectsFromArray:nextResults];
[resultsOutline reloadData];
[loadMoreResultsButton setEnabled:[currentHoster hasMoreResults]];
}
-(IBAction)resetLoadedResults:(id)sender {
[currentHoster resetLoadedResults];
[data removeAllObjects];
[loadedResults removeAllObjects];
[resultsOutline reloadData];
[loadMoreResultsButton setEnabled:[currentHoster hasMoreResults]];
[self lyricsSelectionChanged:resultsOutline];
@@ -134,7 +134,7 @@
} else {
if (selectedRow != index) {
lyricsSelected = YES;
SearchResult *result = [data objectAtIndex:index];
SearchResult *result = [loadedResults objectAtIndex:index];
Lyrics *lyrics = [currentHoster lyricsBySearchResult:result];
currentLyrics = lyrics;
if (lyrics == nil) {
@@ -204,6 +204,15 @@
[savePanel beginSheetModalForWindow:window completionHandler:handler];
}
- (IBAction)showLyricsInBrowser:(id)sender {
int row = [resultsOutline clickedRow];
if (row < 0) {
row = [resultsOutline selectedRow];
}
NSURL *link = [[loadedResults objectAtIndex:row] link];
[[NSWorkspace sharedWorkspace] openURL:link];
}
-(void) savePanelDidClose: (NSNotification *) notification{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidEndSheetNotification object:window];
if (selectedSavePanelButton == NSOKButton) {
@@ -254,6 +263,15 @@
if (action == @selector(showPreview:)) {
return [resultsOutline clickedRow] >= 0;
}
if (action == @selector(showLyricsInBrowser:)) {
if ([resultsOutline clickedRow] >= 0) {
return YES;
} else if ([resultsOutline selectedRow] >= 0) {
return YES;
} else {
return NO;
}
}
return [self respondsToSelector:[item action]];
}