[vlc-commits] macosx: simplify revealInFinder action

David Fuhrmann git at videolan.org
Fri Jan 2 21:58:36 CET 2015


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Fri Jan  2 15:39:00 2015 +0100| [ef6c3bbb71211f480a56bf982b36f27724822a8b] | committer: David Fuhrmann

macosx: simplify revealInFinder action

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

 modules/gui/macosx/playlist.m |   34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index 66d72a1..212aa00 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -487,32 +487,24 @@
 
 - (IBAction)revealItemInFinder:(id)sender
 {
-    NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
-    NSUInteger count = [selectedRows count];
-    NSUInteger indexes[count];
-    [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
+    NSIndexSet *selectedRows = [o_outline_view selectedRowIndexes];
+    [selectedRows enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
 
-    NSMutableString * o_mrl;
-    for (NSUInteger i = 0; i < count; i++) {
-        PLItem *o_item = [o_outline_view itemAtRow:indexes[i]];
-
-        char * psz_url = decode_URI(input_item_GetURI([o_item input]));
-        o_mrl = [[NSMutableString alloc] initWithString: [NSString stringWithUTF8String:psz_url ? psz_url : ""]];
-        if (psz_url != NULL)
-            free( psz_url );
+        PLItem *o_item = [o_outline_view itemAtRow:idx];
 
         /* perform some checks whether it is a file and if it is local at all... */
-        if ([o_mrl length] > 0) {
-            NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
-            if (prefix_range.location != NSNotFound)
-                [o_mrl deleteCharactersInRange: prefix_range];
+        char *psz_url = input_item_GetURI([o_item input]);
+        NSURL *url = [NSURL URLWithString:toNSStr(psz_url)];
+        free(psz_url);
+        if (![url isFileURL])
+            return;
+        if (![[NSFileManager defaultManager] fileExistsAtPath:[url path]])
+            return;
 
-            if ([o_mrl characterAtIndex:0] == '/')
-                [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
-        }
+        msg_Dbg(VLCIntf, "Reveal url %s in finder", [[url path] UTF8String]);
+        [[NSWorkspace sharedWorkspace] selectFile: [url path] inFileViewerRootedAtPath: [url path]];
+    }];
 
-        [o_mrl release];
-    }
 }
 
 /* When called retrieves the selected outlineview row and plays that node or item */



More information about the vlc-commits mailing list