Fix bug 235254 and bug 188657: when showing the Find dialog, always select the text, and update the Find dialog from the find pasteboard when it becomes the key window, and when the app is activated. However, we don't clobber the existing text field value if the pasteboard string didn't change. r=pink

This commit is contained in:
sfraser%netscape.com 2004-02-24 05:45:32 +00:00
parent ed2afb145b
commit 329074f546
3 changed files with 57 additions and 30 deletions

View File

@ -1305,6 +1305,11 @@ const int kReuseWindowOnAE = 2;
[NSApp makeWindowsPerform:@selector(display) inOrder:YES];
}
- (void)applicationDidBecomeActive:(NSNotification *)aNotification
{
[mFindDialog applicationWasActivated];
}
- (void) updatePrebinding
{
// For MacOS 10.2 and higher, don't do anything, since

View File

@ -37,20 +37,21 @@
#import <AppKit/AppKit.h>
@interface FindDlgController : NSWindowController {
@interface FindDlgController : NSWindowController
{
IBOutlet NSTextField* mSearchField;
IBOutlet NSButton* mIgnoreCaseBox;
IBOutlet NSButton* mWrapAroundBox;
IBOutlet NSButton* mFindNextButton;
IBOutlet NSButton* mFindPrevButton;
NSString* mLastFindString;
}
- (IBAction) findNextButton: (id)aSender;
- (IBAction) findPreviousButton: (id)aSender;
- (IBAction) findNextAndOrderOut: (id)aSender;
// delegates for NSTextView
- (void)controlTextDidChange:(NSNotification *)aNotification;
- (void)loadFindStringFromPasteboard;
- (void)putFindStringOnPasteboard;
- (void)applicationWasActivated;
@end

View File

@ -39,22 +39,36 @@
#import "Find.h"
@interface FindDlgController(Private)
- (NSString*)getSearchText;
- (void)loadNewFindStringFromPasteboard;
- (void)putFindStringOnPasteboard;
- (NSString*)getSearchText:(BOOL*)outIsNew;
- (BOOL)find:(BOOL)searchBack;
@end
@implementation FindDlgController
- (void)loadFindStringFromPasteboard
- (void)dealloc
{
NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
if ([[pasteboard types] containsObject:NSStringPboardType]) {
NSString *string = [pasteboard stringForType:NSStringPboardType];
if (string && [string length]) {
[mSearchField setStringValue: string];
[mFindNextButton setEnabled:YES];
[mFindPrevButton setEnabled:YES];
}
[mLastFindString release];
[super dealloc];
}
- (void)loadNewFindStringFromPasteboard
{
BOOL pasteboardChanged;
NSString* curPasteboard = [self getSearchText:&pasteboardChanged];
if (pasteboardChanged)
[mSearchField setStringValue:curPasteboard];
[mSearchField selectText:nil];
if ([[mSearchField stringValue] length] > 0)
{
[mFindNextButton setEnabled:YES];
[mFindPrevButton setEnabled:YES];
}
}
@ -63,6 +77,9 @@
NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pasteboard setString:[mSearchField stringValue] forType:NSStringPboardType];
[mLastFindString release];
mLastFindString = [[NSString stringWithString:[mSearchField stringValue]] retain];
}
//
@ -130,30 +147,34 @@
//
// Retrieve the most recent search string
//
- (NSString*)getSearchText
- (NSString*)getSearchText:(BOOL*)outIsNew
{
NSString* searchText;
NSPasteboard *findPboard = [NSPasteboard pasteboardWithName:NSFindPboard];
if ([[findPboard types] indexOfObject:NSStringPboardType] != NSNotFound)
return [findPboard stringForType:NSStringPboardType];
return [NSString string];
searchText = [findPboard stringForType:NSStringPboardType];
else
searchText = [NSString string];
if (outIsNew)
*outIsNew = mLastFindString && ![mLastFindString isEqualToString:searchText];
// remember the last pasteboard string that we saw
[mLastFindString release];
mLastFindString = [[NSString stringWithString:searchText] retain];
return searchText;
}
//
// -showWindow:
//
// override to set the current search text in the text area before showing
// the window
//
- (IBAction)showWindow:(id)sender
- (void)windowDidBecomeKey:(NSNotification *)notification
{
[mSearchField setStringValue:[self getSearchText]];
[super showWindow:sender];
[self loadNewFindStringFromPasteboard];
}
-(void)windowDidLoad
- (void)applicationWasActivated
{
[mSearchField setStringValue:[self getSearchText]];
[self loadNewFindStringFromPasteboard];
}
@end