Revision: 5720
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5720&view=rev
Author:   hofman
Date:     2009-09-08 21:23:59 +0000 (Tue, 08 Sep 2009)

Log Message:
-----------
use framework methods for UTI and icons

Modified Paths:
--------------
    trunk/NSImage_SKExtensions.h
    trunk/NSImage_SKExtensions.m
    trunk/SKBookmarkController.m
    trunk/SKMainDocument.m

Modified: trunk/NSImage_SKExtensions.h
===================================================================
--- trunk/NSImage_SKExtensions.h        2009-09-08 20:32:01 UTC (rev 5719)
+++ trunk/NSImage_SKExtensions.h        2009-09-08 21:23:59 UTC (rev 5720)
@@ -125,10 +125,6 @@
 + (void)makeAdornImages;
 + (void)makeCursorImages;
 
-+ (NSImage *)iconWithSize:(NSSize)iconSize forToolboxCode:(OSType)code;
-+ (NSImage *)smallImageWithIconForToolboxCode:(OSType)code;
-+ (NSImage *)tinyImageWithIconForToolboxCode:(OSType) code;
-
 + (NSImage *)smallFolderImage;
 + (NSImage *)tinyFolderImage;
 
@@ -138,6 +134,9 @@
 + (NSImage *)smallMultipleFilesImage;
 + (NSImage *)tinyMultipleFilesImage;
 
++ (NSImage *)smallDeleteImage;
++ (NSImage *)tinyDeleteImage;
+
 - (void)drawFlippedInRect:(NSRect)dstRect fromRect:(NSRect)srcRect 
operation:(NSCompositingOperation)op fraction:(CGFloat)delta;
 - (void)drawFlipped:(BOOL)isFlipped inRect:(NSRect)dstRect 
fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op 
fraction:(CGFloat)delta;
 - (void)drawMirroredAndFlipped:(BOOL)isFlipped inRect:(NSRect)dstRect 
fromRect:(NSRect)srcRect operation:(NSCompositingOperation)op 
fraction:(CGFloat)delta;

Modified: trunk/NSImage_SKExtensions.m
===================================================================
--- trunk/NSImage_SKExtensions.m        2009-09-08 20:32:01 UTC (rev 5719)
+++ trunk/NSImage_SKExtensions.m        2009-09-08 21:23:59 UTC (rev 5720)
@@ -1865,50 +1865,32 @@
     [zoomOutCursorImage setName:SKImageNameZoomOutCursor];
 }
 
-static NSSize smallImageSize = {32.0, 32.0};
-static NSSize tinyImageSize = {16.0, 16.0};
+#define smallImageSize NSMakeSize(32.0, 32.0)
+#define smallImageRect NSMakeRect(0.0, 0.0, 32.0, 32.0)
+#define tinyImageSize NSMakeSize(16.0, 16.0)
+#define tinyImageRect NSMakeRect(0.0, 0.0, 16.0, 16.0)
 
-+ (NSImage *)iconWithSize:(NSSize)iconSize forToolboxCode:(OSType) code {
-       IconRef iconref;
-       OSErr myErr = GetIconRef (kOnSystemDisk, kSystemIconsCreator, code, 
&iconref);
-       
-       NSImage *image = [[NSImage alloc] 
initWithSize:NSMakeSize(iconSize.width, iconSize.height)]; 
-       CGRect rect =  CGRectMake(0.0, 0.0, iconSize.width, iconSize.height);
-       
-       [image lockFocus];
-       PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext] 
graphicsPort],
-                         &rect,
-                                                kAlignAbsoluteCenter, 
//kAlignNone,
-                                                kTransformNone,
-                                                NULL /*inLabelColor*/,
-                                                kPlotIconRefNormalFlags,
-                                                iconref); 
-       [image unlockFocus]; 
-       
-       myErr = ReleaseIconRef(iconref);
-       
-       return [image autorelease];
-}
-
-+ (NSImage *)smallImageWithIconForToolboxCode:(OSType) code {
-    return [self iconWithSize:smallImageSize forToolboxCode:code];
-}
-
-+ (NSImage *)tinyImageWithIconForToolboxCode:(OSType) code {
-    return [self iconWithSize:tinyImageSize forToolboxCode:code];
-}
-
 + (NSImage *)smallFolderImage {
     static NSImage *image = nil;
-    if(image == nil)
-        image = [[self smallImageWithIconForToolboxCode:kGenericFolderIcon] 
retain];
+    if(image == nil) {
+        NSImage *folder = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
+        image = [[NSImage alloc] initWithSize:smallImageSize];
+        [image lockFocus];
+        [folder drawInRect:smallImageRect fromRect:NSZeroRect 
operation:NSCompositeCopy fraction:1.0];
+        [image unlockFocus];
+    }
     return image;
 }
 
 + (NSImage *)tinyFolderImage {
     static NSImage *image = nil;
-    if(image == nil)
-        image = [[self tinyImageWithIconForToolboxCode:kGenericFolderIcon] 
retain];
+    if(image == nil) {
+        NSImage *folder = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
+        image = [[NSImage alloc] initWithSize:tinyImageSize];
+        [image lockFocus];
+        [folder drawInRect:tinyImageRect fromRect:NSZeroRect 
operation:NSCompositeCopy fraction:1.0];
+        [image unlockFocus];
+    }
     return image;
 }
 
