macosx: Fix revealInFinder for main menu item and popup menu
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Wed, 6 Jan 2016 14:41:59 +0000 (15:41 +0100)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Wed, 6 Jan 2016 16:32:50 +0000 (17:32 +0100)
Implementation is the same for both menu items. Menu validation
is used to check before if an item is a local file and existing.
Action is passed from main menu via responder chain to playlist.

extras/package/macosx/Resources/English.lproj/MainMenu.xib
extras/package/macosx/Resources/English.lproj/PlaylistMenu.xib
modules/gui/macosx/MainMenu.h
modules/gui/macosx/MainMenu.m
modules/gui/macosx/MainWindow.m
modules/gui/macosx/VLCPlaylist.h
modules/gui/macosx/VLCPlaylist.m

index 74c921d..58aba3c 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14F25a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
         <deployment version="1070" identifier="macosx"/>
         <development version="5100" identifier="xcode"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="VLCMainMenu">
                             </menuItem>
                             <menuItem title="Reveal in Finder" keyEquivalent="R" id="3945">
                                 <connections>
-                                    <action selector="revealItemInFinder:" target="-2" id="s3X-xq-zrn"/>
+                                    <action selector="revealItemInFinder:" target="-1" id="SHl-6e-1ro"/>
                                 </connections>
                             </menuItem>
                             <menuItem isSeparatorItem="YES" id="79">
index 21f80c9..f78eae6 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8152.3" systemVersion="14F6a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
         <deployment version="1070" identifier="macosx"/>
         <development version="5100" identifier="xcode"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8152.3"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="VLCPlaylist">
@@ -22,8 +22,8 @@
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
-        <customObject id="-3" userLabel="Application"/>
-        <menu title="Menu" autoenablesItems="NO" id="1" userLabel="PlaylistMenu">
+        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+        <menu title="Menu" id="1" userLabel="PlaylistMenu">
             <items>
                 <menuItem title="Play" id="12">
                     <connections>
@@ -81,7 +81,7 @@
                 </menuItem>
                 <menuItem title="Reveal in Finder" id="3">
                     <connections>
-                        <action selector="revealItemInFinder:" target="-2" id="35"/>
+                        <action selector="revealItemInFinder:" target="-2" id="4WU-rm-69M"/>
                     </connections>
                 </menuItem>
             </items>
index 1c9fbba..935bb05 100644 (file)
 - (IBAction)intfOpenNet:(id)sender;
 - (IBAction)intfOpenCapture:(id)sender;
 - (IBAction)savePlaylist:(id)sender;
-- (IBAction)revealItemInFinder:(id)sender;
 
 - (IBAction)toggleEffectsButton:(id)sender;
 - (IBAction)toggleJumpButtons:(id)sender;
index 03d896f..c699740 100644 (file)
     }
 }
 
-- (IBAction)revealItemInFinder:(id)sender
-{
-    [[[VLCMain sharedInstance] playlist] revealItemInFinder:sender];
-}
-
 - (IBAction)showConvertAndSave:(id)sender
 {
     [[[VLCMain sharedInstance] convertAndSaveWindow] showWindow:self];
index 6d8c294..438644e 100644 (file)
@@ -166,6 +166,7 @@ static const float f_min_window_height = 307.;
     VLCPlaylist *playlist = [[VLCMain sharedInstance] playlist];
     [playlist setOutlineView:(VLCPlaylistView *)_outlineView];
     [playlist setPlaylistHeaderView:_outlineView.headerView];
+    [self setNextResponder:playlist];
 
     // (Re)load sidebar for the first time and select first item
     [self reloadSidebar];
index ebf259b..3c21d11 100644 (file)
@@ -27,7 +27,7 @@
 #import "PLModel.h"
 #import "VLCPlaylistView.h"
 
-@interface VLCPlaylist : NSObject<NSOutlineViewDelegate>
+@interface VLCPlaylist : NSResponder<NSOutlineViewDelegate>
 
 @property (readwrite, weak) IBOutlet NSMenu *playlistMenu;
 @property (readwrite, weak) IBOutlet NSMenuItem *playPlaylistMenuItem;
index 2bc33f3..da5cfa3 100644 (file)
     [_outlineView selectRowIndexes: [NSIndexSet indexSetWithIndex: itemIndex] byExtendingSelection: NO];
 }
 
+#pragma mark -
+#pragma mark Playlist actions
+
 /* When called retrieves the selected outlineview row and plays that node or item */
 - (IBAction)playItem:(id)sender
 {
 - (IBAction)revealItemInFinder:(id)sender
 {
     NSIndexSet *selectedRows = [_outlineView selectedRowIndexes];
-    [selectedRows enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
-
-        PLItem *o_item = [_outlineView itemAtRow:idx];
+    if (selectedRows.count < 1)
+        return;
 
-        /* perform some checks whether it is a file and if it is local at all... */
-        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;
+    PLItem *o_item = [_outlineView itemAtRow:selectedRows.firstIndex];
 
-        msg_Dbg(VLCIntf, "Reveal url %s in finder", [[url path] UTF8String]);
-        [[NSWorkspace sharedWorkspace] selectFile: [url path] inFileViewerRootedAtPath: [url path]];
-    }];
+    char *psz_url = input_item_GetURI([o_item input]);
+    if (!psz_url)
+        return;
+    char *psz_path = vlc_uri2path(psz_url);
+    NSString *path = toNSStr(psz_path);
+    free(psz_url);
+    free(psz_path);
 
+    msg_Dbg(VLCIntf, "Reveal url %s in finder", [path UTF8String]);
+    [[NSWorkspace sharedWorkspace] selectFile: path inFileViewerRootedAtPath: path];
 }
 
 /* When called retrieves the selected outlineview row and plays that node or item */
 //    [self playlistUpdated];
 }
 
+- (BOOL)validateMenuItem:(NSMenuItem *)item
+{
+    if ([item action] == @selector(revealItemInFinder:)) {
+        NSIndexSet *selectedRows = [_outlineView selectedRowIndexes];
+        if (selectedRows.count != 1)
+            return NO;
+
+        PLItem *o_item = [_outlineView itemAtRow:selectedRows.firstIndex];
+
+        // Check if item exists in file system
+        char *psz_url = input_item_GetURI([o_item input]);
+        NSURL *url = [NSURL URLWithString:toNSStr(psz_url)];
+        free(psz_url);
+        if (![url isFileURL])
+            return NO;
+        if (![[NSFileManager defaultManager] fileExistsAtPath:[url path]])
+            return NO;
+    }
+
+    return YES;
+}
+
+#pragma mark -
+#pragma mark Item helpers
+
 - (input_item_t *)createItem:(NSDictionary *)itemToCreateDict
 {
     intf_thread_t *p_intf = VLCIntf;