Revision: 2642
http://skim-app.svn.sourceforge.net/skim-app/?rev=2642&view=rev
Author: hofman
Date: 2007-08-13 08:05:28 -0700 (Mon, 13 Aug 2007)
Log Message:
-----------
Move code to get a URL from a pasteboard to a separate NSURL category.
Modified Paths:
--------------
trunk/SKDocumentController.m
trunk/SKDownloadController.h
trunk/SKDownloadController.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/NSURL_SKExtensions.h
trunk/NSURL_SKExtensions.m
Added: trunk/NSURL_SKExtensions.h
===================================================================
--- trunk/NSURL_SKExtensions.h (rev 0)
+++ trunk/NSURL_SKExtensions.h 2007-08-13 15:05:28 UTC (rev 2642)
@@ -0,0 +1,45 @@
+//
+// NSURL_SKExtensions.h
+// Skim
+//
+// Created by Christiaan Hofman on 8/13/07.
+/*
+ This software is Copyright (c) 2007
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+extern NSString *SKWeblocFilePboardType;
+
[EMAIL PROTECTED] NSURL (SKExtensions)
++ (NSURL *)URLFromPasteboardAnyType:(NSPasteboard *)pasteboard;
[EMAIL PROTECTED]
Added: trunk/NSURL_SKExtensions.m
===================================================================
--- trunk/NSURL_SKExtensions.m (rev 0)
+++ trunk/NSURL_SKExtensions.m 2007-08-13 15:05:28 UTC (rev 2642)
@@ -0,0 +1,67 @@
+//
+// NSURL_SKExtensions.m
+// Skim
+//
+// Created by Christiaan Hofman on 8/13/07.
+/*
+ This software is Copyright (c) 2007
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "NSURL_SKExtensions.h"
+
+NSString *SKWeblocFilePboardType = @"CorePasteboardFlavorType 0x75726C20";
+
[EMAIL PROTECTED] NSURL (SKExtensions)
+
++ (NSURL *)URLFromPasteboardAnyType:(NSPasteboard *)pasteboard {
+ NSString *pboardType = [pasteboard availableTypeFromArray:[NSArray
arrayWithObjects:NSURLPboardType, SKWeblocFilePboardType, NSStringPboardType,
nil]];
+ NSURL *theURL = nil;
+ if ([pboardType isEqualToString:NSURLPboardType]) {
+ theURL = [NSURL URLFromPasteboard:pasteboard];
+ } else if ([pboardType isEqualToString:SKWeblocFilePboardType]) {
+ theURL = [NSURL URLWithString:[pasteboard
stringForType:SKWeblocFilePboardType]];
+ } else if ([pboardType isEqualToString:NSStringPboardType]) {
+ NSString *string = [[pasteboard stringForType:NSStringPboardType]
stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];
+ if ([string hasPrefix:@"<"] && [string hasSuffix:@">"])
+ string = [string substringWithRange:NSMakeRange(1, [string length]
- 2)];
+ theURL = [NSURL URLWithString:string];
+ if (theURL == nil) {
+ if ([string hasPrefix:@"~"])
+ string = [string stringByExpandingTildeInPath];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:string])
+ theURL = [NSURL fileURLWithPath:string];
+ }
+ }
+ return theURL;
+}
+
[EMAIL PROTECTED]
Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m 2007-08-13 14:48:43 UTC (rev 2641)
+++ trunk/SKDocumentController.m 2007-08-13 15:05:28 UTC (rev 2642)
@@ -40,6 +40,7 @@
#import "SKDocument.h"
#import "SKDownloadController.h"
#import "NSString_SKExtensions.h"
+#import "NSURL_SKExtensions.h"
// See CFBundleTypeName in Info.plist
NSString *SKPDFDocumentType = nil; /* set to NSPDFPboardType, not
@"NSPDFPboardType" */
@@ -168,23 +169,7 @@
} else if ([pboardType isEqualToString:NSURLPboardType] || [pboardType
isEqualToString:SKWeblocFilePboardType] || [pboardType
isEqualToString:NSStringPboardType]) {
- NSURL *theURL = nil;
- if ([pboardType isEqualToString:NSURLPboardType]) {
- theURL = [NSURL URLFromPasteboard:pboard];
- } else if ([pboardType isEqualToString:SKWeblocFilePboardType]) {
- theURL = [NSURL URLWithString:[pboard
stringForType:SKWeblocFilePboardType]];
- } else if ([pboardType isEqualToString:NSStringPboardType]) {
- NSString *string = [[pboard stringForType:NSStringPboardType]
stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];
- if ([string hasPrefix:@"<"] && [string hasSuffix:@">"])
- string = [string substringWithRange:NSMakeRange(1, [string
length] - 2)];
- theURL = [NSURL URLWithString:string];
- if (theURL == nil) {
- if ([string hasPrefix:@"~"])
- string = [string stringByExpandingTildeInPath];
- if ([[NSFileManager defaultManager] fileExistsAtPath:string])
- theURL = [NSURL fileURLWithPath:string];
- }
- }
+ NSURL *theURL = [NSURL URLFromPasteboardAnyType:pboard];
if ([theURL isFileURL]) {
document = [self openDocumentWithContentsOfURL:theURL display:YES
error:outError];
} else if (theURL) {
Modified: trunk/SKDownloadController.h
===================================================================
--- trunk/SKDownloadController.h 2007-08-13 14:48:43 UTC (rev 2641)
+++ trunk/SKDownloadController.h 2007-08-13 15:05:28 UTC (rev 2642)
@@ -38,7 +38,6 @@
#import <Cocoa/Cocoa.h>
-extern NSString *SKWeblocFilePboardType;
@interface SKDownloadController : NSWindowController {
IBOutlet NSTableView *tableView;
Modified: trunk/SKDownloadController.m
===================================================================
--- trunk/SKDownloadController.m 2007-08-13 14:48:43 UTC (rev 2641)
+++ trunk/SKDownloadController.m 2007-08-13 15:05:28 UTC (rev 2642)
@@ -39,8 +39,8 @@
#import "SKDownloadController.h"
#import "SKDownload.h"
#import "SKProgressCell.h"
+#import "NSURL_SKExtensions.h"
-NSString *SKWeblocFilePboardType = @"CorePasteboardFlavorType 0x75726C20";
@implementation SKDownloadController
@@ -197,25 +197,8 @@
- (BOOL)tableView:(NSTableView*)tv acceptDrop:(id <NSDraggingInfo>)info
row:(int)row dropOperation:(NSTableViewDropOperation)op {
NSPasteboard *pboard = [info draggingPasteboard];
- NSString *type = [pboard availableTypeFromArray:[NSArray
arrayWithObjects:NSURLPboardType, SKWeblocFilePboardType, NSStringPboardType,
nil]];
- NSURL *theURL;
+ NSURL *theURL = [NSURL URLFromPasteboardAnyType:pboard];
- if ([type isEqualToString:NSURLPboardType]) {
- theURL = [NSURL URLFromPasteboard:pboard];
- } else if ([type isEqualToString:SKWeblocFilePboardType]) {
- theURL = [NSURL URLWithString:[pboard
stringForType:SKWeblocFilePboardType]];
- } else if ([type isEqualToString:NSStringPboardType]) {
- NSString *string = [[pboard stringForType:NSStringPboardType]
stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];
- if ([string hasPrefix:@"<"] && [string hasSuffix:@">"])
- string = [string substringWithRange:NSMakeRange(1, [string length]
- 2)];
- theURL = [NSURL URLWithString:string];
- if (theURL == nil) {
- if ([string hasPrefix:@"~"])
- string = [string stringByExpandingTildeInPath];
- if ([[NSFileManager defaultManager] fileExistsAtPath:string])
- theURL = [NSURL fileURLWithPath:string];
- }
- }
if ([theURL isFileURL]) {
if ([[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:theURL display:YES error:NULL])
return YES;
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2007-08-13 14:48:43 UTC (rev
2641)
+++ trunk/Skim.xcodeproj/project.pbxproj 2007-08-13 15:05:28 UTC (rev
2642)
@@ -161,6 +161,8 @@
CEAA55F10C6DE5AE006BD633 /* DownloadsWindow.nib in Resources */
= {isa = PBXBuildFile; fileRef = CEAA55EF0C6DE5AE006BD633 /*
DownloadsWindow.nib */; };
CEAA56D40C6DEE83006BD633 /* Cancel.tiff in Resources */ = {isa
= PBXBuildFile; fileRef = CEAA56D20C6DEE83006BD633 /* Cancel.tiff */; };
CEAA56D50C6DEE83006BD633 /* Delete.tiff in Resources */ = {isa
= PBXBuildFile; fileRef = CEAA56D30C6DEE83006BD633 /* Delete.tiff */; };
+ CEAA67250C70A882006BD633 /* NSURL_SKExtensions.h in CopyFiles
*/ = {isa = PBXBuildFile; fileRef = CEAA67230C70A882006BD633 /*
NSURL_SKExtensions.h */; };
+ CEAA67260C70A882006BD633 /* NSURL_SKExtensions.m in Sources */
= {isa = PBXBuildFile; fileRef = CEAA67240C70A882006BD633 /*
NSURL_SKExtensions.m */; };
CEAF079D0C4139EB00C3ECBB /* SKStatusBar.m in Sources */ = {isa
= PBXBuildFile; fileRef = CEAF079B0C4139EB00C3ECBB /* SKStatusBar.m */; };
CEAF2E5A0C45414100C3ECBB /* SKLine.m in Sources */ = {isa =
PBXBuildFile; fileRef = CEAF2E580C45414100C3ECBB /* SKLine.m */; };
CEAFFD7C0C40ED5400C3ECBB /* ToolbarColors.tiff in Resources */
= {isa = PBXBuildFile; fileRef = CEAFFD7A0C40ED5400C3ECBB /* ToolbarColors.tiff
*/; };
@@ -269,6 +271,7 @@
dstSubfolderSpec = 10;
files = (
CE2BD8450BD4135600A5F4DB /* Sparkle.framework
in CopyFiles */,
+ CEAA67250C70A882006BD633 /*
NSURL_SKExtensions.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -537,6 +540,8 @@
CEAA56600C6DE96F006BD633 /* Italian */ = {isa =
PBXFileReference; lastKnownFileType = wrapper.nib; name = Italian; path =
Italian.lproj/DownloadsWindow.nib; sourceTree = "<group>"; };
CEAA56D20C6DEE83006BD633 /* Cancel.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; name = Cancel.tiff; path =
Images/Cancel.tiff; sourceTree = "<group>"; };
CEAA56D30C6DEE83006BD633 /* Delete.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; name = Delete.tiff; path =
Images/Delete.tiff; sourceTree = "<group>"; };
+ CEAA67230C70A882006BD633 /* NSURL_SKExtensions.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
NSURL_SKExtensions.h; sourceTree = "<group>"; };
+ CEAA67240C70A882006BD633 /* NSURL_SKExtensions.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= NSURL_SKExtensions.m; sourceTree = "<group>"; };
CEAF079A0C4139EB00C3ECBB /* SKStatusBar.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKStatusBar.h; sourceTree = "<group>"; };
CEAF079B0C4139EB00C3ECBB /* SKStatusBar.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKStatusBar.m; sourceTree = "<group>"; };
CEAF2E570C45414100C3ECBB /* SKLine.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKLine.h; sourceTree = "<group>"; };
@@ -801,6 +806,8 @@
CE070EA10B89039700733CC8 /*
NSScrollView_SKExtensions.m */,
CE38ECD10B8093B200A1B779 /*
NSString_SKExtensions.h */,
CE38ECD20B8093B200A1B779 /*
NSString_SKExtensions.m */,
+ CEAA67230C70A882006BD633 /*
NSURL_SKExtensions.h */,
+ CEAA67240C70A882006BD633 /*
NSURL_SKExtensions.m */,
CEF7119F0B90B714003A2771 /*
NSUserDefaultsController_SKExtensions.h */,
CEF711A00B90B714003A2771 /*
NSUserDefaultsController_SKExtensions.m */,
CE41B2C90C08D17100E36EB7 /*
NSValue_SKExtensions.h */,
@@ -1434,6 +1441,7 @@
CEAA55800C6DE030006BD633 /*
SKDownloadController.m in Sources */,
CEAA559E0C6DE235006BD633 /* SKDownload.m in
Sources */,
CEAA55B70C6DE452006BD633 /* SKProgressCell.m in
Sources */,
+ CEAA67260C70A882006BD633 /*
NSURL_SKExtensions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit