-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIPDFMacSavePanel.m
51 lines (35 loc) · 1.33 KB
/
IPDFMacSavePanel.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
//
// IPDFMacSavePanel.m
// InstaPDF for Mac
//
// Created by mmackh on 13.10.19.
// Copyright © 2019 mackh ag. All rights reserved.
//
#import "IPDFMacSavePanel.h"
@interface NSSavePanel_Catalyst : NSObject
+ (instancetype)savePanel;
@property (nonatomic) NSString *nameFieldStringValue;
@property (nonatomic) NSArray *allowedFileTypes;
@property (nonatomic,readonly) NSURL *URL;
- (NSInteger)runModal;
- (void)beginSheetModalForWindow:(id)sheetWindow completionHandler:(void (^)(NSInteger returnCode))handler;
@end
@implementation IPDFMacSavePanel
+ (void)showPanelWithFileName:(NSString *)fileName allowedFileExtensions:(NSArray *)allowedFileExtensions saveDataHandler:(void(^)(NSURL *targetURL))saveDataHandler
{
NSSavePanel_Catalyst *savePanel = [NSClassFromString(@"NSSavePanel") savePanel];
[savePanel setNameFieldStringValue:fileName];
[savePanel setAllowedFileTypes:allowedFileExtensions];
id app = [NSClassFromString(@"NSApplication") performSelector:@selector(sharedApplication)];
id keyWindow = [app performSelector:@selector(keyWindow)];
if (!keyWindow) return;
__weak typeof(savePanel) weakSavePanel = savePanel;
[savePanel beginSheetModalForWindow:keyWindow completionHandler:^(NSInteger returnCode)
{
saveDataHandler(weakSavePanel.URL);
}];
}
- (void)show
{
}
@end