]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/MainMenu.m
macosx: dynamically create context and main sub menu for playlist table header select...
[vlc] / modules / gui / macosx / MainMenu.m
index 3898f846e164c2db8b0397a4e67e99509761b8fa..f5ad19f4f743e523de1db9eb0a74a393eacb13b4 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * MainMenu.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2011 Felix Paul Kühne
+ * Copyright (C) 2011-2012 Felix Paul Kühne
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
 #import "simple_prefs.h"
 #import "coredialogs.h"
 #import "controls.h"
+#import "playlist.h"
 #import "playlistinfo.h"
-#import "vout.h"
+#import "VideoView.h"
 #import "CoreInteraction.h"
+#import "MainWindow.h"
+#import "ExtensionsManager.h"
+#import "ConvertAndSave.h"
 
 @implementation VLCMainMenu
 static VLCMainMenu *_o_sharedInstance = nil;
@@ -61,6 +65,22 @@ static VLCMainMenu *_o_sharedInstance = nil;
     else
     {
         _o_sharedInstance = [super init];
+
+        o_ptc_translation_dict = [NSDictionary dictionaryWithObjectsAndKeys:
+                      _NS("Track Number"),  TRACKNUM_COLUMN,
+                      _NS("Title"),         TITLE_COLUMN,
+                      _NS("Artist"),        ARTIST_COLUMN,
+                      _NS("Duration"),      DURATION_COLUMN,
+                      _NS("Genre"),         GENRE_COLUMN,
+                      _NS("Album"),         ALBUM_COLUMN,
+                      _NS("Description"),   DESCRIPTION_COLUMN,
+                      _NS("Date"),          DATE_COLUMN,
+                      _NS("Language"),      LANGUAGE_COLUMN,
+                      _NS("URI"),           URI_COLUMN,
+                      nil];
+        // this array also assigns tags (index) to type of menu item
+        o_ptc_menuorder = [NSArray arrayWithObjects:TRACKNUM_COLUMN, TITLE_COLUMN, ARTIST_COLUMN, DURATION_COLUMN,
+                       GENRE_COLUMN, ALBUM_COLUMN, DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN, nil];
     }
 
     return _o_sharedInstance;
