Revision: 7258
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7258&view=rev
Author:   hofman
Date:     2011-06-07 17:43:25 +0000 (Tue, 07 Jun 2011)

Log Message:
-----------
support 'open location' scripting command

Modified Paths:
--------------
    trunk/SKApplicationController.m

Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m     2011-06-03 00:24:55 UTC (rev 7257)
+++ trunk/SKApplicationController.m     2011-06-07 17:43:25 UTC (rev 7258)
@@ -100,6 +100,7 @@
 
 @interface SKApplicationController (SKPrivate)
 - (void)doSpotlightImportIfNeeded;
+- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event 
withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
 @end
 
 
@@ -181,6 +182,7 @@
 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
     [NSImage makeImages];
     [PDFAnnotation checkPDFKit];
+    [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self 
andSelector:@selector(handleGetURLEvent:withReplyEvent:) 
forEventClass:kInternetEventClass andEventID:kAEGetURL];
 }
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
@@ -391,6 +393,34 @@
 
 #pragma mark Scripting support
 
+- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event 
withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
+    NSString *theURLString = [[event descriptorForKeyword:keyDirectObject] 
stringValue];
+    
+    if (theURLString) {
+        if ([theURLString hasPrefix:@"<"] && [theURLString hasSuffix:@">"])
+            theURLString = [theURLString substringWithRange:NSMakeRange(0, 
[theURLString length] - 2)];
+        if ([theURLString hasPrefix:@"URL:"])
+            theURLString = [theURLString substringFromIndex:4];
+        
+        NSURL *theURL = [NSURL URLWithString:theURLString];
+        
+        if (theURL) {
+            id document = nil;
+            NSError *error = nil;
+            
+            if ([theURL isFileURL]) {
+                document = [[NSDocumentController sharedDocumentController] 
openDocumentWithContentsOfURL:theURL display:YES error:&error];
+                if (document == nil && error && [error isUserCancelledError] 
== NO)
+                    [NSApp presentError:error];
+            } else {
+                document = [[SKDownloadController sharedDownloadController] 
addDownloadForURL:theURL];
+                if (document && [[NSUserDefaults standardUserDefaults] 
boolForKey:SKAutoOpenDownloadsWindowKey])
+                    [[SKDownloadController sharedDownloadController] 
showWindow:nil];
+            }
+        }
+    }
+}
+
 - (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key 
{
     static NSSet *applicationScriptingKeys = nil;
     if (applicationScriptingKeys == nil)


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

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to