Revision: 2651
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2651&view=rev
Author:   mmcc
Date:     2007-08-13 18:12:06 -0700 (Mon, 13 Aug 2007)

Log Message:
-----------
add service to download from URL

Modified Paths:
--------------
    trunk/Info.plist
    trunk/SKApplicationController.h
    trunk/SKApplicationController.m

Modified: trunk/Info.plist
===================================================================
--- trunk/Info.plist    2007-08-13 23:15:15 UTC (rev 2650)
+++ trunk/Info.plist    2007-08-14 01:12:06 UTC (rev 2651)
@@ -351,5 +351,25 @@
                        </dict>
                </dict>
        </array>
+   <key>NSServices</key>
+  <array>
+     <dict>
+        <key>NSMenuItem</key>
+        <dict>
+           <key>default</key>
+           <string>Open PDF at URL</string>
+        </dict>
+        <key>NSMessage</key>
+        <string>openDocumentFromURLOnPboard</string>
+        <key>NSPortName</key>
+        <string>Skim</string>
+        <key>NSSendTypes</key>
+        <array>
+           <string>NSStringPboardType</string>
+           <string>NSURLPboardType</string>
+        </array>
+     </dict>
+  </array>
+
 </dict>
 </plist>

Modified: trunk/SKApplicationController.h
===================================================================
--- trunk/SKApplicationController.h     2007-08-13 23:15:15 UTC (rev 2650)
+++ trunk/SKApplicationController.h     2007-08-14 01:12:06 UTC (rev 2651)
@@ -38,10 +38,11 @@
 
 #import <Cocoa/Cocoa.h>
 
[EMAIL PROTECTED] SUUpdater, SKLine;
[EMAIL PROTECTED] SUUpdater, SKLine, SKDownloadController;
 
 @interface SKApplicationController : NSObject {
     BOOL remoteScrolling;
+    
 }
 
 + (void)setupDefaults;

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2007-08-13 23:15:15 UTC (rev 2650)
+++ trunk/SKApplicationController.m     2007-08-14 01:12:06 UTC (rev 2651)
@@ -156,6 +156,7 @@
 }
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
+    [NSApp setServicesProvider:self];
     NSString *versionString = [[[NSBundle mainBundle] infoDictionary] 
objectForKey:@"CFBundleShortVersionString"];
     SKVersionNumber *versionNumber = versionString ? [[[SKVersionNumber alloc] 
initWithVersionString:versionString] autorelease] : nil;
     NSString *lastVersionString = [[NSUserDefaults standardUserDefaults] 
stringForKey:SKLastVersionLaunchedKey];
@@ -186,6 +187,58 @@
     }
 }
 
+#pragma mark Services Support
+
+- (void)openDocumentFromURLOnPboard:(NSPasteboard *)pboard
+                           userData:(NSString *)userData
+                              error:(NSString **)error{
+
+    NSArray *types = [pboard types];
+    
+    bool pbHasStringType = [types containsObject:NSStringPboardType];
+    bool pbHasURLType = [types containsObject:NSURLPboardType];
+    
+    if (!pbHasStringType && !pbHasURLType) {
+        *error = NSLocalizedString(@"Error: couldn't get a URL.",
+                                   @"pboard couldn't give string or URL.");
+        return;
+    }
+    
+    NSURL *pdfURL = nil;
+    
+    if (pbHasURLType){
+        pdfURL = [NSURL URLFromPasteboard:pboard];
+    }
+    
+    if (pdfURL == nil && pbHasStringType){
+        NSString *pboardString = [pboard stringForType:NSStringPboardType];
+        
+        if (!pboardString) {
+            *error = NSLocalizedString(@"Error: couldn't get a URL.",
+                                       @"pboard couldn't give string.");
+            return;
+        }
+        pdfURL = [NSURL URLWithString:pboardString];
+    }
+    
+    if (!pdfURL){
+        *error = NSLocalizedString(@"Error: couldn't get a URL",
+                                   @"nothing worked.");
+        return;
+    }
+
+    if([pdfURL isFileURL]){
+        NSError *newError;
+        [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:pdfURL
+                                                                               
display:YES
+                                                                               
  error:&newError];
+    }else{
+        [[SKDownloadController sharedDownloadController] 
addDownloadForURL:pdfURL];
+    }
+    
+    return;
+}
+
 #pragma mark Actions
 
 - (IBAction)visitWebSite:(id)sender{


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

Reply via email to