Hook up find window to search table

This commit is contained in:
anthony 2020-12-14 21:27:23 +00:00
parent adda2aed3c
commit 6886cc5a8f
7 changed files with 43 additions and 19 deletions

View File

@ -37,7 +37,8 @@ struct browser_window;
-(void)stopThrobber;
-(void)setNavigationUrl: (NSString*)urlString;
-(void)setTitle: (NSString*)title;
-(void)findNext: (NSString*)needle matchCase: (BOOL)matchCase;
-(void)findPrevious: (NSString*)needle matchCase: (BOOL)matchCase;
-(void)showAll: (NSString*)needle matchCase: (BOOL)matchCase;
-(void)findNext: (NSString*)needle matchCase: (BOOL)matchCase sender: (id)sender;
-(void)findPrevious: (NSString*)needle matchCase: (BOOL)matchCase sender: (id)sender;
-(void)showAll: (NSString*)needle matchCase: (BOOL)matchCase sender: (id)sender;
@end

View File

@ -139,28 +139,28 @@
[[self window] setTitle: title];
}
-(void)findNext: (NSString*)needle matchCase: (BOOL)matchCase {
-(void)findNext: (NSString*)needle matchCase: (BOOL)matchCase sender: (id)sender {
search_flags_t flags = SEARCH_FLAG_FORWARDS;
if (matchCase) {
flags |= SEARCH_FLAG_CASE_SENSITIVE;
}
browser_window_search(browser, NULL, flags, [needle cString]);
browser_window_search(browser, (void*)sender, flags, [needle cString]);
}
-(void)findPrevious: (NSString*)needle matchCase: (BOOL)matchCase {
-(void)findPrevious: (NSString*)needle matchCase: (BOOL)matchCase sender: (id)sender {
search_flags_t flags = SEARCH_FLAG_BACKWARDS;
if (matchCase) {
flags |= SEARCH_FLAG_CASE_SENSITIVE;
}
browser_window_search(browser, NULL, flags, [needle cString]);
browser_window_search(browser, (void*)sender, flags, [needle cString]);
}
-(void)showAll: (NSString*)needle matchCase: (BOOL)matchCase {
-(void)showAll: (NSString*)needle matchCase: (BOOL)matchCase sender: (id)sender {
search_flags_t flags = SEARCH_FLAG_SHOWALL;
if (matchCase) {
flags |= SEARCH_FLAG_CASE_SENSITIVE;
}
browser_window_search(browser, NULL, flags, [needle cString]);
browser_window_search(browser, (void*)sender, flags, [needle cString]);
}
@end

View File

@ -7,6 +7,7 @@
id searchField;
id showAllButton;
id browserController;
id noResultsLabel;
}
-(void)setBrowserController: (id)aBrowserController;
-(void)findPrevious: (id)sender;
@ -15,4 +16,8 @@
-(void)updateSearch: (id)sender;
-(void)toggleMatchCase: (id)sender;
// Interface for use by search.h table
-(void)setFound: (BOOL)found;
-(void)setCanFindNext: (BOOL)canFindNext;
-(void)setCanFindPrevious: (BOOL)canFindPrevious;
@end

View File

@ -12,6 +12,7 @@
}
-(void)awakeFromNib {
[noResultsLabel setHidden: YES];
[[self window] makeKeyAndOrderFront: self];
[self windowBecameMain: [NSNotification notificationWithName: @""
object: [NSApp mainWindow]]];
@ -42,33 +43,33 @@
-(void)setBrowserController: (id)aBrowserController {
browserController = aBrowserController;
BOOL enabled = browserController != nil;
[previousButton setEnabled: enabled];
[nextButton setEnabled: enabled];
[matchCaseButton setEnabled: enabled];
[showAllButton setEnabled: enabled];
[previousButton setEnabled: NO];
[nextButton setEnabled: NO];
[showAllButton setEnabled: NO];
}
-(void)findPrevious: (id)sender {
[browserController findPrevious: [searchField stringValue]
matchCase: [matchCaseButton state] == NSOnState];
matchCase: [matchCaseButton state] == NSOnState sender: self];
}
-(void)findNext: (id)sender {
[browserController findNext: [searchField stringValue]
matchCase: [matchCaseButton state] == NSOnState];
matchCase: [matchCaseButton state] == NSOnState sender: self];
}
-(void)showAll: (id)sender {
[browserController showAll: [searchField stringValue]
matchCase: [matchCaseButton state] == NSOnState];
matchCase: [matchCaseButton state] == NSOnState sender: self];
}
-(void)updateSearch: (id)sender {
if (browserController != nil) {
[self findNext: sender];
}
}
@ -76,4 +77,17 @@
}
-(void)setFound: (BOOL)found {
[noResultsLabel setHidden: found];
[showAllButton setEnabled: found];
}
-(void)setCanFindNext: (BOOL)canFindNext {
[nextButton setEnabled: canFindNext];
}
-(void)setCanFindPrevious: (BOOL)canFindPrevious {
[previousButton setEnabled: canFindPrevious];
}
@end

View File

@ -13,7 +13,8 @@
nextButton,
matchCaseButton,
searchField,
showAllButton
showAllButton,
noResultsLabel
);
Super = NSWindowController;
};

View File

@ -11,6 +11,7 @@
// Change displayed search status found/notfound?
static void gnustep_search_status(bool found, void *p) {
NSLog(@"gnustep_search_status");
[(id)p setFound: found ? YES : NO];
}
// Show hourglass if active else stop hourglass
@ -26,11 +27,13 @@ static void gnustep_search_add_recent(const char *string, void *p) {
// Set the next match button to active/inactive
static void gnustep_search_forward_state(bool active, void *p) {
NSLog(@"gnustep_search_forward_state");
[(id)p setCanFindNext: active ? YES : NO];
}
// set the previous match button to active/inactive
static void gnustep_search_back_state(bool active, void *p) {
NSLog(@"gnustep_search_back_state");
[(id)p setCanFindPrevious: active ? YES : NO];
}
struct gui_search_table gnustep_search_table = {