macosx: robustify playlist table columns initialization
authorDavid Fuhrmann <david.fuhrmann@googlemail.com>
Thu, 13 Mar 2014 18:06:58 +0000 (19:06 +0100)
committerDavid Fuhrmann <david.fuhrmann@googlemail.com>
Thu, 13 Mar 2014 18:32:36 +0000 (19:32 +0100)
Unknown columns might occur if the prefs are written
by a newer VLC version.

close #10664

modules/gui/macosx/MainMenu.h
modules/gui/macosx/MainMenu.m
modules/gui/macosx/playlist.m

index 36c33db..1fe68e4 100644 (file)
 - (IBAction)togglePlaymodeButtons:(id)sender;
 - (IBAction)toggleSidebar:(id)sender;
 - (IBAction)togglePlaylistColumnTable:(id)sender;
-- (void)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column;
+- (BOOL)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column;
 - (NSMenu *)setupPlaylistTableColumnsMenu;
 
 - (IBAction)quitAfterPlayback:(id)sender;
index e774752..baa83d2 100644 (file)
@@ -751,12 +751,18 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state translationDict: o_ptc_translation_dict];
 }
 
-- (void)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
+- (BOOL)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
 {
-    NSInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
+    NSUInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
+    // prevent setting unknown columns
+    if(i_tag == NSNotFound)
+        return NO;
+
     [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_state];
     [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_state];
     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_state translationDict: o_ptc_translation_dict];
+
+    return YES;
 }
 
 #pragma mark -
index 7c92bb6..5ceba5f 100644 (file)
         if ([o_column isEqualToString:@"status"])
             continue;
 
-        [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column];
+        if(![o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column])
+            continue;
+
         [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]];
     }
 
     NSTableColumn * o_work_tc;
 
     if (i_state == NSOnState) {
+        NSString *o_title = [o_dict objectForKey:o_column];
+        if (!o_title)
+            return;
+
         o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column];
         [o_work_tc setEditable: NO];
         [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]];