From a3ae8cd47652dd08e9391b46065569b849c8d154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <felix@feepk.net> Date: Tue, 16 Apr 2019 22:39:31 +0200 Subject: [PATCH] macosx/main menu: cosmetics --- modules/gui/macosx/menus/VLCMainMenu.h | 18 ---- modules/gui/macosx/menus/VLCMainMenu.m | 110 +++++++++++++++---------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/modules/gui/macosx/menus/VLCMainMenu.h b/modules/gui/macosx/menus/VLCMainMenu.h index cf9fb9b73e86..57050e67aa82 100644 --- a/modules/gui/macosx/menus/VLCMainMenu.h +++ b/modules/gui/macosx/menus/VLCMainMenu.h @@ -283,21 +283,3 @@ - (IBAction)showPlaylist:(id)sender; @end - -/***************************************************************************** - *VLCAutoGeneratedMenuContent interface - ***************************************************************************** - *This holds our data for autogenerated menus - *****************************************************************************/ -@interface VLCAutoGeneratedMenuContent : NSObject - -- (id)initWithVariableName: (const char *)name - ofObject: (vlc_object_t *)object - andValue: (vlc_value_t)value - ofType: (int)type; -- (const char *)name; -- (vlc_value_t)value; -- (vlc_object_t *)vlcObject; -- (int)type; - -@end diff --git a/modules/gui/macosx/menus/VLCMainMenu.m b/modules/gui/macosx/menus/VLCMainMenu.m index fd60e48dfd35..e5be19c72644 100644 --- a/modules/gui/macosx/menus/VLCMainMenu.m +++ b/modules/gui/macosx/menus/VLCMainMenu.m @@ -57,6 +57,24 @@ #import <Sparkle/Sparkle.h> #endif +@interface VLCAutoGeneratedMenuContent : NSObject +{ + char *psz_name; + vlc_object_t *vlc_object; + vlc_value_t value; + int i_type; +} +- (id)initWithVariableName:(const char *)name + ofObject:(vlc_object_t *)object + andValue:(vlc_value_t)value + ofType:(int)type; +- (const char *)name; +- (vlc_value_t)value; +- (vlc_object_t *)vlcObject; +- (int)type; + +@end + @interface VLCMainMenu() <NSMenuDelegate> { VLCAboutWindowController *_aboutWindowController; @@ -186,7 +204,7 @@ /* Let the ExtensionsManager itself build the menu */ VLCExtensionsManager *extMgr = [[VLCMain sharedInstance] extensionsManager]; [extMgr buildMenu:_extensionsMenu]; - [_extensions setEnabled: ([_extensionsMenu numberOfItems] > 0)]; + [_extensions setEnabled:([_extensionsMenu numberOfItems] > 0)]; // FIXME: Implement preference for autoloading extensions on mac // FIXME: this is definitely the wrong place to do this. @@ -637,7 +655,7 @@ action:@selector(toggleFullscreenDevice:) keyEquivalent:@""]; menuItem = [submenu itemAtIndex:i+1]; - [menuItem setTag: (int)[[screens objectAtIndex:i] displayID]]; + [menuItem setTag:(int)[[screens objectAtIndex:i] displayID]]; [menuItem setEnabled: YES]; [menuItem setTarget: self]; } @@ -857,7 +875,7 @@ vlc_tick_t length = _playerController.length; [_timeSelectionPanel setMaxTime:(int)SEC_FROM_VLC_TICK(length)]; vlc_tick_t time = _playerController.time; - [_timeSelectionPanel setPosition: (int)SEC_FROM_VLC_TICK(time)]; + [_timeSelectionPanel setPosition:(int)SEC_FROM_VLC_TICK(time)]; [_timeSelectionPanel runModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger returnCode, int64_t returnTime) { if (returnCode != NSModalResponseOK) @@ -890,7 +908,10 @@ _subtitle_track.enabled = numberOfTracks > 0 ? YES : NO; } -- (void)rebuildTracksMenu:(NSMenu *)menu withMetadata:(NSArray *)metadataArray count:(size_t)count category:(enum es_format_category_e)category +- (void)rebuildTracksMenu:(NSMenu *)menu + withMetadata:(NSArray *)metadataArray + count:(size_t)count + category:(enum es_format_category_e)category { [menu removeAllItems]; @@ -1320,8 +1341,9 @@ - (IBAction)showPreferences:(id)sender { - NSInteger i_level = [[[VLCMain sharedInstance] voutProvider] currentStatusWindowLevel]; - [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level]; + VLCMain *mainInstance = [VLCMain sharedInstance]; + NSInteger i_level = [[mainInstance voutProvider] currentStatusWindowLevel]; + [[mainInstance simplePreferences] showSimplePrefsWithLevel:i_level]; } - (IBAction)openAddonManager:(id)sender @@ -1508,8 +1530,11 @@ if (i_type & VLC_VAR_HASCHOICE) { NSMenu *menu = [menuItem submenu]; - [self setupVarMenu:menu forMenuItem:menuItem target:p_object - var:psz_variable selector:pf_callback]; + [self setupVarMenu:menu + forMenuItem:menuItem + target:p_object + var:psz_variable + selector:pf_callback]; free(text); return; @@ -1521,30 +1546,35 @@ VLCAutoGeneratedMenuContent *data; switch(i_type & VLC_VAR_TYPE) { case VLC_VAR_VOID: - data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object - andValue: val ofType: i_type]; + data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName:psz_variable + ofObject:p_object + andValue:val + ofType:i_type]; [menuItem setRepresentedObject:data]; break; case VLC_VAR_BOOL: - data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object - andValue: val ofType: i_type]; + data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName:psz_variable + ofObject:p_object + andValue:val + ofType:i_type]; [menuItem setRepresentedObject:data]; if (!(i_type & VLC_VAR_ISCOMMAND)) - [menuItem setState: val.b_bool ? TRUE : FALSE ]; + [menuItem setState:val.b_bool ? NSOnState : NSOffState]; break; default: break; } - if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string); + if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) + free(val.psz_string); free(text); } - (void)setupVarMenu:(NSMenu *)menu - forMenuItem: (NSMenuItem *)parent + forMenuItem:(NSMenuItem *)parent target:(vlc_object_t *)p_object var:(const char *)psz_variable selector:(SEL)pf_callback @@ -1608,7 +1638,7 @@ } /* make (un)sensitive */ - [parent setEnabled: (count > 1)]; + [parent setEnabled:(count > 1)]; for (i = 0; i < count; i++) { NSMenuItem *lmi; @@ -1620,14 +1650,16 @@ title = _NS(text_list[i] ? text_list[i] : val_list[i].psz_string); - lmi = [menu addItemWithTitle: title action: pf_callback keyEquivalent: @""]; - data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object - andValue: val_list[i] ofType: i_type]; + lmi = [menu addItemWithTitle:title action:pf_callback keyEquivalent:@""]; + data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName:psz_variable + ofObject:p_object + andValue:val_list[i] + ofType:i_type]; [lmi setRepresentedObject:data]; - [lmi setTarget: self]; + [lmi setTarget:self]; if (!strcmp(val.psz_string, val_list[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND)) - [lmi setState: TRUE ]; + [lmi setState:NSOnState]; free(text_list[i]); free(val_list[i].psz_string); @@ -1636,16 +1668,18 @@ case VLC_VAR_INTEGER: title = text_list[i] ? - _NS(text_list[i]) : [NSString stringWithFormat: @"%"PRId64, val_list[i].i_int]; + _NS(text_list[i]) : [NSString stringWithFormat:@"%"PRId64, val_list[i].i_int]; lmi = [menu addItemWithTitle: title action: pf_callback keyEquivalent: @""]; - data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object - andValue: val_list[i] ofType: i_type]; + data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName:psz_variable + ofObject:p_object + andValue:val_list[i] + ofType:i_type]; [lmi setRepresentedObject:data]; - [lmi setTarget: self]; + [lmi setTarget:self]; if (val_list[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND)) - [lmi setState: TRUE ]; + [lmi setState:NSOnState]; free(text_list[i]); break; @@ -1665,13 +1699,14 @@ { NSMenuItem *mi = (NSMenuItem *)sender; VLCAutoGeneratedMenuContent *data = [mi representedObject]; - [NSThread detachNewThreadSelector: @selector(toggleVarThread:) - toTarget: self withObject: data]; + [NSThread detachNewThreadSelector:@selector(toggleVarThread:) + toTarget:self + withObject:data]; return; } -- (int)toggleVarThread: (id)data +- (void)toggleVarThread:(id)data { @autoreleasepool { vlc_object_t *p_object; @@ -1681,7 +1716,6 @@ p_object = [menuContent vlcObject]; var_Set(p_object, [menuContent name], [menuContent value]); - return true; } } @@ -1760,7 +1794,6 @@ vout_thread_t *p_vout = [_playerController videoOutputThreadForKeyWindow]; if (p_vout != NULL) { - // FIXME: re-write using VLCPlayerController if (mi == _floatontop) [mi setState: var_GetBool(p_vout, "video-on-top")]; @@ -1796,7 +1829,6 @@ @end - /***************************************************************************** *VLCAutoGeneratedMenuContent implementation ***************************************************************************** @@ -1804,18 +1836,12 @@ *the variable of the autogenerated menu *****************************************************************************/ -@interface VLCAutoGeneratedMenuContent () -{ - char *psz_name; - vlc_object_t *vlc_object; - vlc_value_t value; - int i_type; -} -@end @implementation VLCAutoGeneratedMenuContent --(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object - andValue:(vlc_value_t)val ofType:(int)type +-(id)initWithVariableName:(const char *)name + ofObject:(vlc_object_t *)object + andValue:(vlc_value_t)val + ofType:(int)type { self = [super init]; -- GitLab