[vlc-commits] macosx: simple prefs: Replace huge define by block / inline function

David Fuhrmann git at videolan.org
Sun Jun 10 14:06:23 CEST 2018


vlc/vlc-3.0 | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Jun  9 20:08:46 2018 +0200| [8a4609f3b09d0c3f63b38ad831ad56f66502d7a5] | committer: Felix Paul Kühne

macosx: simple prefs: Replace huge define by block / inline function

One should not have such huge defines.

(cherry picked from commit ea8ed957e480c46436a4e8b4edc9ad2945b2345a)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=8a4609f3b09d0c3f63b38ad831ad56f66502d7a5
---

 modules/gui/macosx/VLCSimplePrefsController.m | 60 +++++++++++++--------------
 1 file changed, 28 insertions(+), 32 deletions(-)

diff --git a/modules/gui/macosx/VLCSimplePrefsController.m b/modules/gui/macosx/VLCSimplePrefsController.m
index a5f50b1b8f..9a7a348426 100644
--- a/modules/gui/macosx/VLCSimplePrefsController.m
+++ b/modules/gui/macosx/VLCSimplePrefsController.m
@@ -1311,38 +1311,34 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
     NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
 
     if (sender == _input_urlhandlerButton) {
-        NSArray *handlers;
-        NSString *handler;
-        NSString *rawhandler;
-        NSMutableArray *rawHandlers;
-        NSUInteger count;
-
-#define fillUrlHandlerPopup( protocol, object ) \
-        handlers = (__bridge_transfer NSArray *)LSCopyAllHandlersForURLScheme(CFSTR( protocol )); \
-        rawHandlers = [[NSMutableArray alloc] init]; \
-        [object removeAllItems]; \
-        count = [handlers count]; \
-        for (NSUInteger x = 0; x < count; x++) { \
-            rawhandler = [handlers objectAtIndex:x]; \
-            handler = [self applicationNameForBundleIdentifier:rawhandler]; \
-            if (handler && ![handler isEqualToString:@""]) { \
-                [object addItemWithTitle:handler]; \
-                [[object lastItem] setImage: [self iconForBundleIdentifier:[handlers objectAtIndex:x]]]; \
-                [rawHandlers addObject: rawhandler]; \
-            } \
-        } \
-        [object selectItemAtIndex: [rawHandlers indexOfObject:(__bridge_transfer id)LSCopyDefaultHandlerForURLScheme(CFSTR( protocol ))]];
-
-        fillUrlHandlerPopup( "ftp", _urlhandler_ftpPopup);
-        fillUrlHandlerPopup( "mms", _urlhandler_mmsPopup);
-        fillUrlHandlerPopup( "rtmp", _urlhandler_rtmpPopup);
-        fillUrlHandlerPopup( "rtp", _urlhandler_rtpPopup);
-        fillUrlHandlerPopup( "rtsp", _urlhandler_rtspPopup);
-        fillUrlHandlerPopup( "sftp", _urlhandler_sftpPopup);
-        fillUrlHandlerPopup( "smb", _urlhandler_smbPopup);
-        fillUrlHandlerPopup( "udp", _urlhandler_udpPopup);
-
-#undef fillUrlHandlerPopup
+
+        void (^fillUrlHandlerPopup)(NSString*, NSPopUpButton*) = ^void(NSString *protocol, NSPopUpButton *object) {
+
+            NSArray *handlers = (__bridge_transfer NSArray *)LSCopyAllHandlersForURLScheme((__bridge CFStringRef)protocol);
+            NSMutableArray *rawHandlers = [[NSMutableArray alloc] init];
+            [object removeAllItems];
+            NSUInteger count = [handlers count];
+            for (NSUInteger x = 0; x < count; x++) {
+                NSString *rawhandler = [handlers objectAtIndex:x];
+                NSString *handler = [self applicationNameForBundleIdentifier:rawhandler];
+                if (handler && ![handler isEqualToString:@""]) {
+                    [object addItemWithTitle:handler];
+                    [[object lastItem] setImage: [self iconForBundleIdentifier:[handlers objectAtIndex:x]]];
+                    [rawHandlers addObject: rawhandler];
+                }
+            }
+            [object selectItemAtIndex: [rawHandlers indexOfObject:(__bridge_transfer id)LSCopyDefaultHandlerForURLScheme((__bridge CFStringRef)protocol)]];
+        };
+
+        fillUrlHandlerPopup(@"ftp", _urlhandler_ftpPopup);
+        fillUrlHandlerPopup(@"mms", _urlhandler_mmsPopup);
+        fillUrlHandlerPopup(@"rtmp", _urlhandler_rtmpPopup);
+        fillUrlHandlerPopup(@"rtp", _urlhandler_rtpPopup);
+        fillUrlHandlerPopup(@"rtsp", _urlhandler_rtspPopup);
+        fillUrlHandlerPopup(@"sftp", _urlhandler_sftpPopup);
+        fillUrlHandlerPopup(@"smb", _urlhandler_smbPopup);
+        fillUrlHandlerPopup(@"udp", _urlhandler_udpPopup);
+
 
         [NSApp beginSheet:_urlhandler_win modalForWindow:self.window modalDelegate:self didEndSelector:NULL contextInfo:nil];
     } else {



More information about the vlc-commits mailing list