/* The primitive for finding; this ends up setting the status field (and beeping if necessary)...
*/
- (BOOL)find:(BOOL)direction {
NSTextView *text = [self textObjectToSearchIn];
lastFindWasSuccessful = NO;
if (text) {
NSString *textContents = [text string];
unsigned textLength;
if (textContents && (textLength = [textContents length])) {
NSRange range;
unsigned options = 0;
if (direction == Backward) options |= NSBackwardsSearch;
if ([ignoreCaseButton state]) options |= NSCaseInsensitiveSearch;
range = [textContents findString:[self findString] selectedRange:[text selectedRange] options:options wrap:YES];
if (range.length) {
[text setSelectedRange:range];
[text scrollRangeToVisible:range];
lastFindWasSuccessful = YES;
}
}
}
if (!lastFindWasSuccessful) {
NSBeep();
[statusField setStringValue:NSLocalizedStringFromTable(@"Not found", @"FindPanel", @"Status displayed in find panel when the find string is not found.")];
} else {
[statusField setStringValue:@""];
}
return lastFindWasSuccessful;
}
- (void)orderFrontFindPanel:(id)sender {
NSPanel *panel = [self findPanel];
[findTextField selectText:nil];
[panel makeKeyAndOrderFront:nil];
}
/**** Action methods for gadgets in the find panel; these should all end up setting or clearing the status field ****/
- (void)findNextAndOrderFindPanelOut:(id)sender {
[findNextButton performClick:nil];
if (lastFindWasSuccessful) {
[[self findPanel] orderOut:sender];
} else {
[findTextField selectText:nil];
}
}
- (void)findNext:(id)sender {
if (findTextField) [self setFindString:[findTextField stringValue]]; /* findTextField should be set */
(void)[self find:Forward];
}
- (void)findPrevious:(id)sender {
if (findTextField) [self setFindString:[findTextField stringValue]]; /* findTextField should be set */
[statusField setStringValue:NSLocalizedStringFromTable(@"Not found", @"FindPanel", @"Status displayed in find panel when the find string is not found.")];
} else {
[statusField setStringValue:[NSString localizedStringWithFormat:NSLocalizedStringFromTable(@"%d replaced", @"FindPanel", @"Status displayed in find panel when indicated number of matches are replaced."), replaced]];