[vlc-commits] macosx: restore playlist column selection, position and siz (close #501)
Felix Paul Kühne
git at videolan.org
Wed May 30 02:43:52 CEST 2012
vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Wed May 30 00:42:37 2012 +0200| [5e9ec8ba136d5a81430faeaeb1874c61365a7719] | committer: Felix Paul Kühne
macosx: restore playlist column selection, position and siz (close #501)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5e9ec8ba136d5a81430faeaeb1874c61365a7719
---
modules/gui/macosx/playlist.m | 60 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 54 insertions(+), 6 deletions(-)
diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index a264cbb..6c0fab8 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -134,6 +134,18 @@
*****************************************************************************/
@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 );
@@ -165,13 +177,29 @@
[[o_tc_author_other headerCell] setStringValue:_NS("Author")];
[[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
- [self setColumn: TITLE_COLUMN state: NSOnState];
- [self setColumn: ARTIST_COLUMN state: NSOnState];
- [self setColumn: DURATION_COLUMN state: NSOnState];
+ NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"];
+ NSUInteger count = [o_columnArray count];
+
id o_menu = [[VLCMain sharedInstance] mainMenu];
- [o_menu setPlaylistColumnTableState: NSOnState forColumn: TITLE_COLUMN];
- [o_menu setPlaylistColumnTableState: NSOnState forColumn: ARTIST_COLUMN];
- [o_menu setPlaylistColumnTableState: NSOnState forColumn: DURATION_COLUMN];
+ 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
@@ -214,7 +242,10 @@
[[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])
@@ -237,6 +268,23 @@
}
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
More information about the vlc-commits
mailing list