Revision: 14712
http://sourceforge.net/p/skim-app/code/14712
Author: hofman
Date: 2024-11-17 18:45:58 +0000 (Sun, 17 Nov 2024)
Log Message:
-----------
Use application:openURLs: delegate method to open URLs instead of registering
gURL event handler
Modified Paths:
--------------
trunk/SKApplicationController.m
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2024-11-17 18:21:31 UTC (rev 14711)
+++ trunk/SKApplicationController.m 2024-11-17 18:45:58 UTC (rev 14712)
@@ -209,7 +209,6 @@
[NSImage makeImages];
[NSColor makeHighlightColors];
[NSValueTransformer registerCustomTransformers];
- [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
[PDFPage setUsesSequentialPageNumbering:[[NSUserDefaults
standardUserDefaults] boolForKey:SKSequentialPageNumberingKey]];
[[NSUserDefaults standardUserDefaults] addObserver:self
forKeyPath:SKSequentialPageNumberingKey options:0
context:&SKApplicationControllerDefaultsObservationContext];
}
@@ -257,6 +256,37 @@
return flag;
}
+- (void)application:(NSApplication *)sender openURLs:(NSArray *)urls {
+ for (NSURL *theURL in urls) {
+ if ([theURL isFileURL]) {
+ [[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:theURL display:YES completionHandler:^(NSDocument
*document, BOOL documentWasAlreadyOpen, NSError *error) {
+ if (document == nil && error && [error isUserCancelledError]
== NO)
+ [NSApp presentError:error];
+ }];
+ } else if ([theURL isSkimURL]) {
+ if ([theURL isSkimBookmarkURL]) {
+ SKBookmark *bookmark = [[SKBookmarkController
sharedBookmarkController] bookmarkForURL:theURL];
+ if (bookmark) {
+ [[NSDocumentController sharedDocumentController]
openDocumentWithBookmark:bookmark completionHandler:^(NSDocument *document,
BOOL documentWasAlreadyOpen, NSError *error) {
+ if (document == nil && error && [error
isUserCancelledError] == NO)
+ [NSApp presentError:error];
+ }];
+ }
+ } else {
+ [[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:[theURL associatedFileURL] display:YES
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError
*error) {
+ if (document == nil && error && [error
isUserCancelledError] == NO)
+ [NSApp presentError:error];
+ }];
+ }
+ } else if (theURL) {
+ SKDownload *download = [[SKDownload alloc] initWithURL:theURL];
+ if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKAutoOpenDownloadsWindowKey])
+ [[self downloadController] showWindow:self];
+ [[self downloadController] addObjectToDownloads:download];
+ }
+ }
+}
+
- (void)applicationStartsTerminating:(NSNotification *)aNotification {
[currentDocumentsTimer invalidate];
currentDocumentsTimer = nil;
@@ -443,50 +473,6 @@
#pragma mark Scripting support
-- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
- didCheckReopen = YES;
-
- NSString *theURLString = [[event descriptorForKeyword:keyDirectObject]
stringValue];
- NSAppleEventDescriptor *errr = [event descriptorForKeyword:'errr'];
- BOOL errorReporting = errr ? [errr booleanValue] : YES;
-
- 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] ?: [NSURL
URLWithString:[theURLString
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
URLGenericAllowedCharacterSet]]];
-
- if ([theURL isFileURL]) {
- [[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:theURL display:YES completionHandler:^(NSDocument
*document, BOOL documentWasAlreadyOpen, NSError *error) {
- if (document == nil && errorReporting && error && [error
isUserCancelledError] == NO)
- [NSApp presentError:error];
- }];
- } else if ([theURL isSkimURL]) {
- if ([theURL isSkimBookmarkURL]) {
- SKBookmark *bookmark = [[SKBookmarkController
sharedBookmarkController] bookmarkForURL:theURL];
- if (bookmark) {
- [[NSDocumentController sharedDocumentController]
openDocumentWithBookmark:bookmark completionHandler:^(NSDocument *document,
BOOL documentWasAlreadyOpen, NSError *error) {
- if (document == nil && errorReporting && error &&
[error isUserCancelledError] == NO)
- [NSApp presentError:error];
- }];
- }
- } else {
- [[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:[theURL associatedFileURL] display:YES
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError
*error) {
- if (document == nil && errorReporting && error && [error
isUserCancelledError] == NO)
- [NSApp presentError:error];
- }];
- }
- } else if (theURL) {
- SKDownload *download = [[SKDownload alloc] initWithURL:theURL];
- if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKAutoOpenDownloadsWindowKey])
- [[self downloadController] showWindow:self];
- [[self downloadController] addObjectToDownloads:download];
- }
- }
-}
-
- (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.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit