Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move iconForDefaultDirectoryWithFSRef: implementation to smallIconFor…

…FSRef:
  • Loading branch information...
commit 1a6bf202bc310bd791aa45baffc6b0abe421d5fb 1 parent d209a9e
Zachary Schneirov authored
1  GlobalPrefs.h
View
@@ -172,7 +172,6 @@ BOOL ColorsEqualWith8BitChannels(NSColor *c1, NSColor *c2);
- (void)setAliasDataForDefaultDirectory:(NSData*)alias sender:(id)sender;
- (NSData*)aliasDataForDefaultDirectory;
-- (NSImage*)iconForDefaultDirectoryWithFSRef:(FSRef*)fsRef;
- (NSString*)displayNameForDefaultDirectoryWithFSRef:(FSRef*)fsRef;
- (NSString*)humanViewablePathForDefaultDirectory;
29 GlobalPrefs.m
View
@@ -798,35 +798,6 @@ - (NSData*)aliasDataForDefaultDirectory {
return [defaults dataForKey:DirectoryAliasKey];
}
-- (NSImage*)iconForDefaultDirectoryWithFSRef:(FSRef*)fsRef {
- OSStatus err = noErr;
-
- if (!fsRef)
- return nil;
-
- if (IsZeros(fsRef, sizeof(FSRef))) {
- if (![[self aliasDataForDefaultDirectory] fsRefAsAlias:fsRef])
- return nil;
- }
- IconRef iconRef;
- if ((err = GetIconRefFromFileInfo(fsRef, 0, NULL, 0, NULL, kIconServicesNormalUsageFlag, &iconRef, NULL)) == noErr) {
-
- NSImage *image = [[[NSImage alloc] initWithSize:NSMakeSize(16.0f, 16.0f)] autorelease];
- NSRect frame = NSMakeRect(0.0f,0.0f,16.0f,16.0f);
-
- [image lockFocus];
- err = PlotIconRefInContext([[NSGraphicsContext currentContext] graphicsPort], (CGRect *)&frame, 0, 0, nil, 0, iconRef);
- [image unlockFocus];
-
- if (err == noErr)
- return image;
- }
-
- NSLog(@"iconForDefaultDirectory error: %d", err);
-
- return nil;
-}
-
- (NSString*)displayNameForDefaultDirectoryWithFSRef:(FSRef*)fsRef {
if (!fsRef)
5 NSBezierPath_NV.h
View
@@ -31,3 +31,8 @@
+ (NSBezierPath *)bezierPathWithLayoutManager:(NSLayoutManager*)layoutManager characterRange:(NSRange)charRange atPoint:(NSPoint)point;
@end
+
+@interface NSImage (NV)
+
++ (NSImage*)smallIconForFSRef:(FSRef*)fsRef;
+@end
31 NSBezierPath_NV.m
View
@@ -54,3 +54,34 @@ + (NSBezierPath *)bezierPathWithLayoutManager:(NSLayoutManager*)layoutManager ch
@end
+
+
+@implementation NSImage (NV)
+
++ (NSImage*)smallIconForFSRef:(FSRef*)fsRef {
+ OSStatus err = noErr;
+
+ if (!fsRef)
+ return nil;
+
+ IconRef iconRef;
+ if ((err = GetIconRefFromFileInfo(fsRef, 0, NULL, 0, NULL, kIconServicesNormalUsageFlag, &iconRef, NULL)) == noErr) {
+
+ NSImage *image = [[[NSImage alloc] initWithSize:NSMakeSize(16.0f, 16.0f)] autorelease];
+ NSRect frame = NSMakeRect(0.0f,0.0f,16.0f,16.0f);
+
+ [image lockFocus];
+ err = PlotIconRefInContext([[NSGraphicsContext currentContext] graphicsPort], (CGRect *)&frame, 0, 0, nil, 0, iconRef);
+ [image unlockFocus];
+
+ if (err == noErr)
+ return image;
+ }
+
+ NSLog(@"smallIconForFSRef error: %d", err);
+
+ return nil;
+}
+
+
+@end
5 PrefsWindowController.m
View
@@ -22,6 +22,7 @@
#import "NSData_transformations.h"
#import "NSString_NV.h"
#import "NSFileManager_NV.h"
+#import "NSBezierPath_NV.h"
#import "NotationPrefs.h"
#import "GlobalPrefs.h"
@@ -242,7 +243,9 @@ - (NSMenu*)directorySelectionMenu {
if (!name)
name = NSLocalizedString(@"<Directory unknown>", nil);
- NSImage *iconImage = [prefsController iconForDefaultDirectoryWithFSRef:&targetRef];
+ NSImage *iconImage = nil;
+ if (!IsZeros(&targetRef, sizeof(FSRef)) || [[prefsController aliasDataForDefaultDirectory] fsRefAsAlias:&targetRef])
+ iconImage = [NSImage smallIconForFSRef:&targetRef];
NSMenuItem *theMenuItem = [[[NSMenuItem alloc] initWithTitle:name action:nil keyEquivalent:@""] autorelease];
Please sign in to comment.
Something went wrong with that request. Please try again.