-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIPDFToolbarHelper.m
105 lines (72 loc) · 2.56 KB
/
IPDFToolbarHelper.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// IPDFToolbarHelper.m
// InstaPDF for Mac
//
// Created by mmackh on 13.10.19.
// Copyright © 2019 mackh ag. All rights reserved.
//
#import "IPDFToolbarHelper.h"
#import <UIKit/NSToolbar+UIKitAdditions.h>
@class NSSearchField_Catalyst;
@protocol NSSearchFieldDelegate_Catalyst
@optional
- (void)searchFieldDidStartSearching:(NSSearchField_Catalyst *)sender;
- (void)searchFieldDidEndSearching:(NSSearchField_Catalyst *)sender;
@required
- (void)controlTextDidChange:(NSNotification *)notification;
@end
@interface NSUIWindow_Catalyst : NSObject
- (void)makeFirstResponder:(id)obj;
@end
@interface NSSearchField_Catalyst : NSObject
@property(weak) id<NSSearchFieldDelegate_Catalyst> delegate;
@property (nonatomic,readwrite) NSString *stringValue;
@end
@interface NSToolbarItem_Catalyst () <NSSearchFieldDelegate_Catalyst>
@property (nonatomic,copy) void(^textDidChangeHandler)(NSString *stringValue);
@property id image;
@property id imageStore;
@end
@implementation NSToolbarItem_Catalyst
@dynamic view;
@dynamic minSize;
@dynamic maxSize;
@dynamic image;
+ (instancetype)searchItemWithItemIdentifier:(NSString *)itemIdentifier textDidChangeHandler:(void(^)(NSString *stringValue))textDidChangeHandler
{
NSToolbarItem_Catalyst *toolbarItem = [[[self class] alloc] initWithItemIdentifier:itemIdentifier];
NSSearchField_Catalyst *searchField = [NSClassFromString(@"NSSearchField") new];
searchField.delegate = toolbarItem;
toolbarItem.view = searchField;
toolbarItem.maxSize = CGSizeMake(240, 44);
toolbarItem.textDidChangeHandler = textDidChangeHandler;
toolbarItem.paletteLabel = @"Search";
return toolbarItem;
}
- (void)controlTextDidChange:(NSNotification *)notification
{
NSSearchField_Catalyst *searchField = notification.object;
if (self.textDidChangeHandler) self.textDidChangeHandler(searchField.stringValue);
}
- (void)setSearchFieldStringValue:(NSString *)searchFieldStringValue
{
if (![self.view isKindOfClass:NSClassFromString(@"NSSearchField")]) return;
NSSearchField_Catalyst *searchField = self.view;
searchField.stringValue = searchFieldStringValue;
}
- (NSString *)searchFieldStringValue
{
if (![self.view isKindOfClass:NSClassFromString(@"NSSearchField")]) return @"";
NSSearchField_Catalyst *searchField = self.view;
return searchField.stringValue;
}
- (void)searchItemBecomeFirstResponder
{
[[self.view window] performSelector:@selector(makeFirstResponder:) withObject:self.view];
}
@end
@implementation NSToolbar_Catalyst
@dynamic sizeMode;
@end
@implementation IPDFToolbarHelper
@end