[vlc-commits] [Git][videolan/vlc][master] 3 commits: macosx: Separate menu creation into separate methods
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed Dec 21 12:39:12 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
821bbe33 by Claudio Cambra at 2022-12-21T12:06:02+00:00
macosx: Separate menu creation into separate methods
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
b032d3cd by Claudio Cambra at 2022-12-21T12:06:02+00:00
macosx: Streamline VLCLibraryMenuController, use one NSMenu with hideable menuitems rather than two separate menus
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
667690ef by Claudio Cambra at 2022-12-21T12:06:02+00:00
macosx: Use weakObjectsHashTable for VLCLibraryMenuController menuitems
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
2 changed files:
- modules/gui/macosx/library/VLCLibraryMenuController.h
- modules/gui/macosx/library/VLCLibraryMenuController.m
Changes:
=====================================
modules/gui/macosx/library/VLCLibraryMenuController.h
=====================================
@@ -29,8 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface VLCLibraryMenuController : NSObject
@property (readonly) NSMenu *libraryMenu;
- at property (readonly) NSMenu *minimalMenu;
- at property (readonly) NSMenu *menuToPresent;
- (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView;
- (void)setRepresentedItem:(id<VLCMediaLibraryItemProtocol>)item;
=====================================
modules/gui/macosx/library/VLCLibraryMenuController.m
=====================================
@@ -34,6 +34,8 @@
{
VLCLibraryInformationPanel *_informationPanel;
id<VLCMediaLibraryItemProtocol> _representedItem;
+
+ NSHashTable<NSMenuItem*> *_mediaItemRequiringMenuItems;
}
@end
@@ -43,42 +45,61 @@
{
self = [super init];
if (self) {
- [self createMenu];
+ [self createLibraryMenu];
}
return self;
}
-- (void)createMenu
+- (void)createLibraryMenu
{
NSMenuItem *playItem = [[NSMenuItem alloc] initWithTitle:_NS("Play") action:@selector(play:) keyEquivalent:@""];
playItem.target = self;
+
NSMenuItem *appendItem = [[NSMenuItem alloc] initWithTitle:_NS("Append to Playlist") action:@selector(appendToPlaylist:) keyEquivalent:@""];
appendItem.target = self;
+
NSMenuItem *addItem = [[NSMenuItem alloc] initWithTitle:_NS("Add Media Folder...") action:@selector(addMedia:) keyEquivalent:@""];
addItem.target = self;
+
NSMenuItem *revealItem = [[NSMenuItem alloc] initWithTitle:_NS("Reveal in Finder") action:@selector(revealInFinder:) keyEquivalent:@""];
revealItem.target = self;
+
NSMenuItem *deleteItem = [[NSMenuItem alloc] initWithTitle:_NS("Delete from Library") action:@selector(moveToTrash:) keyEquivalent:@""];
deleteItem.target = self;
+
NSMenuItem *informationItem = [[NSMenuItem alloc] initWithTitle:_NS("Information...") action:@selector(showInformation:) keyEquivalent:@""];
informationItem.target = self;
_libraryMenu = [[NSMenu alloc] initWithTitle:@""];
[_libraryMenu addMenuItemsFromArray:@[playItem, appendItem, revealItem, deleteItem, informationItem, [NSMenuItem separatorItem], addItem]];
+
+ _mediaItemRequiringMenuItems = [NSHashTable weakObjectsHashTable];
+ [_mediaItemRequiringMenuItems addObject:playItem];
+ [_mediaItemRequiringMenuItems addObject:appendItem];
+ [_mediaItemRequiringMenuItems addObject:revealItem];
+ [_mediaItemRequiringMenuItems addObject:deleteItem];
+ [_mediaItemRequiringMenuItems addObject:informationItem];
+}
- _minimalMenu = [[NSMenu alloc] initWithTitle:@""];
- NSMenuItem *addItem2 = [[NSMenuItem alloc] initWithTitle:_NS("Add Media Folder...") action:@selector(addMedia:) keyEquivalent:@""];
- [_minimalMenu addItem:addItem2];
+- (void)setMediaItemRequiringMenuItemsHidden:(BOOL)hidden
+{
+ for (NSMenuItem *menuItem in _mediaItemRequiringMenuItems) {
+ menuItem.hidden = hidden;
+ }
}
-- (NSMenu *)menuToPresent
+- (void)updateLibraryMenuItems
{
- return _representedItem == nil ? _minimalMenu : _libraryMenu;
+ if (_representedItem) {
+ [self setMediaItemRequiringMenuItemsHidden:NO];
+ } else {
+ [self setMediaItemRequiringMenuItemsHidden:YES];
+ }
}
- (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView
{
- [NSMenu popUpContextMenu:[self menuToPresent] withEvent:theEvent forView:theView];
+ [NSMenu popUpContextMenu:_libraryMenu withEvent:theEvent forView:theView];
}
#pragma mark - actions
@@ -169,6 +190,7 @@
- (void)setRepresentedItem:(id<VLCMediaLibraryItemProtocol>)item
{
_representedItem = item;
+ [self updateLibraryMenuItems];
}
@end
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/09f99896cd1eef0b93123e5d8249dc044fbec233...667690efb2280e31d5abcb15f752e9b382a531f0
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/09f99896cd1eef0b93123e5d8249dc044fbec233...667690efb2280e31d5abcb15f752e9b382a531f0
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list