@@ -69,7 +89,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
 - (void)dealloc
 {
     [[NSNotificationCenter defaultCenter] removeObserver: self];
-    
+
     if (b_nib_about_loaded)
         [o_about release];
 
@@ -82,12 +102,20 @@ static VLCMainMenu *_o_sharedInstance = nil;
     if (b_nib_tracksynchro_loaded)
         [o_trackSynchronization release];
 
+    if (b_nib_convertandsave_loaded)
+        [o_convertandsave release];
+
+    [o_extMgr release];
+
+    if( o_mu_playlistTableColumnsContextMenu )
+        [o_mu_playlistTableColumnsContextMenu release];
+
     [super dealloc];
 }
 
 - (void)awakeFromNib
 {
-    [[NSNotificationCenter defaultCenter] addObserver: self 
+    [[NSNotificationCenter defaultCenter] addObserver: self
                                              selector: @selector(applicationWillFinishLaunching:)
                                                  name: NSApplicationWillFinishLaunchingNotification
                                                object: nil];
@@ -107,6 +135,10 @@ static VLCMainMenu *_o_sharedInstance = nil;
      because VLCMain is the owner */
     if( b_mainMenu_setup ) return;
 
+    /* Get ExtensionsManager */
+    o_extMgr = [ExtensionsManager getInstance:p_intf];
+    [o_extMgr retain];
+
     [self initStrings];
 
     key = config_GetPsz( p_intf, "key-quit" );
@@ -217,6 +249,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
     [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
                              var: "intf-add" selector: @selector(toggleVar:)];
+
+    [self setupExtensionsMenu];
 }
 
 - (void)initStrings
@@ -226,6 +260,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
                            stringByAppendingString: @"..."]];
     [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
     [o_mi_prefs setTitle: _NS("Preferences...")];
+    [o_mi_extensions setTitle: _NS("Extensions")];
+    [o_mu_extensions setTitle: _NS("Extensions")];
     [o_mi_add_intf setTitle: _NS("Add Interface")];
     [o_mu_add_intf setTitle: _NS("Add Interface")];
     [o_mi_services setTitle: _NS("Services")];
@@ -241,8 +277,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_open_net setTitle: _NS("Open Network...")];
     [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
     [o_mi_open_recent setTitle: _NS("Open Recent")];
-    [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
     [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
+    [o_mi_convertandsave setTitle: _NS("Convert / Save...")];
 
     [o_mu_edit setTitle: _NS("Edit")];
     [o_mi_cut setTitle: _NS("Cut")];
@@ -254,6 +290,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mu_controls setTitle: _NS("Playback")];
     [o_mi_play setTitle: _NS("Play")];
     [o_mi_stop setTitle: _NS("Stop")];
+    [o_mi_record setTitle: _NS("Record")];
     [o_mi_rate setView: o_mi_rate_view];
     [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
     [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
@@ -269,6 +306,11 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
     [o_mi_fwd setTitle: _NS("Step Forward")];
     [o_mi_bwd setTitle: _NS("Step Backward")];
+    [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
+    [o_mi_toggleJumpButtons setState: config_GetInt( VLCIntf, "macosx-show-playback-buttons")];
+    [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
+    [o_mi_togglePlaymodeButtons setState: config_GetInt( VLCIntf, "macosx-show-playmode-buttons")];
+    [o_mu_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
 
     [o_mi_program setTitle: _NS("Program")];
     [o_mu_program setTitle: _NS("Program")];
@@ -366,15 +408,41 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_vmi_snapshot setTitle: _NS("Snapshot")];
 }
 
+- (NSMenu *)setupPlaylistTableColumnsMenu
+{
+    NSMenu *o_context_menu = [[NSMenu alloc] init];
+
+    NSMenuItem *o_mi_tmp;
+    for( NSUInteger i = 0; i < [o_ptc_menuorder count]; i++ )
+    {
+        NSString *o_title = [o_ptc_translation_dict objectForKey:[o_ptc_menuorder objectAtIndex:i]];
+        o_mi_tmp = [o_mu_playlistTableColumns addItemWithTitle:o_title
+                                                        action:@selector(togglePlaylistColumnTable:)
+                                                 keyEquivalent:@""];
+        [o_mi_tmp setTarget:self];
+        [o_mi_tmp setTag:i];
+
+        o_mi_tmp = [o_context_menu addItemWithTitle:o_title
+                                             action:@selector(togglePlaylistColumnTable:)
+                                      keyEquivalent:@""];
+        [o_mi_tmp setTarget:self];
+        [o_mi_tmp setTag:i];
+    }
+    if( !o_mu_playlistTableColumnsContextMenu )
+        o_mu_playlistTableColumnsContextMenu = [o_context_menu retain];
+    return [o_context_menu autorelease];
+}
+
 #pragma mark -
 #pragma mark Termination
 
 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
 {
     if( !p_intf ) return;
-    
+
     NSArray *menuitems_array = [the_menu itemArray];
-    for( int i=0; i<[menuitems_array count]; i++ )
+    NSUInteger menuItemCount = [menuitems_array count];
+    for( NSUInteger i=0; i < menuItemCount; i++ )
     {
         NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
         if( [one_item hasSubmenu] )
@@ -393,6 +461,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
     if( p_input != NULL )
     {
+        [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
+
         [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
                                  var: "program" selector: @selector(toggleVar:)];
 
@@ -426,24 +496,19 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
             [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
                                      var: "visual" selector: @selector(toggleVar:)];
-            vlc_object_release( (vlc_object_t *)p_aout );
+            vlc_object_release( p_aout );
         }
 
         vout_thread_t * p_vout = input_GetVout( p_input );
 
         if( p_vout != NULL )
         {
-            vlc_object_t * p_dec_obj;
-
             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
 
             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
                                      var: "crop" selector: @selector(toggleVar:)];
 
-            [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
-                                     var: "video-device" selector: @selector(toggleVar:)];
-
             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
                                      var: "deinterlace" selector: @selector(toggleVar:)];
 
@@ -455,35 +520,44 @@ static VLCMainMenu *_o_sharedInstance = nil;
              (vlc_object_t *)p_vout var:"postprocess" selector:
              @selector(toggleVar:)];
 #endif
-            vlc_object_release( (vlc_object_t *)p_vout );
+            vlc_object_release( p_vout );
+
+            [self refreshVoutDeviceMenu:nil];
         }
         vlc_object_release( p_input );
     }
+    else
+        [o_mi_record setEnabled: NO];
 }
 
 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
 {
-    int x, y = 0;
-    vout_thread_t * p_vout = getVout();
-    if( !p_vout )
-        return;
-
-    /* clean the menu before adding new entries */
-    if( [o_mi_screen hasSubmenu] )
+    NSUInteger count = [o_mu_screen numberOfItems];
+    NSMenu * o_submenu = o_mu_screen;
+    if (count > 0)
+        [o_submenu removeAllItems];
+
+    NSArray * o_screens = [NSScreen screens];
+    NSMenuItem * o_mitem;
+    count = [o_screens count];
+    [o_mi_screen setEnabled: YES];
+    [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
+    o_mitem = [o_submenu itemAtIndex: 0];
+    [o_mitem setTag: 0];
+    [o_mitem setEnabled: YES];
+    [o_mitem setTarget: self];
+    NSRect s_rect;
+    for (NSUInteger i = 0; i < count; i++)
     {
-        y = [[o_mi_screen submenu] numberOfItems] - 1;
-        msg_Dbg( VLCIntf, "%i items in submenu", y );
-        while( x != y )
-        {
-            msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
-            [[o_mi_screen submenu] removeItemAtIndex: x];
-            x++;
-        }
+        s_rect = [[o_screens objectAtIndex: i] frame];
+        [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
+                                      (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
+        o_mitem = [o_submenu itemAtIndex:i+1];
+        [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
+        [o_mitem setEnabled: YES];
+        [o_mitem setTarget: self];
     }
-
-    [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
-                             var: "video-device" selector: @selector(toggleVar:)];
-    vlc_object_release( (vlc_object_t *)p_vout );
+    [[o_submenu itemWithTag: var_InheritInteger( VLCIntf, "macosx-vdev" )] setState: NSOnState];
 }
 
 - (void)setSubmenusEnabled:(BOOL)b_enabled
@@ -512,9 +586,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_rate_sld setEnabled: b_enabled];
     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
-    if (i == 0)
-        i = 1;
-    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
+    double speed =  pow( 2, (double)i / 17 );
+    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
     if (b_enabled) {
         [o_mi_rate_lbl setHidden: NO];
         [o_mi_rate_lbl_gray setHidden: YES];
@@ -528,38 +601,163 @@ static VLCMainMenu *_o_sharedInstance = nil;
 }
 
 #pragma mark -
-#pragma mark Recent Items
-- (void)openRecentItem:(id)item
-{
-    [[VLCMain sharedInstance] application: nil openFile: [item title]];
-}
+#pragma mark Extensions
 
-- (IBAction)clearRecentItems:(id)sender
+- (void)setupExtensionsMenu
 {
-    [[NSDocumentController sharedDocumentController]
-     clearRecentDocuments: nil];
+    /* Load extensions if needed */
+    // TODO: Implement preference for autoloading extensions on mac
+
+    // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
+    //     && ![o_extMgr isLoaded] )
+    // {
+    //     return;
+    // }
+
+    if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
+    {
+        [o_extMgr loadExtensions];
+    }
+
+    /* Let the ExtensionsManager itself build the menu */
+    [o_extMgr buildMenu:o_mu_extensions];
+    [o_mi_extensions setEnabled: ( [o_mu_extensions numberOfItems] > 0 )];
 }
 
 #pragma mark -
 #pragma mark Playback
+- (IBAction)toggleRecord:(id)sender
+{
+    [[VLCCoreInteraction sharedInstance] toggleRecord];
+}
+
+- (void)updateRecordState:(BOOL)b_value
+{
+    [o_mi_record setState:b_value];
+}
+
 - (IBAction)setPlaybackRate:(id)sender
 {
     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
-    if (i == 0)
-        i = 1;
-    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
+    double speed =  pow( 2, (double)i / 17 );
+    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
 }
 
 - (void)updatePlaybackRate
 {
     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
-    if (i == 0)
-        i = 1;
-    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
+    double speed =  pow( 2, (double)i / 17 );
+    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
     [o_mi_rate_sld setIntValue: i];
 }
 
+- (IBAction)toggleJumpButtons:(id)sender
+{
+    BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playback-buttons" );
+    config_PutInt( VLCIntf, "macosx-show-playback-buttons", b_value );
+    [[[VLCMain sharedInstance] mainWindow] toggleJumpButtons];
+    [o_mi_toggleJumpButtons setState: b_value];
+}
+
+- (IBAction)togglePlaymodeButtons:(id)sender
+{
+    BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playmode-buttons" );
+    config_PutInt( VLCIntf, "macosx-show-playmode-buttons", b_value );
+    [[[VLCMain sharedInstance] mainWindow] togglePlaymodeButtons];
+    [o_mi_togglePlaymodeButtons setState: b_value];
+}
+
+- (IBAction)togglePlaylistColumnTable:(id)sender
+{
+    NSInteger i_new_state = ![sender state];
+    NSInteger i_tag = [sender tag];
+    [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_new_state];
+    [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_new_state];
+
+    NSString *o_column = [o_ptc_menuorder objectAtIndex: i_tag];
+    [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state];
+}
+
+- (void)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
+{
+    NSInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
+    [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_state];
+    [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_state];
+}
+
+#pragma mark -
+#pragma mark video menu
+- (IBAction)toggleFullscreen:(id)sender
+{
+    [[VLCCoreInteraction sharedInstance] toggleFullscreen];
+}
+
+- (IBAction)resizeVideoWindow:(id)sender
+{
+    input_thread_t *p_input = pl_CurrentInput( VLCIntf );
+    if (p_input)
+    {
+        vout_thread_t *p_vout = getVout();
+        if (p_vout)
+        {
+            if (sender == o_mi_half_window)
+                var_SetFloat( p_vout, "zoom", 0.5 );
+            else if (sender == o_mi_normal_window)
+                var_SetFloat( p_vout, "zoom", 1.0 );
+            else if (sender == o_mi_double_window)
+                var_SetFloat( p_vout, "zoom", 2.0 );
+            else
+            {
+                [[[[[VLCMain sharedInstance] mainWindow] videoView] window] performZoom:sender];
+            }
+            vlc_object_release( p_vout );
+        }
+        vlc_object_release( p_input );
+    }
+}
+
+- (IBAction)floatOnTop:(id)sender
+{
+    input_thread_t *p_input = pl_CurrentInput( VLCIntf );
+    if (p_input)
+    {
+        vout_thread_t *p_vout = getVout();
+        if (p_vout)
+        {
+            var_ToggleBool( p_vout, "video-on-top" );
+            vlc_object_release( p_vout );
+        }
+        vlc_object_release( p_input );
+    }
+}
+
+- (IBAction)createVideoSnapshot:(id)sender
+{
+    input_thread_t *p_input = pl_CurrentInput( VLCIntf );
+    if (p_input)
+    {
+        vout_thread_t *p_vout = getVout();
+        if (p_vout)
+        {
+            var_TriggerCallback( p_vout, "video-snapshot" );
+            vlc_object_release( p_vout );
+        }
+        vlc_object_release( p_input );
+    }
+}
+
+- (IBAction)toggleFullscreenDevice:(id)sender
+{
+    config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
+    [self refreshVoutDeviceMenu: nil];
+}
+
+- (id)voutMenu
+{
+    return o_vout_menu;
+}
+
 #pragma mark -
 #pragma mark Panels
 
@@ -594,6 +792,17 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[[VLCMain sharedInstance] wizard] showWizard];
 }
 
+- (IBAction)showConvertAndSave:(id)sender
+{
+    if( o_convertandsave == nil )
+        o_convertandsave = [[VLCConvertAndSave alloc] init];
+
+    if( !b_nib_convertandsave_loaded )
+        b_nib_convertandsave_loaded = [NSBundle loadNibNamed:@"ConvertAndSave" owner: NSApp];
+
+    [o_convertandsave toggleWindow];
+}
+
 - (IBAction)showVideoEffects:(id)sender
 {
     if( o_videoeffects == nil )
@@ -634,7 +843,11 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (IBAction)viewPreferences:(id)sender
 {
-    [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
+    NSInteger i_level = NSNormalWindowLevel;
+    NSInteger i_video_window_level = [[[[VLCMainWindow sharedInstance] videoView] window] level];
+    if( i_video_window_level == NSStatusWindowLevel )
+        i_level = NSStatusWindowLevel;
+    [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level];
 }
 
 #pragma mark -
@@ -754,7 +967,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     bool b_value;
     playlist_t *p_playlist = pl_Get( VLCIntf );
     b_value = var_GetBool( p_playlist, "random" );
-       [o_mi_random setState: b_value];
+
+    [o_mi_random setState: b_value];
 }
 
 #pragma mark -
@@ -781,30 +995,21 @@ static VLCMainMenu *_o_sharedInstance = nil;
             return;
     }
 
-    /* Make sure we want to display the variable */
-    if( i_type & VLC_VAR_HASCHOICE )
-    {
-        var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
-        if( val.i_int == 0 ) return;
-        if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
-            return;
-    }
-
     /* Get the descriptive name of the variable */
     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
-    [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
-                     text.psz_string : psz_variable ]];
+    [o_mi setTitle: _NS( text.psz_string ? text.psz_string : psz_variable )];
 
     if( i_type & VLC_VAR_HASCHOICE )
     {
         NSMenu *o_menu = [o_mi submenu];
-        
+
         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
                        var:psz_variable selector:pf_callback];
-        
+
         free( text.psz_string );
         return;
     }
+
     if( var_Get( p_object, psz_variable, &val ) < 0 )
     {
         return;
@@ -843,12 +1048,35 @@ static VLCMainMenu *_o_sharedInstance = nil;
             selector:(SEL)pf_callback
 {
     vlc_value_t val, val_list, text_list;
-    int i_type, i, i_nb_items;
+    int i_type, i;
 
     /* remove previous items */
-    i_nb_items = [o_menu numberOfItems];
-    for( i = 0; i < i_nb_items; i++ )
-        [o_menu removeItemAtIndex: 0];
+    [o_menu removeAllItems];
+
+    /* we disable everything here, and enable it again when needed, below */
+    [o_parent setEnabled:NO];
+
+    /* Aspect Ratio */
+    if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
+    {
+        NSMenuItem *o_lmi_tmp2;
+        o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
+        [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
+        [o_lmi_tmp2 setEnabled: YES];
+        [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
+        [o_parent setEnabled: YES];
+        [o_menu addItem: [NSMenuItem separatorItem]];
+    }
+
+    /* special case for the subtitles item */
+    if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
+    {
+        NSMenuItem * o_lmi_tmp;
+        o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
+        [o_lmi_tmp setTarget: [[VLCMain sharedInstance] controls]];
+        [o_lmi_tmp setEnabled: YES];
+        [o_parent setEnabled: YES];
+    }
 
     /* Check the type of the object variable */
     i_type = var_Type( p_object, psz_variable );
@@ -857,7 +1085,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     if( i_type & VLC_VAR_HASCHOICE )
     {
         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
-        if( val.i_int == 0 ) return;
+        if( val.i_int == 0 )
+            return;
         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
             return;
     }
@@ -892,28 +1121,9 @@ static VLCMainMenu *_o_sharedInstance = nil;
     /* make (un)sensitive */
     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
 
-    /* Aspect Ratio */
-    if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
-    {
-        NSMenuItem *o_lmi_tmp2;
-        o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
-        [o_lmi_tmp2 setTarget: self];
-        [o_lmi_tmp2 setEnabled: YES];
-        [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
-        [o_parent setEnabled: YES];
-        [o_menu addItem: [NSMenuItem separatorItem]];
-    }
-
-    /* special case for the subtitles items */
+    /* another special case for the subtitles item */
     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
-    {
-        NSMenuItem * o_lmi_tmp;
-        o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
-        [o_lmi_tmp setTarget: self];
-        [o_lmi_tmp setEnabled: YES];
-        [o_parent setEnabled: YES];
         [o_menu addItem: [NSMenuItem separatorItem]];
-    }
 
     for( i = 0; i < val_list.p_list->i_count; i++ )
     {
@@ -925,8 +1135,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
         {
             case VLC_VAR_STRING:
 
-                o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
-                           text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
+                o_title = _NS( text_list.p_list->p_values[i].psz_string ? text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string );
 
                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
@@ -942,9 +1151,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
             case VLC_VAR_INTEGER:
 
                 o_title = text_list.p_list->p_values[i].psz_string ?
-                [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
-                [NSString stringWithFormat: @"%"PRId64,
-                 val_list.p_list->p_values[i].i_int];
+                _NS( text_list.p_list->p_values[i].psz_string ) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
 
                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
@@ -992,6 +1199,14 @@ static VLCMainMenu *_o_sharedInstance = nil;
     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
 
+    /* Preserve settings across vouts via the playlist object: */
+    if( !strcmp( [menuContent name], "fullscreen" ) || !strcmp( [menuContent name], "video-on-top" ) )
+        var_Set( pl_Get( VLCIntf ), [menuContent name] , [menuContent value] );
+
+    /* save our audio device across multiple sessions */
+    if( !strcmp( [menuContent name], "audio-device" ) )
+        config_PutInt( VLCIntf, "macosx-audio-device", [menuContent value].i_int );
+
     p_object = [menuContent vlcObject];
 
     if( p_object != NULL )
@@ -1017,55 +1232,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     playlist_t * p_playlist = pl_Get( p_intf );
     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
 
-    /* Recent Items Menu */
-    if( [o_title isEqualToString: _NS("Clear Menu")] )
-    {
-        NSMenu * o_menu = [o_mi_open_recent submenu];
-        int i_nb_items = [o_menu numberOfItems];
-        NSArray * o_docs = [[NSDocumentController sharedDocumentController]
-                            recentDocumentURLs];
-        UInt32 i_nb_docs = [o_docs count];
-
-        if( i_nb_items > 1 )
-        {
-            while( --i_nb_items )
-            {
-                [o_menu removeItemAtIndex: 0];
-            }
-        }
-
-        if( i_nb_docs > 0 )
-        {
-            NSURL * o_url;
-            NSString * o_doc;
-
-            [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
-
-            while( TRUE )
-            {
-                i_nb_docs--;
-
-                o_url = [o_docs objectAtIndex: i_nb_docs];
-
-                if( [o_url isFileURL] )
-                    o_doc = [o_url path];
-                else
-                    o_doc = [o_url absoluteString];
-
-                [o_menu insertItemWithTitle: o_doc
-                                     action: @selector(openRecentItem:)
-                              keyEquivalent: @"" atIndex: 0];
-
-                if( i_nb_docs == 0 )
-                    break;
-            }
-        }
-        else
-        {
-            bEnabled = FALSE;
-        }
-    }
-    else if( [o_title isEqualToString: _NS("Stop")] )
+    if( [o_title isEqualToString: _NS("Stop")] )
     {
         if( p_input == NULL )
         {
@@ -1121,7 +1288,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     }
     else if( [o_title isEqualToString: _NS("Mute")] )
     {
-        //FIXME [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
+        [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
         [self setupMenus]; /* Make sure audio menu is up to date */
     }
     else if( [o_title isEqualToString: _NS("Half Size")] ||
@@ -1132,9 +1299,6 @@ static VLCMainMenu *_o_sharedInstance = nil;
             [o_title isEqualToString: _NS("Fullscreen")] ||
             [o_title isEqualToString: _NS("Float on Top")] )
     {
-        id o_window;
-        NSArray *o_windows = [NSApp orderedWindows];
-        NSEnumerator *o_enumerator = [o_windows objectEnumerator];
         bEnabled = FALSE;
 
         if( p_input != NULL )
@@ -1143,29 +1307,16 @@ static VLCMainMenu *_o_sharedInstance = nil;
             if( p_vout != NULL )
             {
                 if( [o_title isEqualToString: _NS("Float on Top")] )
-                {
-                    var_Get( p_vout, "video-on-top", &val );
-                    [o_mi setState: val.b_bool ?  NSOnState : NSOffState];
-                }
-
-                while( (o_window = [o_enumerator nextObject]))
-                {
-                    if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
-                       [[[VLCMain sharedInstance] embeddedList]
-                        windowContainsEmbedded: o_window])
-                    {
-                        bEnabled = TRUE;
-                        break;
-                    }
-                }
-
-                vlc_object_release( (vlc_object_t *)p_vout );
+                    [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
+
+                bEnabled = TRUE;
+
+                vlc_object_release( p_vout );
             }
         }
         if( [o_title isEqualToString: _NS("Fullscreen")] )
         {
-            var_Get( p_playlist, "fullscreen", &val );
-            [o_mi setState: val.b_bool];
+        [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
             bEnabled = TRUE;
         }
         [self setupMenus]; /* Make sure video menu is up to date */
@@ -1175,7 +1326,9 @@ static VLCMainMenu *_o_sharedInstance = nil;
     if( [o_title isEqualToString: _NS("Normal Size")] )
     {
         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
-               bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
+
+
+bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
 
         [[item submenu] setAutoenablesItems:NO];
         for( int k=0; k < [[item submenu] numberOfItems]; k++ )
@@ -1220,7 +1373,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (void)dealloc
 {
-    vlc_object_release( _vlc_object );
+    if( _vlc_object )
+        vlc_object_release( _vlc_object );
     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
         free( value.psz_string );
     free( psz_name );