From: Felix Paul Kühne Date: Mon, 11 Jun 2012 12:00:32 +0000 (+0200) Subject: macosx: fixed table column duplication by moving the dynamic column generation from... X-Git-Tag: 2.1.0-git~4091 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=bc8f5562c5f15d75e025349127d6af735a074cbb;p=vlc macosx: fixed table column duplication by moving the dynamic column generation from VLCPlaylistCommon to VLCPlaylist, where it belongs (close #6928) --- diff --git a/extras/package/macosx/Resources/English.lproj/MainMenu.xib b/extras/package/macosx/Resources/English.lproj/MainMenu.xib index 45a79a93b8..4362622796 100644 --- a/extras/package/macosx/Resources/English.lproj/MainMenu.xib +++ b/extras/package/macosx/Resources/English.lproj/MainMenu.xib @@ -21,16 +21,16 @@ YES - - - - + + - + + + - + YES @@ -445,10 +445,9 @@ 15 - -71303168 + -88080384 - 10thaniversary-mainPlaylistView 1 4 15 diff --git a/modules/gui/macosx/playlist.h b/modules/gui/macosx/playlist.h index 2d770a2664..433bd1396f 100644 --- a/modules/gui/macosx/playlist.h +++ b/modules/gui/macosx/playlist.h @@ -65,8 +65,6 @@ - (playlist_item_t *)currentPlaylistRoot; - (playlist_item_t *)selectedPlaylistItem; - (NSOutlineView *)outlineView; - -- (void)setColumn: (NSString *)o_column state: (NSInteger)i_state; @end /***************************************************************************** @@ -151,4 +149,6 @@ - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue; - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue; + +- (void)setColumn: (NSString *)o_column state: (NSInteger)i_state; @end diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m index abad412b8f..215ccf1883 100644 --- a/modules/gui/macosx/playlist.m +++ b/modules/gui/macosx/playlist.m @@ -134,18 +134,6 @@ *****************************************************************************/ @implementation VLCPlaylistCommon -+ (void)initialize{ - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSMutableArray * o_columnArray = [[NSMutableArray alloc] init]; - [o_columnArray addObject: [NSArray arrayWithObjects: TITLE_COLUMN, [NSNumber numberWithFloat: 190.], nil]]; - [o_columnArray addObject: [NSArray arrayWithObjects: ARTIST_COLUMN, [NSNumber numberWithFloat: 95.], nil]]; - [o_columnArray addObject: [NSArray arrayWithObjects: DURATION_COLUMN, [NSNumber numberWithFloat: 95.], nil]]; - NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:o_columnArray] forKey:@"PlaylistColumnSelection"]; - - [defaults registerDefaults:appDefaults]; - [o_columnArray release]; -} - - (id)init { playlist_t * p_playlist = pl_Get( VLCIntf ); @@ -176,30 +164,6 @@ [[o_tc_name_other headerCell] setStringValue:_NS("Name")]; [[o_tc_author_other headerCell] setStringValue:_NS("Author")]; [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")]; - - NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"]; - NSUInteger count = [o_columnArray count]; - - id o_menu = [[VLCMain sharedInstance] mainMenu]; - NSString * o_column; - for (NSUInteger i = 0; i < count; i++) - { - o_column = [[o_columnArray objectAtIndex:i] objectAtIndex:0]; - if ([o_column isEqualToString:@"status"]) - continue; - - [self setColumn: o_column state: NSOnState]; - [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column]; - [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]]; - } - - [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil]; -} - -- (void)applicationWillTerminate:(NSNotification *)notification -{ - /* let's make sure we save the correct widths and positions, since this likely changed since the last time the user played with the column selection */ - [self saveTableColumns]; } - (void)setPlaylistRoot: (playlist_item_t *)root_item @@ -225,68 +189,6 @@ pointerValue]; } -- (void)setColumn: (NSString *)o_column state: (NSInteger)i_state -{ - NSTableColumn * o_work_tc; - - if (i_state == NSOnState) - { - o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column]; - [o_work_tc setEditable: NO]; - [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]]; - - /* we cannot use a makro here, because gettext isn't clever enough for that */ - if ([o_column isEqualToString: TRACKNUM_COLUMN]) - { - [o_work_tc setMaxWidth: 20.]; - [[o_work_tc headerCell] setStringValue: @"#"]; - } - else if ([o_column isEqualToString: TITLE_COLUMN]) - { - [[o_work_tc headerCell] setStringValue: _NS("Name")]; - [o_work_tc setResizingMask: NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask]; - } - else if ([o_column isEqualToString: ARTIST_COLUMN]) - [[o_work_tc headerCell] setStringValue: _NS("Author")]; - else if ([o_column isEqualToString: DURATION_COLUMN]) - [[o_work_tc headerCell] setStringValue: _NS("Duration")]; - else if ([o_column isEqualToString: GENRE_COLUMN]) - [[o_work_tc headerCell] setStringValue: _NS("Genre")]; - else if ([o_column isEqualToString: ALBUM_COLUMN]) - [[o_work_tc headerCell] setStringValue: _NS("Album")]; - else if ([o_column isEqualToString: DESCRIPTION_COLUMN]) - [[o_work_tc headerCell] setStringValue: _NS("Description")]; - else if ([o_column isEqualToString: DATE_COLUMN]) - [[o_work_tc headerCell] setStringValue: _NS("Date")]; - else if ([o_column isEqualToString: LANGUAGE_COLUMN]) - [[o_work_tc headerCell] setStringValue: _NS("Language")]; - - [o_outline_view addTableColumn: o_work_tc]; - [o_work_tc release]; - [o_outline_view reloadData]; - [o_outline_view setNeedsDisplay: YES]; - } - else - [o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]]; - - [self saveTableColumns]; -} - -- (void)saveTableColumns -{ - NSMutableArray * o_arrayToSave = [[NSMutableArray alloc] init]; - NSArray * o_columns = [o_outline_view tableColumns]; - NSUInteger count = [o_columns count]; - NSTableColumn * o_currentColumn; - for (NSUInteger i = 0; i < count; i++) - { - o_currentColumn = [o_columns objectAtIndex: i]; - [o_arrayToSave addObject: [NSArray arrayWithObjects: [o_currentColumn identifier], [NSNumber numberWithFloat: [o_currentColumn width]], nil]]; - } - [[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"]; - [o_arrayToSave release]; -} - @end @implementation VLCPlaylistCommon (NSOutlineViewDataSource) @@ -537,6 +439,18 @@ *****************************************************************************/ @implementation VLCPlaylist ++ (void)initialize{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSMutableArray * o_columnArray = [[NSMutableArray alloc] init]; + [o_columnArray addObject: [NSArray arrayWithObjects: TITLE_COLUMN, [NSNumber numberWithFloat: 190.], nil]]; + [o_columnArray addObject: [NSArray arrayWithObjects: ARTIST_COLUMN, [NSNumber numberWithFloat: 95.], nil]]; + [o_columnArray addObject: [NSArray arrayWithObjects: DURATION_COLUMN, [NSNumber numberWithFloat: 95.], nil]]; + NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:o_columnArray] forKey:@"PlaylistColumnSelection"]; + + [defaults registerDefaults:appDefaults]; + [o_columnArray release]; +} + - (id)init { self = [super init]; @@ -583,6 +497,30 @@ o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage]; o_tc_sortColumn = nil; + + NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"]; + NSUInteger count = [o_columnArray count]; + + id o_menu = [[VLCMain sharedInstance] mainMenu]; + NSString * o_column; + for (NSUInteger i = 0; i < count; i++) + { + o_column = [[o_columnArray objectAtIndex:i] objectAtIndex:0]; + if ([o_column isEqualToString:@"status"]) + continue; + + [self setColumn: o_column state: NSOnState]; + [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column]; + [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]]; + } + + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil]; +} + +- (void)applicationWillTerminate:(NSNotification *)notification +{ + /* let's make sure we save the correct widths and positions, since this likely changed since the last time the user played with the column selection */ + [self saveTableColumns]; } - (void)searchfieldChanged:(NSNotification *)o_notification @@ -621,8 +559,7 @@ NSUInteger count = [[o_outline_view tableColumns] count]; for( NSUInteger i = 0 ; i < count ; i++ ) { - [o_outline_view setIndicatorImage:nil inTableColumn: - [[o_outline_view tableColumns] objectAtIndex:i]]; + [o_outline_view setIndicatorImage:nil inTableColumn: [[o_outline_view tableColumns] objectAtIndex:i]]; } [o_outline_view setHighlightedTableColumn:nil]; @@ -1534,6 +1471,69 @@ { return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain]; } + +- (void)setColumn: (NSString *)o_column state: (NSInteger)i_state +{ + NSTableColumn * o_work_tc; + + if (i_state == NSOnState) + { + o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column]; + [o_work_tc setEditable: NO]; + [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]]; + + /* we cannot use a makro here, because gettext isn't clever enough for that */ + if ([o_column isEqualToString: TRACKNUM_COLUMN]) + { + [o_work_tc setMaxWidth: 20.]; + [[o_work_tc headerCell] setStringValue: @"#"]; + } + else if ([o_column isEqualToString: TITLE_COLUMN]) + { + [[o_work_tc headerCell] setStringValue: _NS("Name")]; + [o_work_tc setResizingMask: NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask]; + } + else if ([o_column isEqualToString: ARTIST_COLUMN]) + [[o_work_tc headerCell] setStringValue: _NS("Author")]; + else if ([o_column isEqualToString: DURATION_COLUMN]) + [[o_work_tc headerCell] setStringValue: _NS("Duration")]; + else if ([o_column isEqualToString: GENRE_COLUMN]) + [[o_work_tc headerCell] setStringValue: _NS("Genre")]; + else if ([o_column isEqualToString: ALBUM_COLUMN]) + [[o_work_tc headerCell] setStringValue: _NS("Album")]; + else if ([o_column isEqualToString: DESCRIPTION_COLUMN]) + [[o_work_tc headerCell] setStringValue: _NS("Description")]; + else if ([o_column isEqualToString: DATE_COLUMN]) + [[o_work_tc headerCell] setStringValue: _NS("Date")]; + else if ([o_column isEqualToString: LANGUAGE_COLUMN]) + [[o_work_tc headerCell] setStringValue: _NS("Language")]; + + [o_outline_view addTableColumn: o_work_tc]; + [o_work_tc release]; + [o_outline_view reloadData]; + [o_outline_view setNeedsDisplay: YES]; + } + else + [o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]]; +} + +- (void)saveTableColumns +{ + NSMutableArray * o_arrayToSave = [[NSMutableArray alloc] init]; + NSArray * o_columns = [[NSArray alloc] initWithArray:[o_outline_view tableColumns]]; + NSUInteger count = [o_columns count]; + NSTableColumn * o_currentColumn; + for (NSUInteger i = 0; i < count; i++) + { + o_currentColumn = [o_columns objectAtIndex: i]; + [o_arrayToSave addObject: [NSArray arrayWithObjects: [o_currentColumn identifier], [NSNumber numberWithFloat: [o_currentColumn width]], nil]]; + } + [[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + [o_columns release]; + [o_arrayToSave release]; +} + @end @implementation VLCPlaylist (NSOutlineViewDataSource)