From b02cb3c302529974bae67b90a0867f74a276b331 Mon Sep 17 00:00:00 2001
From: Claudio Cambra <developer@claudiocambra.com>
Date: Sun, 26 May 2024 00:01:59 +0800
Subject: [PATCH] macosx: Use accessibility description for input node path
 control items as path control item identifiers

The input node path control items are readable strings but can be used
as identifiers thanks to the fact the contain the path for the given
input node. This is a big ugly hack but we have no other option to make
input node path control items identifiable, as we receive different
instances from the nspathcontrol that are not our subclass

Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
---
 .../macosx/library/VLCInputNodePathControl.m  | 40 +++++++++----------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/modules/gui/macosx/library/VLCInputNodePathControl.m b/modules/gui/macosx/library/VLCInputNodePathControl.m
index 3a8a4bd5d668..cf5c51372bea 100644
--- a/modules/gui/macosx/library/VLCInputNodePathControl.m
+++ b/modules/gui/macosx/library/VLCInputNodePathControl.m
@@ -30,16 +30,16 @@
 {
     NSParameterAssert(inputNodePathControlItem != nil);
     NSParameterAssert(inputNodePathControlItem.image != nil);
-    NSParameterAssert(inputNodePathControlItem.image.name != nil);
-    NSParameterAssert(![inputNodePathControlItem.image.name isEqualToString:@""]);
+    NSParameterAssert(inputNodePathControlItem.image.accessibilityDescription != nil);
+    NSParameterAssert(![inputNodePathControlItem.image.accessibilityDescription isEqualToString:@""]);
 
-    if (_inputNodePathControlItems == nil) {
+    if (self.inputNodePathControlItems == nil) {
         _inputNodePathControlItems = [NSMutableDictionary dictionary];
     }
 
-    [_inputNodePathControlItems setObject:inputNodePathControlItem forKey:inputNodePathControlItem.image.name];
+    [self.inputNodePathControlItems setObject:inputNodePathControlItem forKey:inputNodePathControlItem.image.accessibilityDescription];
 
-    NSMutableArray *pathItems = [NSMutableArray arrayWithArray:self.pathItems];
+    NSMutableArray * const pathItems = [NSMutableArray arrayWithArray:self.pathItems];
     [pathItems addObject:inputNodePathControlItem];
     self.pathItems = pathItems;
 }
@@ -47,49 +47,49 @@
 - (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 = [NSMutableArray arrayWithArray:self.pathItems];
+    NSPathControlItem * const lastItem = pathItems.lastObject;
 
     [pathItems removeLastObject];
     self.pathItems = pathItems;
-    [_inputNodePathControlItems removeObjectForKey:lastItem.image.name];
+    [self.inputNodePathControlItems removeObjectForKey:lastItem.image.accessibilityDescription];
 }
 
 - (void)clearInputNodePathControlItems
 {
-    _inputNodePathControlItems = [NSMutableDictionary dictionary];
+    _inputNodePathControlItems = NSMutableDictionary.dictionary;
     self.pathItems = @[];
 }
 
 - (void)clearPathControlItemsAheadOf:(NSPathControlItem *)item
 {
-    if ([item.image.name isEqualToString:@""]) {
+    if ([item.image.accessibilityDescription isEqualToString:@""]) {
         return;
     }
 
-    NSUInteger indexOfItem = [self.pathItems indexOfObjectPassingTest:^BOOL(NSPathControlItem *searchItem, NSUInteger idx, BOOL *stop) {
-        return [searchItem.image.name isEqualToString:item.image.name];
+    const NSUInteger indexOfItem = [self.pathItems indexOfObjectPassingTest:^BOOL(NSPathControlItem * const searchItem, const NSUInteger idx, BOOL * const stop) {
+        return [searchItem.image.accessibilityDescription isEqualToString:item.image.accessibilityDescription];
     }];
 
     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 = [NSMutableArray arrayWithArray:self.pathItems];
+    NSArray<NSPathControlItem *> * const itemsToRemove = [pathItems subarrayWithRange:NSMakeRange(indexOfItem + 1, pathItems.count - indexOfItem - 1)];
+    NSMutableArray<NSString *> * const itemIdsToRemove = [NSMutableArray arrayWithCapacity:itemsToRemove.count];
 
-    for (NSPathControlItem *searchItem in itemsToRemove) {
-        NSString *searchItemMrl = searchItem.image.name;
-        [itemMrlsToRemove addObject:searchItemMrl];
+    for (NSPathControlItem * const searchItem in itemsToRemove) {
+        NSString * const searchItemId = searchItem.image.accessibilityDescription;
+        [itemIdsToRemove addObject:searchItemId];
     };
 
     self.pathItems = [pathItems subarrayWithRange:NSMakeRange(0, indexOfItem + 1)];
-    [_inputNodePathControlItems removeObjectsForKeys:itemMrlsToRemove];
+    [self.inputNodePathControlItems removeObjectsForKeys:itemIdsToRemove];
 }
 
 @end
-- 
GitLab