[vlc-commits] [Git][videolan/vlc][master] 5 commits: macosx: Fix path control items by creating independent copies of folder image

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon May 27 12:30:38 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
a739e705 by Claudio Cambra at 2024-05-27T09:50:50+00:00
macosx: Fix path control items by creating independent copies of folder image

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
b6d41084 by Claudio Cambra at 2024-05-27T09:50:50+00:00
macosx: Add convenience property to input node path control item for prefix sentence of accessibility description of image

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
4577ba3e by Claudio Cambra at 2024-05-27T09:50:50+00:00
macosx: Provide debug output when no matching input item found for clicked path item

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
cd699323 by Claudio Cambra at 2024-05-27T09:50:50+00:00
macosx: Set accessibility description for input node path control items

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
b02cb3c3 by Claudio Cambra at 2024-05-27T09:50:50+00:00
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 at claudiocambra.com>

- - - - -


4 changed files:

- modules/gui/macosx/library/VLCInputNodePathControl.m
- modules/gui/macosx/library/VLCInputNodePathControlItem.h
- modules/gui/macosx/library/VLCInputNodePathControlItem.m
- modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m


Changes:

=====================================
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


=====================================
modules/gui/macosx/library/VLCInputNodePathControlItem.h
=====================================
@@ -28,6 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCInputNodePathControlItem : NSPathControlItem
 
+ at property (class, readonly) NSString *accessibilityDescriptionPrefix;
+
 @property (readonly) VLCInputNode *inputNode;
 
 - (instancetype)initWithInputNode:(VLCInputNode *)inputNode;


=====================================
modules/gui/macosx/library/VLCInputNodePathControlItem.m
=====================================
@@ -25,8 +25,15 @@
 #import "VLCInputItem.h"
 #import "VLCLibraryImageCache.h"
 
+#import "extensions/NSString+Helpers.h"
+
 @implementation VLCInputNodePathControlItem
 
++ (NSString *)accessibilityDescriptionPrefix
+{
+    return _NS("Thumbnail for media location");
+}
+
 - (instancetype)initWithInputNode:(VLCInputNode *)inputNode
 {
     self = [super init];
@@ -36,14 +43,16 @@
         VLCInputItem * const inputItem = inputNode.inputItem;
         self.title = inputItem.name;
 
-        self.image = [NSImage imageNamed:NSImageNameFolder];
+        NSImage * const folderImage = [NSImage imageNamed:NSImageNameFolder];
+        self.image = folderImage.copy;
         // 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;
-
+        // this class. As a very awkward workaround, lets set the accessibility
+        // description of the image and we will use this as an identifier.
+        self.image.accessibilityDescription = [NSString stringWithFormat:@"%@: %@", 
+                                               VLCInputNodePathControlItem.accessibilityDescriptionPrefix, 
+                                               inputItem.path];
     } else if (inputNode == nil) {
         NSLog(@"WARNING: Received nil input node, cannot create VLCInputNodePathControlItem");
     } else if (inputNode.inputItem == nil) {


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
=====================================
@@ -503,17 +503,19 @@ referenceSizeForHeaderInSection:(NSInteger)section
 
 - (void)pathControlAction:(id)sender
 {
-    if (_pathControl.clickedPathItem == nil || _childDataSource == nil) {
+    if (self.pathControl.clickedPathItem == nil || self.childDataSource == nil) {
         return;
     }
 
-    NSPathControlItem * const selectedItem = _pathControl.clickedPathItem;
-    NSString * const itemNodeMrl = selectedItem.image.name;
+    NSPathControlItem * const selectedItem = self.pathControl.clickedPathItem;
+    NSString * const itemNodeMrl = selectedItem.image.accessibilityDescription;
 
-    VLCInputNodePathControlItem * const matchingItem = [_pathControl.inputNodePathControlItems objectForKey:itemNodeMrl];
+    VLCInputNodePathControlItem * const matchingItem = [self.pathControl.inputNodePathControlItems objectForKey:itemNodeMrl];
     if (matchingItem != nil) {
-        _childDataSource.nodeToDisplay = matchingItem.inputNode;
-        [_pathControl clearPathControlItemsAheadOf:selectedItem];
+        self.childDataSource.nodeToDisplay = matchingItem.inputNode;
+        [self.pathControl clearPathControlItemsAheadOf:selectedItem];
+    } else {
+        NSLog(@"Could not find matching item for clicked path item: %@", selectedItem);
     }
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/71d385aba8336aac24576e407869697c6297612e...b02cb3c302529974bae67b90a0867f74a276b331

-- 
This project does not include diff previews in email notifications.
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/71d385aba8336aac24576e407869697c6297612e...b02cb3c302529974bae67b90a0867f74a276b331
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