Revision: 2653
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2653&view=rev
Author:   hofman
Date:     2007-08-14 02:56:09 -0700 (Tue, 14 Aug 2007)

Log Message:
-----------
Use documentcontroller method for URL service. Add a service to open selected 
PDF. 

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

Modified: trunk/Info.plist
===================================================================
--- trunk/Info.plist    2007-08-14 09:21:28 UTC (rev 2652)
+++ trunk/Info.plist    2007-08-14 09:56:09 UTC (rev 2653)
@@ -365,10 +365,28 @@
         <string>Skim</string>
         <key>NSSendTypes</key>
         <array>
+           <string>NSURLPboardType</string>
            <string>NSStringPboardType</string>
-           <string>NSURLPboardType</string>
+           <string>CorePasteboardFlavorType 0x75726C20</string>
         </array>
      </dict>
+     <dict>
+        <key>NSMenuItem</key>
+        <dict>
+           <key>default</key>
+           <string>Open Selected PDF</string>
+        </dict>
+        <key>NSMessage</key>
+        <string>openDocumentFromDataOnPboard</string>
+        <key>NSPortName</key>
+        <string>Skim</string>
+        <key>NSSendTypes</key>
+        <array>
+           <string>NSPDFPboardType</string>
+           <string>NSPostScriptPboardType</string>
+           <string>NSTIFFPboardType</string>
+        </array>
+     </dict>
   </array>
 
 </dict>

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2007-08-14 09:21:28 UTC (rev 2652)
+++ trunk/SKApplicationController.m     2007-08-14 09:56:09 UTC (rev 2653)
@@ -53,6 +53,8 @@
 #import "SKLine.h"
 #import "NSImage_SKExtensions.h"
 #import "SKDownloadController.h"
+#import "NSURL_SKExtensions.h"
+#import "SKDocumentController.h"
 
 
 @implementation SKApplicationController
@@ -189,54 +191,20 @@
 
 #pragma mark Services Support
 
-- (void)openDocumentFromURLOnPboard:(NSPasteboard *)pboard
-                           userData:(NSString *)userData
-                              error:(NSString **)error{
-
-    NSArray *types = [pboard types];
+- (void)openDocumentFromURLOnPboard:(NSPasteboard *)pboard userData:(NSString 
*)userData error:(NSString **)error {
+    NSError *outError;
+    id document = [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfPasteboard:pboard typesMask:SKURLPboardTypesMask 
error:&outError];
     
-    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 (document == nil && outError && error)
+        *error = [outError localizedDescription];
+}
 
-    if([pdfURL isFileURL]){
-        NSError *newError;
-        [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:pdfURL
-                                                                               
display:YES
-                                                                               
  error:&newError];
-    }else{
-        [[SKDownloadController sharedDownloadController] 
addDownloadForURL:pdfURL];
-    }
+- (void)openDocumentFromDataOnPboard:(NSPasteboard *)pboard userData:(NSString 
*)userData error:(NSString **)error {
+    NSError *outError;
+    id document = [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfPasteboard:pboard typesMask:SKImagePboardTypesMask 
error:&outError];
     
-    return;
+    if (document == nil && outError && error)
+        *error = [outError localizedDescription];
 }
 
 #pragma mark Actions

Modified: trunk/SKDocumentController.h
===================================================================
--- trunk/SKDocumentController.h        2007-08-14 09:21:28 UTC (rev 2652)
+++ trunk/SKDocumentController.h        2007-08-14 09:56:09 UTC (rev 2653)
@@ -47,8 +47,12 @@
 extern NSString *SKPostScriptDocumentType;
 extern NSString *SKDVIDocumentType;
 
+enum {
+    SKImagePboardTypesMask = 1,
+    SKURLPboardTypesMask = 2
+};
 
 @interface SKDocumentController : NSDocumentController
 - (void)newDocumentFromClipboard:(id)sender;
-- (id)openDocumentWithContentsOfPasteboard:(NSPasteboard *)pboard 
error:(NSError **)outError;
+- (id)openDocumentWithContentsOfPasteboard:(NSPasteboard *)pboard 
typesMask:(int)mask error:(NSError **)outError;
 @end

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2007-08-14 09:21:28 UTC (rev 2652)
+++ trunk/SKDocumentController.m        2007-08-14 09:56:09 UTC (rev 2653)
@@ -136,13 +136,13 @@
     return pdfData;
 }
 
-- (id)openDocumentWithContentsOfPasteboard:(NSPasteboard *)pboard 
error:(NSError **)outError {
+- (id)openDocumentWithContentsOfPasteboard:(NSPasteboard *)pboard 
typesMask:(int)mask error:(NSError **)outError {
     // allow any filter services to convert to TIFF data if we can't get PDF 
or PS directly
     pboard = [NSPasteboard pasteboardByFilteringTypesInPasteboard:pboard];
     NSString *pboardType;
     id document = nil;
     
-    if (pboardType = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSPDFPboardType, NSPostScriptPboardType, NSTIFFPboardType, 
nil]]) {
+    if ((mask & SKImagePboardTypesMask) && (pboardType = [pboard 
availableTypeFromArray:[NSArray arrayWithObjects:NSPDFPboardType, 
NSPostScriptPboardType, NSTIFFPboardType, nil]])) {
         
         NSData *data = [pboard dataForType:pboardType];
         
@@ -167,7 +167,7 @@
                 *outError = error;
         }
         
-    } else if (pboardType = [pboard availableTypeFromArray:[NSArray 
arrayWithObjects:NSURLPboardType, SKWeblocFilePboardType, NSStringPboardType, 
nil]]) {
+    } else if ((mask & SKURLPboardTypesMask) && (pboardType = [pboard 
availableTypeFromArray:[NSArray arrayWithObjects:NSURLPboardType, 
SKWeblocFilePboardType, NSStringPboardType, nil]])) {
         
         NSURL *theURL = [NSURL URLFromPasteboardAnyType:pboard];
         if ([theURL isFileURL]) {
@@ -190,7 +190,7 @@
 
 - (void)newDocumentFromClipboard:(id)sender {
     NSError *error = nil;
-    id document = [self openDocumentWithContentsOfPasteboard:[NSPasteboard 
generalPasteboard] error:&error];
+    id document = [self openDocumentWithContentsOfPasteboard:[NSPasteboard 
generalPasteboard] typesMask:SKImagePboardTypesMask | SKURLPboardTypesMask 
error:&error];
     
     if (document == nil && error)
         [NSApp presentError:error];


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
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to