@@ -1916,11 +1898,11 @@
     static NSImage *image = nil;
     if(image == nil){
         image = [[NSImage alloc] initWithSize:smallImageSize];
-        NSImage *genericDocImage = [self 
smallImageWithIconForToolboxCode:kGenericDocumentIcon];
-        NSImage *questionMark = [self iconWithSize:NSMakeSize(20.0, 20.0) 
forToolboxCode:kQuestionMarkIcon];
+        NSImage *genericDocImage = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kGenericDocumentIcon)];
+        NSImage *questionMark = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kQuestionMarkIcon)];
         [image lockFocus];
-        [genericDocImage compositeToPoint:NSZeroPoint 
operation:NSCompositeCopy fraction:0.7];
-        [questionMark compositeToPoint:NSMakePoint(6.0, 4.0) 
operation:NSCompositeSourceOver fraction:0.7];
+        [genericDocImage drawInRect:smallImageRect fromRect:NSZeroRect 
operation:NSCompositeCopy fraction:0.7];
+        [questionMark drawInRect:NSMakeRect(6.0, 4.0, 20.0, 20.0) 
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.7];
         [image unlockFocus];
     }
     return image;
@@ -1930,11 +1912,11 @@
     static NSImage *image = nil;
     if(image == nil){
         image = [[NSImage alloc] initWithSize:tinyImageSize];
-        NSImage *genericDocImage = [self 
tinyImageWithIconForToolboxCode:kGenericDocumentIcon];
-        NSImage *questionMark = [self iconWithSize:NSMakeSize(10.0, 10.0) 
forToolboxCode:kQuestionMarkIcon];
+        NSImage *genericDocImage = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kGenericDocumentIcon)];
+        NSImage *questionMark = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kQuestionMarkIcon)];
         [image lockFocus];
-        [genericDocImage compositeToPoint:NSZeroPoint 
operation:NSCompositeCopy fraction:0.7];
-        [questionMark compositeToPoint:NSMakePoint(3.0, 2.0) 
operation:NSCompositeSourceOver fraction:0.7];
+        [genericDocImage drawInRect:tinyImageRect fromRect:NSZeroRect 
operation:NSCompositeCopy fraction:0.7];
+        [questionMark drawInRect:NSMakeRect(3.0, 2.0, 10.0, 10.0) 
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.7];
         [image unlockFocus];
     }
     return image;
@@ -1944,11 +1926,10 @@
     static NSImage *image = nil;
     if(image == nil) {
         image = [[NSImage alloc] initWithSize:smallImageSize];
-        NSImage *multipleFilesImage = [[NSWorkspace sharedWorkspace] 
iconForFiles:[NSArray arrayWithObjects:@"", @"", nil]];
+        NSImage *multipleFilesImage = [NSImage 
imageNamed:NSImageNameMultipleDocuments];
         NSRect sourceRect = {NSZeroPoint, [multipleFilesImage size]};
-        NSRect targetRect = {NSZeroPoint, smallImageSize};
         [image lockFocus];
-        [multipleFilesImage drawInRect:targetRect fromRect:sourceRect 
operation:NSCompositeCopy fraction:1.0];
+        [multipleFilesImage drawInRect:smallImageRect fromRect:sourceRect 
operation:NSCompositeCopy fraction:1.0];
         [image unlockFocus];
     }
     return image;
@@ -1958,16 +1939,39 @@
     static NSImage *image = nil;
     if(image == nil) {
         image = [[NSImage alloc] initWithSize:tinyImageSize];
-        NSImage *multipleFilesImage = [[NSWorkspace sharedWorkspace] 
iconForFiles:[NSArray arrayWithObjects:@"", @"", nil]];
+        NSImage *multipleFilesImage = [NSImage 
imageNamed:NSImageNameMultipleDocuments];
         NSRect sourceRect = {NSZeroPoint, [multipleFilesImage size]};
-        NSRect targetRect = {NSZeroPoint, tinyImageSize};
         [image lockFocus];
-        [multipleFilesImage drawInRect:targetRect fromRect:sourceRect 
operation:NSCompositeCopy fraction:1.0];
+        [multipleFilesImage drawInRect:tinyImageRect fromRect:sourceRect 
operation:NSCompositeCopy fraction:1.0];
         [image unlockFocus];
     }
     return image;
 }
 
