-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyApplication.m
175 lines (142 loc) · 4.43 KB
/
MyApplication.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Copyright (C) 2012 Alasdair Morrison <[email protected]>
* This file is part of ProductivePDF.
* ProductivePDF is free software and comes with ABSOLUTELY NO WARRANTY.
* See LICENSE for details.
*/
#import "MyApplication.h"
#import "MyWindowController.h"
@implementation MyApplication
// ======================================================================================================== MyApplication
// ---------------------------------------------------------------------------------------------------------- findOptions
- (int) findOptions
{
int options = 0;
if ([_ignoreCaseCheckbox intValue])
options = options | NSCaseInsensitiveSearch;
return options;
}
// ------------------------------------------------------------------------------------------------------------- findNext
- (void) findNext: (id) sender
{
MyWindowController *controller;
PDFView *theView;
PDFSelection *selection;
controller = [[self mainWindow] windowController];
if (controller == NULL)
return;
theView = [controller pdfView];
selection = [[theView document] findString: [_findPanelSearchField stringValue] fromSelection:
[theView currentSelection] withOptions: [self findOptions]];
if (selection)
{
[theView setCurrentSelection: selection];
[theView scrollSelectionToVisible: self];
}
else
{
NSBeep();
}
}
// ----------------------------------------------------------------------------------------- findNextAndOrderOutFindPanel
- (void) findNextAndOrderOutFindPanel: (id) sender
{
[self findNext: sender];
[_findPanel orderOut: self];
}
// --------------------------------------------------------------------------------------------------------- findPrevious
- (void) findPrevious: (id) sender
{
MyWindowController *controller;
PDFView *theView;
PDFSelection *selection;
controller = [[self mainWindow] windowController];
if (controller == NULL)
return;
theView = [controller pdfView];
selection = [[theView document] findString: [_findPanelSearchField stringValue] fromSelection:
[theView currentSelection] withOptions: [self findOptions] | NSBackwardsSearch];
if (selection)
{
[theView setCurrentSelection: selection];
[theView scrollSelectionToVisible: self];
}
else
{
NSBeep();
}
}
// ----------------------------------------------------------------------------------------------- performFindPanelAction
- (void) performFindPanelAction: (id) sender
{
MyWindowController *controller;
PDFView *theView;
PDFSelection *selection;
NSPasteboard *findPasteboard;
switch ([sender tag])
{
case NSFindPanelActionShowFindPanel:
[_findPanel makeKeyAndOrderFront: self];
break;
// Select next row.
case NSFindPanelActionNext:
[self findNext: sender];
break;
case NSFindPanelActionPrevious:
[self findPrevious: sender];
break;
case NSFindPanelActionReplaceAll:
case NSFindPanelActionReplace:
case NSFindPanelActionReplaceAndFind:
case NSFindPanelActionReplaceAllInSelection:
NSBeep();
break;
// Get selected text.
case NSFindPanelActionSetFindString:
controller = [[self mainWindow] windowController];
if (controller)
{
theView = [controller pdfView];
selection = [theView currentSelection];
if (selection == NULL)
break;
}
// Load up on find pasteboard.
findPasteboard = [NSPasteboard pasteboardWithName: NSFindPboard];
[findPasteboard declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: NULL];
[findPasteboard setString: [selection string] forType: NSStringPboardType];
// Select it.
[_findPanelSearchField setStringValue: [selection string]];
break;
case NSFindPanelActionSelectAll:
case NSFindPanelActionSelectAllInSelection:
NSBeep();
break;
}
}
// ----------------------------------------------------------------------------------------------------- validateMenuItem
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
{
BOOL enable = YES;
if ([menuItem action] == @selector(performFindPanelAction:))
{
if ([menuItem tag] != NSFindPanelActionSetFindString)
{
NSWindowController *controller;
// Do we have a window controller (document open)?
controller = [[self mainWindow] windowController];
// No document: no find, otherwise see that there is text worth searching.
if (controller == NULL)
{
enable = NO;
}
else
{
if ([menuItem tag] != NSFindPanelActionShowFindPanel)
enable = ([[_findPanelSearchField stringValue] length] > 0);
}
}
}
return enable;
}
@end