Merge branch 'work/fix-unclickable-media-source-items-try-2' into 'master'

macosx: Fix media source items becoming unresponsive after switching away from media source views

See merge request videolan/vlc!3998
This commit is contained in:
Claudio Cambra 2024-04-28 07:10:48 +00:00
commit 825ff6dfc5
4 changed files with 40 additions and 28 deletions

View File

@ -28,18 +28,16 @@
- (void)appendInputNodePathControlItem:(VLCInputNodePathControlItem *)inputNodePathControlItem
{
NSParameterAssert(inputNodePathControlItem != nil);
NSParameterAssert(inputNodePathControlItem.image != nil);
NSParameterAssert(inputNodePathControlItem.image.name != nil);
NSParameterAssert(![inputNodePathControlItem.image.name isEqualToString:@""]);
NSString * const inputNodeMRL = [VLCInputNodePathControlItem MRLFromPathControlItem:inputNodePathControlItem];
NSParameterAssert(![inputNodeMRL isEqualToString:@""]);
if (_inputNodePathControlItems == nil) {
_inputNodePathControlItems = [NSMutableDictionary dictionary];
_inputNodePathControlItems = NSMutableDictionary.dictionary;
}
[_inputNodePathControlItems setObject:inputNodePathControlItem forKey:inputNodePathControlItem.image.name];
[_inputNodePathControlItems setObject:inputNodePathControlItem forKey:inputNodeMRL];
NSMutableArray *pathItems = [NSMutableArray arrayWithArray:self.pathItems];
NSMutableArray * const pathItems = self.pathItems.mutableCopy;
[pathItems addObject:inputNodePathControlItem];
self.pathItems = pathItems;
}
@ -47,44 +45,47 @@
- (void)removeLastInputNodePathControlItem
{
if (self.pathItems.count == 0) {
_inputNodePathControlItems = [NSMutableDictionary dictionary];
_inputNodePathControlItems = NSMutableDictionary.dictionary;
return;
}
NSMutableArray *pathItems = [NSMutableArray arrayWithArray:self.pathItems];
NSPathControlItem *lastItem = pathItems.lastObject;
NSMutableArray * const pathItems = self.pathItems.mutableCopy;
NSPathControlItem * const lastItem = pathItems.lastObject;
NSString * const lastItemMRL = [VLCInputNodePathControlItem MRLFromPathControlItem:lastItem];
[pathItems removeLastObject];
self.pathItems = pathItems;
[_inputNodePathControlItems removeObjectForKey:lastItem.image.name];
[_inputNodePathControlItems removeObjectForKey:lastItemMRL];
}
- (void)clearInputNodePathControlItems
{
_inputNodePathControlItems = [NSMutableDictionary dictionary];
_inputNodePathControlItems = NSMutableDictionary.dictionary;
self.pathItems = @[];
}
- (void)clearPathControlItemsAheadOf:(NSPathControlItem *)item
{
if ([item.image.name isEqualToString:@""]) {
NSString * const itemMRL = [VLCInputNodePathControlItem MRLFromPathControlItem:item];
if ([itemMRL isEqualToString:@""]) {
return;
}
NSUInteger indexOfItem = [self.pathItems indexOfObjectPassingTest:^BOOL(NSPathControlItem *searchItem, NSUInteger idx, BOOL *stop) {
return [searchItem.image.name isEqualToString:item.image.name];
NSUInteger indexOfItem = [self.pathItems indexOfObjectPassingTest:^BOOL(NSPathControlItem * const searchItem, const NSUInteger idx, BOOL * const stop) {
NSString * const searchItemMRL = [VLCInputNodePathControlItem MRLFromPathControlItem:searchItem];
return [searchItemMRL isEqualToString:itemMRL];
}];
if (indexOfItem == NSNotFound) {
return;
}
NSMutableArray<NSPathControlItem *> *pathItems = [NSMutableArray arrayWithArray:self.pathItems];
NSArray<NSPathControlItem *> *itemsToRemove = [pathItems subarrayWithRange:NSMakeRange(indexOfItem + 1, pathItems.count - indexOfItem - 1)];
NSMutableArray<NSString *> *itemMrlsToRemove = [NSMutableArray arrayWithCapacity:itemsToRemove.count];
NSMutableArray<NSPathControlItem *> * const pathItems = self.pathItems.mutableCopy;
NSArray<NSPathControlItem *> * const itemsToRemove = [pathItems subarrayWithRange:NSMakeRange(indexOfItem + 1, pathItems.count - indexOfItem - 1)];
NSMutableArray<NSString *> * const itemMrlsToRemove = [NSMutableArray arrayWithCapacity:itemsToRemove.count];
for (NSPathControlItem *searchItem in itemsToRemove) {
NSString *searchItemMrl = searchItem.image.name;
for (NSPathControlItem * const searchItem in itemsToRemove) {
NSString * const searchItemMrl = [VLCInputNodePathControlItem MRLFromPathControlItem:searchItem];
[itemMrlsToRemove addObject:searchItemMrl];
};

View File

@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (readonly) VLCInputNode *inputNode;
+ (NSString *)MRLFromPathControlItem:(NSPathControlItem *)pathControlItem;
- (instancetype)initWithInputNode:(VLCInputNode *)inputNode;
@end

View File

@ -27,6 +27,15 @@
@implementation VLCInputNodePathControlItem
+ (NSString *)MRLFromPathControlItem:(NSPathControlItem *)pathControlItem
{
if (pathControlItem == nil || pathControlItem.image == nil || pathControlItem.image.accessibilityDescription == nil) {
return @"";
}
return pathControlItem.image.accessibilityDescription;
}
- (instancetype)initWithInputNode:(VLCInputNode *)inputNode
{
self = [super init];
@ -36,14 +45,15 @@
VLCInputItem * const inputItem = inputNode.inputItem;
self.title = inputItem.name;
self.image = [VLCLibraryImageCache thumbnailForInputItem:inputItem];;
self.image = [VLCLibraryImageCache thumbnailForInputItem:inputItem];
// HACK: We have no way when we get the clicked item from the path control
// of knowing specifically which input node this path item corresponds to,
// as the path control returns a copy for clickedPathItem that is not of
// this class. As a very awkward workaround, lets set the name of the image
// used here as the MRL of the node's input item
self.image.name = inputItem.MRL;
// HACK: We have no way when we get the clicked item from the path
// control of knowing specifically which input node this path item
// corresponds to, as the path control returns a copy for
// clickedPathItem that is not of this class. As a very awkward
// workaround, lets set the desc of the image used here as the MRL of
// the node's input item
self.image.accessibilityDescription = inputItem.MRL;
} else if (inputNode == nil) {
NSLog(@"WARNING: Received nil input node, cannot create VLCInputNodePathControlItem");

View File

@ -508,7 +508,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
}
NSPathControlItem * const selectedItem = _pathControl.clickedPathItem;
NSString * const itemNodeMrl = selectedItem.image.name;
NSString * const itemNodeMrl = [VLCInputNodePathControlItem MRLFromPathControlItem:selectedItem];
VLCInputNodePathControlItem * const matchingItem = [_pathControl.inputNodePathControlItems objectForKey:itemNodeMrl];
if (matchingItem != nil) {