Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,22 @@ - (MDVPreviewWindowController *)currentPreviewWindowController {
return nil;
}

- (NSURL *)standardizedFileURL:(NSURL *)fileURL {
return fileURL.fileURL ? fileURL.URLByStandardizingPath : [NSURL fileURLWithPath:fileURL.path];
}

- (MDVPreviewWindowController *)windowControllerForFileURL:(NSURL *)fileURL {
NSURL *standardURL = [self standardizedFileURL:fileURL];

for (MDVPreviewWindowController *controller in self.windowControllers) {
if ([controller.sourceFileURL isEqual:standardURL]) {
return controller;
}
}

return nil;
}

- (MDVPreviewWindowController *)newWindowController {
MDVPreviewWindowController *controller = [[MDVPreviewWindowController alloc] init];
__weak typeof(self) weakSelf = self;
Expand Down Expand Up @@ -796,6 +812,14 @@ - (void)openFileURLs:(NSArray<NSURL *> *)urls reuseCurrentWindow:(BOOL)reuseCurr

for (NSUInteger index = 0; index < urls.count; index += 1) {
NSURL *fileURL = urls[index];
MDVPreviewWindowController *existingController = [self windowControllerForFileURL:fileURL];
if (existingController) {
[existingController showWindow:self];
[existingController.window makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
continue;
}

MDVPreviewWindowController *controller = (index == 0 && reusableController) ? reusableController : [self newWindowController];
NSError *error = nil;

Expand Down