++ (NSImage *)smallDeleteImage {
+    static NSImage *image = nil;
+    if(image == nil) {
+        NSImage *delete = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kToolbarDeleteIcon)];
+        image = [[NSImage alloc] initWithSize:smallImageSize];
+        [image lockFocus];
+        [delete drawInRect:smallImageRect fromRect:NSZeroRect 
operation:NSCompositeCopy fraction:1.0];
+        [image unlockFocus];
+    }
+    return image;
+}
+
++ (NSImage *)tinyDeleteImage {
+    static NSImage *image = nil;
+    if(image == nil) {
+        NSImage *delete = [[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kToolbarDeleteIcon)];
+        image = [[NSImage alloc] initWithSize:tinyImageSize];
+        [image lockFocus];
+        [delete drawInRect:tinyImageRect fromRect:NSZeroRect 
operation:NSCompositeCopy fraction:1.0];
+        [image unlockFocus];
+    }
+    return image;
+}
+
 - (void)drawFlippedInRect:(NSRect)dstRect fromRect:(NSRect)srcRect 
operation:(NSCompositingOperation)op fraction:(CGFloat)delta {
     [self drawMirrored:NO andFlipped:YES inRect:dstRect fromRect:srcRect 
operation:op fraction:delta];
 }

Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m        2009-09-08 20:32:01 UTC (rev 5719)
+++ trunk/SKBookmarkController.m        2009-09-08 21:23:59 UTC (rev 5720)
@@ -793,7 +793,7 @@
     item = [[SKToolbarItem alloc] 
initWithItemIdentifier:SKBookmarksDeleteToolbarItemIdentifier];
     [item setLabels:NSLocalizedString(@"Delete", @"Toolbar item label")];
     [item setToolTip:NSLocalizedString(@"Delete Selected Items", @"Tool tip 
message")];
-    [item setImage:[NSImage 
smallImageWithIconForToolboxCode:kToolbarDeleteIcon]];
+    [item setImage:[NSImage smallDeleteImage]];
     [item setTarget:self];
     [item setAction:@selector(deleteBookmark:)];
     [toolbarItems setObject:item 
forKey:SKBookmarksDeleteToolbarItemIdentifier];

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2009-09-08 20:32:01 UTC (rev 5719)
+++ trunk/SKMainDocument.m      2009-09-08 21:23:59 UTC (rev 5720)
@@ -1352,8 +1352,9 @@
     NSString *extension = [fileName pathExtension];
     BOOL isDVI = NO;
     if (extension) {
-        NSString *theUTI = 
[(id)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, 
(CFStringRef)extension, NULL) autorelease];
-        if ([extension caseInsensitiveCompare:@"pdfd"] == NSOrderedSame || 
(theUTI && UTTypeConformsTo((CFStringRef)theUTI, 
CFSTR("net.sourceforge.skim-app.pdfd")))) {
+        NSWorkspace *ws = [NSWorkspace sharedWorkspace];
+        NSString *theUTI = [ws typeOfFile:fileName error:NULL];
+        if ([extension caseInsensitiveCompare:@"pdfd"] == NSOrderedSame || [ws 
type:theUTI conformsToType:@"net.sourceforge.skim-app.pdfd"]) {
             fileName = [[NSFileManager defaultManager] 
bundledFileWithExtension:@"pdf" inPDFBundleAtPath:fileName error:NULL];
             if (fileName == nil)
                 return NO;
@@ -1592,12 +1593,10 @@
         [cmdString insertString:editorCmd atIndex:0];
         [cmdString insertString:@"\"" atIndex:0];
         
-        NSString *extension = [editorCmd pathExtension];
-        if (extension) {
-            NSString *theUTI = 
[(id)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, 
(CFStringRef)extension, NULL) autorelease];
-            if (theUTI && UTTypeConformsTo((CFStringRef)theUTI, 
CFSTR("com.apple.applescript.script")) || UTTypeConformsTo((CFStringRef)theUTI, 
CFSTR("com.apple.applescript.text")))
-                [cmdString insertString:@"/usr/bin/osascript " atIndex:0];
-        }
+        NSWorkspace *ws = [NSWorkspace sharedWorkspace];
+        NSString *theUTI = [ws typeOfFile:editorCmd error:NULL];
+        if ([ws type:theUTI conformsToType:@"com.apple.applescript.script"] || 
[ws type:theUTI conformsToType:@"com.apple.applescript.text"])
+            [cmdString insertString:@"/usr/bin/osascript " atIndex:0];
         
         [NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:[NSArray 
arrayWithObjects:@"-c", cmdString, nil] currentDirectoryPath:[file 
stringByDeletingLastPathComponent]];
     }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to