[vlc-commits] macosx: reimplemented the right-click Reveal-in-Finder feature on the window title when using the dark interface style
Felix Paul Kühne
git at videolan.org
Thu Jun 21 17:26:48 CEST 2012
vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Thu Jun 21 17:26:04 2012 +0200| [ce2b23f7e82e4571d59eb90428641e00df9560e0] | committer: Felix Paul Kühne
macosx: reimplemented the right-click Reveal-in-Finder feature on the window title when using the dark interface style
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ce2b23f7e82e4571d59eb90428641e00df9560e0
---
configure.ac | 2 +-
.../macosx/Resources/English.lproj/MainMenu.xib | 19 ++-
modules/gui/macosx/CompatibilityFixes.h | 4 +
modules/gui/macosx/MainWindowTitle.h | 7 ++
modules/gui/macosx/MainWindowTitle.m | 121 ++++++++++++++++++++
5 files changed, 146 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3b66640..da7a386 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3731,7 +3731,7 @@ then
VLC_ADD_OBJCFLAGS([macosx minimal_macosx], [-fobjc-exceptions] )
VLC_ADD_PLUGIN([macosx minimal_macosx])
- VLC_ADD_LIBS([macosx], [-Wl,-framework,QTKit -Wl,-framework,IOKit -Wl,-framework,AddressBook -Wl,-framework,WebKit -Wl,-framework,CoreAudio])
+ VLC_ADD_LIBS([macosx], [-Wl,-framework,QTKit -Wl,-framework,IOKit -Wl,-framework,AddressBook -Wl,-framework,WebKit -Wl,-framework,CoreAudio -Wl,-framework,SystemConfiguration])
if test ! -d ${CONTRIB_DIR}/Sparkle.framework
then
diff --git a/extras/package/macosx/Resources/English.lproj/MainMenu.xib b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
index f91e565..d13520c 100644
--- a/extras/package/macosx/Resources/English.lproj/MainMenu.xib
+++ b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
@@ -2,7 +2,7 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">11E53</string>
+ <string key="IBDocument.SystemVersion">11G15</string>
<string key="IBDocument.InterfaceBuilderVersion">851</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
@@ -21,16 +21,16 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="915"/>
- <integer value="2770"/>
- <integer value="4722"/>
+ <integer value="4596"/>
<integer value="4850"/>
+ <integer value="915"/>
<integer value="5100"/>
- <integer value="1617"/>
- <integer value="4596"/>
<integer value="4948"/>
<integer value="2730"/>
<integer value="4756"/>
+ <integer value="2770"/>
+ <integer value="1617"/>
+ <integer value="4722"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -11859,6 +11859,7 @@ LCAuLi4</string>
<string>4898.CustomClassName</string>
<string>4898.IBPluginDependency</string>
<string>4898.IBViewBoundsToFrameTransform</string>
+ <string>4899.CustomClassName</string>
<string>4899.IBPluginDependency</string>
<string>4899.IBViewBoundsToFrameTransform</string>
<string>4900.IBPluginDependency</string>
@@ -12773,6 +12774,7 @@ LCAuLi4</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABDv4AAwYAAAA</bytes>
</object>
+ <string>VLCWindowTitleTextField</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABCggAAwZAAAA</bytes>
@@ -18054,6 +18056,11 @@ LCAuLi4</string>
<string key="superclassName">NSButtonCell</string>
<reference key="sourceIdentifier" ref="672431580"/>
</object>
+ <object class="IBPartialClassDescription">
+ <string key="className">VLCWindowTitleTextField</string>
+ <string key="superclassName">NSTextField</string>
+ <reference key="sourceIdentifier" ref="672431580"/>
+ </object>
</object>
<object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
<bool key="EncodedWithXMLCoder">YES</bool>
diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
index b4d85d9..cf27f38 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -75,6 +75,10 @@ extern OSErr UpdateSystemActivity(UInt8 activity);
- (void)setPresentationOptions:(NSApplicationPresentationOptions)newOptions;
- (NSApplicationPresentationOptions)currentSystemPresentationOptions;
@end
+
+ at interface NSURL (IntroducedInSnowLeopard)
+- (NSArray *)pathComponents;
+ at end
#endif
#pragma mark -
diff --git a/modules/gui/macosx/MainWindowTitle.h b/modules/gui/macosx/MainWindowTitle.h
index fb85ff5..68e61c4 100644
--- a/modules/gui/macosx/MainWindowTitle.h
+++ b/modules/gui/macosx/MainWindowTitle.h
@@ -103,3 +103,10 @@
{
}
@end
+
+ at interface VLCWindowTitleTextField : NSTextField
+{
+ NSMenu * contextMenu;
+}
+
+ at end
diff --git a/modules/gui/macosx/MainWindowTitle.m b/modules/gui/macosx/MainWindowTitle.m
index 55cb1f7..41e6381 100644
--- a/modules/gui/macosx/MainWindowTitle.m
+++ b/modules/gui/macosx/MainWindowTitle.m
@@ -26,6 +26,7 @@
#import "MainWindowTitle.h"
#import "CoreInteraction.h"
#import "CompatibilityFixes.h"
+#import <SystemConfiguration/SystemConfiguration.h> // for the revealInFinder clone
/*****************************************************************************
* VLCMainWindowTitleView
@@ -453,3 +454,123 @@
#endif
@end
+
+
+ at implementation VLCWindowTitleTextField
+
+- (void)dealloc
+{
+ if (contextMenu)
+ [contextMenu release];
+
+ [super dealloc];
+}
+
+- (void)showRightClickMenuWithEvent:(NSEvent *)o_event
+{
+ if (contextMenu)
+ [contextMenu release];
+
+ NSURL * representedURL = [[self window] representedURL];
+ if (! representedURL)
+ return;
+
+ NSArray * pathComponents;
+
+ if (OSX_SNOW_LEOPARD || OSX_LION)
+ pathComponents = [representedURL pathComponents];
+ else
+ pathComponents = [[representedURL path] pathComponents];
+
+ if (!pathComponents)
+ return;
+
+ contextMenu = [[NSMenu alloc] initWithTitle: [[NSFileManager defaultManager] displayNameAtPath: [representedURL path]]];
+
+ NSUInteger count = [pathComponents count];
+ NSImage * icon;
+ NSMenuItem * currentItem;
+ NSMutableString * currentPath;
+ NSSize iconSize = NSMakeSize( 16., 16. );
+ for (NSUInteger i = count - 1; i > 0; i--) {
+ currentPath = [NSMutableString stringWithCapacity:1024];
+ for (NSUInteger y = 0; y < i; y++)
+ [currentPath appendFormat: @"/%@", [pathComponents objectAtIndex:y + 1]];
+
+ [contextMenu addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath: currentPath] action:@selector(revealInFinder:) keyEquivalent:@""];
+ currentItem = [contextMenu itemAtIndex:[contextMenu numberOfItems] - 1];
+ [currentItem setTarget: self];
+
+ icon = [[NSWorkspace sharedWorkspace] iconForFile:currentPath];
+ [icon setSize: iconSize];
+ [currentItem setImage: icon];
+ }
+
+ if ([[pathComponents objectAtIndex: 1] isEqualToString:@"Users"]) {
+ /* we're on the boot drive, so add it is since it isn't part of the components */
+ [contextMenu addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:@"/"] action:@selector(revealInFinder:) keyEquivalent:@""];
+ currentItem = [contextMenu itemAtIndex: [contextMenu numberOfItems] - 1];
+ icon = [[NSWorkspace sharedWorkspace] iconForFile:@"/"];
+ [icon setSize: iconSize];
+ [currentItem setImage: icon];
+ [currentItem setTarget: self];
+ }
+
+ /* add the computer item */
+ [contextMenu addItemWithTitle: [(NSString*)SCDynamicStoreCopyComputerName(NULL, NULL) autorelease] action:@selector(revealInFinder:) keyEquivalent:@""];
+ currentItem = [contextMenu itemAtIndex: [contextMenu numberOfItems] - 1];
+ icon = [NSImage imageNamed: NSImageNameComputer];
+ [icon setSize: iconSize];
+ [currentItem setImage: icon];
+ [currentItem setTarget: self];
+
+ [NSMenu popUpContextMenu: contextMenu withEvent: o_event forView: [self superview]];
+}
+
+- (IBAction)revealInFinder:(id)sender
+{
+ NSUInteger count = [contextMenu numberOfItems];
+ NSUInteger selectedItem = [contextMenu indexOfItem: sender];
+
+ if (selectedItem == count - 1) // the fake computer item
+ {
+ [[NSWorkspace sharedWorkspace] selectFile: @"/" inFileViewerRootedAtPath: @""];
+ return;
+ }
+
+ NSURL * representedURL = [[self window] representedURL];
+ if (! representedURL)
+ return;
+
+ if (selectedItem == 0) // the actual file, let's save time
+ {
+ [[NSWorkspace sharedWorkspace] selectFile: [representedURL path] inFileViewerRootedAtPath: [representedURL path]];
+ return;
+ }
+
+ NSArray * pathComponents;
+ if (OSX_SNOW_LEOPARD || OSX_LION)
+ pathComponents = [representedURL pathComponents];
+ else
+ pathComponents = [[representedURL path] pathComponents];
+ if (!pathComponents)
+ return;
+
+ NSMutableString * currentPath;
+ currentPath = [NSMutableString stringWithCapacity:1024];
+ selectedItem = count - selectedItem;
+ for (NSUInteger y = 1; y < selectedItem; y++)
+ [currentPath appendFormat: @"/%@", [pathComponents objectAtIndex:y]];
+
+ [[NSWorkspace sharedWorkspace] selectFile: currentPath inFileViewerRootedAtPath: currentPath];
+}
+
+- (void)rightMouseDown:(NSEvent *)o_event
+{
+ if( [o_event type] == NSRightMouseDown )
+ [self showRightClickMenuWithEvent:o_event];
+
+ [super mouseDown: o_event];
+}
+
+ at end
More information about the vlc-commits
mailing list