-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIPDFMacOpenPanel.m
66 lines (48 loc) · 1.84 KB
/
IPDFMacOpenPanel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// IPDFMacOpenPanel.m
// Scanner
//
// Created by mmackh on 14/02/2020.
// Copyright © 2020 mackh ag. All rights reserved.
//
#import "IPDFMacOpenPanel.h"
@interface NSOpenPanel_Catalyst : NSObject
+ (instancetype)openPanel;
@property (nonatomic) BOOL allowsMultipleSelection;
@property (nonatomic) BOOL canChooseDirectories;
@property (nonatomic) BOOL canChooseFiles;
@property (nonatomic) BOOL resolvesAliases;
@property (nonatomic) BOOL accessoryViewDisclosed;
@property (nonatomic) NSArray *allowedFileTypes;
@property (nonatomic,readonly) NSArray<NSURL *>*URLs;
- (NSInteger)runModal;
- (void)beginSheetModalForWindow:(id)sheetWindow completionHandler:(void (^)(NSInteger returnCode))handler;
@end
@implementation IPDFMacOpenPanel
- (instancetype)init
{
self = [super init];
if (!self) return nil;
self.canChooseFiles = YES;
self.resolvesAliases = YES;
return self;
}
- (void)showPanelWithChosenFilesHandler:(void(^)(NSArray<NSURL*>*fileURLs))openDataHandler
{
NSOpenPanel_Catalyst *openPanel = [NSClassFromString(@"NSOpenPanel") openPanel];
openPanel.allowsMultipleSelection = self.allowsMultipleSelection;
openPanel.canChooseDirectories = self.canChooseDirectories;
openPanel.canChooseFiles = self.canChooseFiles;
openPanel.resolvesAliases = self.resolvesAliases;
openPanel.accessoryViewDisclosed = self.accessoryViewDisclosed;
[openPanel setAllowedFileTypes:self.allowedFileTypes];
id app = [NSClassFromString(@"NSApplication") performSelector:@selector(sharedApplication)];
id keyWindow = [app performSelector:@selector(keyWindow)];
if (!keyWindow) return;
__weak typeof(openPanel) weakOpenPanel = openPanel;
[openPanel beginSheetModalForWindow:keyWindow completionHandler:^(NSInteger returnCode)
{
openDataHandler(weakOpenPanel.URLs);
}];
}
@end