Skip to content

Commit a890f7e

Browse files
committed
Replace deprecated method for opening files
As the replacement method does not have a return value but rather has a callback, also switch from openFile: to openFiles: to avoid having to return a nonsensical value. (Not 100% sure this is the right thing to do as we call replyToOpenOrPrint: for each file that is opened which seems odd.)
1 parent 2a6e9ce commit a890f7e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Classes/Controllers/ApplicationController.m

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@ - (void)registerServices
7171
}
7272
}
7373

74-
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
75-
NSURL *repository = [NSURL fileURLWithPath:filename];
76-
NSError *error = nil;
77-
NSDocument *doc = [[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:repository
78-
display:YES
79-
error:&error];
80-
if (!doc) {
81-
NSLog(@"Error opening repository \"%@\": %@", repository.path, error);
82-
return NO;
83-
}
84-
85-
return YES;
74+
- (void)application:(NSApplication *)sender openFiles:(NSArray <NSString *> *)filenames {
75+
PBRepositoryDocumentController * controller = [PBRepositoryDocumentController sharedDocumentController];
76+
77+
for (NSString * filename in filenames) {
78+
NSURL * repository = [NSURL fileURLWithPath:filename];
79+
[controller openDocumentWithContentsOfURL:repository display:YES
80+
completionHandler:^void (NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
81+
if (!document) {
82+
NSLog(@"Error opening repository \"%@\": %@", repository.path, error);
83+
[sender replyToOpenOrPrint:NSApplicationDelegateReplyFailure];
84+
}
85+
else {
86+
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
87+
}
88+
}];
89+
}
8690
}
8791

8892
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender

0 commit comments

Comments
 (0)