1 /* 2 Reusable find panel functionality (find, replace). 3 Need one shared instance of TextFinder to which the menu items and widgets in the find panel are connected. 4 Loads UI lazily. 5 Works on first responder, assumed to be an NSTextView. 6 */ 7 8 #import <Foundation/Foundation.h> 9 #import <AppKit/AppKit.h> 10 11 #define Forward YES 12 #define Backward NO 13 14 @interface TextFinder : NSObject { 15 NSString *findString; 16 id findTextField; 17 id rawButton; 18 id regexButton; 19 id multilineButton; 20 id replaceTextField; 21 id ignoreCaseButton; 22 id findNextButton; 23 id findPrevButton; 24 id replaceAllScopeMatrix; 25 id statusField; 26 IBOutlet id scopeFlag; 27 BOOL lastFindWasSuccessful; 28 } 29 30 /* Common way to get a text finder. One instance of TextFinder per app is good enough. */ 31 + (id)sharedInstance; 32 33 /* Main method for external users; does a find in the first responder. Selects found range or beeps. */ 34 - (BOOL)find:(BOOL)direction; 35 36 /* Loads UI lazily */ 37 - (NSPanel *)findPanel; 38 39 /* Gets the first responder and returns it if it's an NSTextView */ 40 - (NSTextView *)textObjectToSearchIn; 41 42 /* Get/set the current find string. Will update UI if UI is loaded */ 43 - (NSString *)findString; 44 - (void)setFindString:(NSString *)string; 45 - (void)setFindString:(NSString *)string writeToPasteboard:(BOOL)flag; 46 47 /* Misc internal methods */ 48 - (void)appDidActivate:(NSNotification *)notification; 49 - (void)loadFindStringFromPasteboard; 50 - (void)loadFindStringToPasteboard; 51 52 /* Action methods, sent from the find panel UI; can also be connected to menu items */ 53 - (void)findNext:(id)sender; 54 - (void)findPrevious:(id)sender; 55 - (void)findNextAndOrderFindPanelOut:(id)sender; 56 - (void)replace:(id)sender; 57 - (void)replaceAndFind:(id)sender; 58 - (void)replaceAll:(id)sender; 59 - (void)orderFrontFindPanel:(id)sender; 60 - (void)takeFindStringFromSelection:(id)sender; 61 - (void)jumpToSelection:(id)sender; 62 -(NSString *)convertEscapeString: (NSString *) oString; 63 64 @end 65 66