[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:54:37 CEST 2012


vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Thu Jun 21 17:52:05 2012 +0200| [a168e79bd412d72ea73ffbbb51be92ed96f4800d] | committer: Felix Paul Kühne

macosx: reimplemented the right-click Reveal-in-Finder feature on the window title when using the dark interface style

manual merge of ce2b23f7e82e4571d59eb90428641e00df9560e0

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

 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 198a4ff..3776421 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3762,7 +3762,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])
+  VLC_ADD_LIBS([macosx], [-Wl,-framework,QTKit -Wl,-framework,IOKit -Wl,-framework,AddressBook -Wl,-framework,WebKit -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 7631b04..c707b46 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,15 +21,15 @@
     </object>
     <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
       <bool key="EncodedWithXMLCoder">YES</bool>
-      <integer value="2730"/>
+      <integer value="4596"/>
+      <integer value="915"/>
+      <integer value="1617"/>
       <integer value="2770"/>
-      <integer value="4948"/>
       <integer value="81"/>
+      <integer value="2730"/>
       <integer value="4850"/>
+      <integer value="4948"/>
       <integer value="4756"/>
-      <integer value="1617"/>
-      <integer value="4596"/>
-      <integer value="915"/>
       <integer value="4722"/>
     </object>
     <object class="NSArray" key="IBDocument.PluginDependencies">
@@ -11610,6 +11610,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>
@@ -12519,6 +12520,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>
@@ -17664,6 +17666,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 cc0d504..ebcf5dd 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -74,6 +74,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 2ed6dbd..3d77d31 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