From ca28ed71e6bf56dd4e85f8bf773414c2886c529b Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Fri, 6 Dec 2013 17:38:25 +0100 Subject: [PATCH] Add a contextual menu to check/uncheck multiple tracks in SBFileImport, plus minor cleanups. --- Classes/SBFileImport.h | 8 +- Classes/SBFileImport.m | 48 +++++++- English.lproj/FileImport.xib | 206 ++++++++++++++++++++++------------- 3 files changed, 177 insertions(+), 85 deletions(-) diff --git a/Classes/SBFileImport.h b/Classes/SBFileImport.h index f8ea640..8d06f57 100755 --- a/Classes/SBFileImport.h +++ b/Classes/SBFileImport.h @@ -22,11 +22,10 @@ NSMutableArray *_importCheckArray; NSMutableArray *_actionArray; - id delegate; - IBOutlet NSTableView *tableView; + id delegate; + IBOutlet NSTableView *tracksTableView; IBOutlet NSButton *addTracksButton; IBOutlet NSButton *importMetadata; - IBOutlet NSProgressIndicator *loadProgressBar; } - (instancetype)initWithDelegate:(id )del andFiles:(NSArray *)files error:(NSError **)outError; @@ -34,4 +33,7 @@ - (IBAction)closeWindow:(id)sender; - (IBAction)addTracks:(id)sender; +- (IBAction)checkSelected:(id)sender; +- (IBAction)uncheckSelected:(id)sender; + @end diff --git a/Classes/SBFileImport.m b/Classes/SBFileImport.m index 31c8532..8f5982f 100755 --- a/Classes/SBFileImport.m +++ b/Classes/SBFileImport.m @@ -116,7 +116,7 @@ if ([[_tracks objectAtIndex:row] isKindOfClass:[MP42Track class]]) return 1; - return 4; + return 6; } - (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex @@ -254,7 +254,7 @@ if ([tableColumn.identifier isEqualToString:@"trackAction"]) return [_actionArray objectAtIndex:rowIndex]; - } else if ([tableColumn.identifier isEqualToString:@"trackId"]) { + } else if ([tableColumn isEqual:[[tableView tableColumns] objectAtIndex:1]]) { return object; } @@ -272,10 +272,46 @@ [_actionArray replaceObjectAtIndex:rowIndex withObject:anObject]; } +- (void)toggleSelectionCheck:(BOOL)value +{ + NSIndexSet *selection = [tracksTableView selectedRowIndexes]; + NSInteger clickedRow = [tracksTableView clickedRow]; + + if (clickedRow != -1 && ![selection containsIndex:clickedRow]) + selection = [NSIndexSet indexSetWithIndex:clickedRow]; + + [selection enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { + [_importCheckArray replaceObjectAtIndex:idx withObject:@(value)]; + }]; + + [tracksTableView reloadDataForRowIndexes:selection columnIndexes:[NSIndexSet indexSetWithIndex:0]]; +} + +- (IBAction)checkSelected:(id)sender +{ + [self toggleSelectionCheck:YES]; +} + +- (IBAction)uncheckSelected:(id)sender +{ + [self toggleSelectionCheck:NO]; +} + +- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem +{ + SEL action = [anItem action]; + + if (action == @selector(uncheckSelected:) || action == @selector(checkSelected:)) + if ([tracksTableView selectedRow] != -1 || [tracksTableView clickedRow] != -1) + return YES; + + return NO; +} + - (IBAction)closeWindow:(id)sender { - [tableView setDelegate:nil]; - [tableView setDataSource:nil]; + [tracksTableView setDelegate:nil]; + [tracksTableView setDataSource:nil]; [NSApp endSheet:[self window] returnCode:NSOKButton]; [[self window] orderOut:self]; } @@ -379,8 +415,8 @@ [tracks release]; - [tableView setDelegate:nil]; - [tableView setDataSource:nil]; + [tracksTableView setDelegate:nil]; + [tracksTableView setDataSource:nil]; [NSApp endSheet:[self window] returnCode:NSOKButton]; [[self window] orderOut:self]; } diff --git a/English.lproj/FileImport.xib b/English.lproj/FileImport.xib index d5655fd..eef1132 100755 --- a/English.lproj/FileImport.xib +++ b/English.lproj/FileImport.xib @@ -15,7 +15,8 @@ NSButton NSButtonCell NSCustomObject - NSProgressIndicator + NSMenu + NSMenuItem NSScrollView NSScroller NSTableColumn @@ -323,13 +324,13 @@ 17 - -557809664 + -624918528 1 15 0 - NO + YES 0 1 @@ -342,31 +343,6 @@ 4 - - - -2147483392 - {{588, 17}, {15, 12}} - - - - NO - - _doScroller: - 0.99056603773584906 - - - - -2147483392 - {{1, 172}, {602, 16}} - - - - NO - 1 - - _doScroller: - 0.99834162520729686 - 2338 @@ -381,6 +357,31 @@ 4 + + + -2147483392 + {{588, 17}, {15, 12}} + + + + NO + + _doScroller: + 0.9941860465116279 + + + + -2147483392 + {{1, 172}, {602, 16}} + + + + NO + 1 + + _doScroller: + 0.99834162520729686 + {{20, 49}, {604, 189}} @@ -431,7 +432,6 @@ {{534, 13}, {96, 32}} - YES 603979776 @@ -471,23 +471,13 @@ NO - - - -2147483382 - {{155, 20}, {189, 20}} - - - - 16394 - 100 - 292 {{18, 22}, {127, 18}} - + YES -1543503872 @@ -523,6 +513,33 @@ SBFileImportWindow YES + + + + + + Uncheck + + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + + + + Check + + 2147483647 + + + + + NO @@ -559,14 +576,6 @@ 33 - - - loadProgressBar - - - - 35 - importMetadata @@ -575,13 +584,29 @@ 38 + + + uncheckSelected: + + + + UR1-gU-1lS + + + + checkSelected: + + + + eqx-lP-ybu + - tableView + tracksTableView - 31 + qn7-PC-KQu @@ -599,6 +624,14 @@ 24 + + + menu + + + + 63V-hm-RPy + @@ -642,7 +675,6 @@ - @@ -653,8 +685,8 @@ - + @@ -668,11 +700,6 @@ - - 8 - - - 13 @@ -712,11 +739,6 @@ - - 34 - - - 36 @@ -835,6 +857,30 @@ + + Nqo-5L-aDh + + + + + + + + + GIM-Js-R4l + + + + + w6q-DP-C0O + + + + + d1E-cV-kwd + + + @@ -861,7 +907,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -872,8 +917,11 @@ com.apple.InterfaceBuilder.CocoaPlugin SBTableView com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -887,23 +935,32 @@ NSWindowController id + id id + id addTracks: id + + checkSelected: + id + closeWindow: id + + uncheckSelected: + id + NSButton NSButton - NSProgressIndicator - NSTableView + NSTableView @@ -914,12 +971,8 @@ importMetadata NSButton - - loadProgressBar - NSProgressIndicator - - - tableView + + tracksTableView NSTableView @@ -975,10 +1028,11 @@ YES 3 - - NSSwitch - {15, 15} - + + {11, 11} + {10, 3} + {15, 15} +