Commit 6d1da70d authored by David Fuhrmann's avatar David Fuhrmann

macosx: Fix revealInFinder for main menu item and popup menu

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.
parent 75c71f54
<?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">
......@@ -302,7 +302,7 @@
</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">
......
<?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>
......
......@@ -221,7 +221,6 @@
- (IBAction)intfOpenNet:(id)sender;
- (IBAction)intfOpenCapture:(id)sender;
- (IBAction)savePlaylist:(id)sender;
- (IBAction)revealItemInFinder:(id)sender;
- (IBAction)toggleEffectsButton:(id)sender;
- (IBAction)toggleJumpButtons:(id)sender;
......
......@@ -1228,11 +1228,6 @@
}
}
- (IBAction)revealItemInFinder:(id)sender
{
[[[VLCMain sharedInstance] playlist] revealItemInFinder:sender];
}
- (IBAction)showConvertAndSave:(id)sender
{
[[[VLCMain sharedInstance] convertAndSaveWindow] showWindow:self];
......
......@@ -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];
......
......@@ -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;
......
......@@ -291,6 +291,9 @@
[_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
{
......@@ -317,23 +320,21 @@
- (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 */
......@@ -438,6 +439,31 @@
// [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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment