From da01624374ea884fffb15d10a295ded84c6619af Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Wed, 26 Jan 2011 13:35:07 +0000 Subject: [PATCH] Enabling back/forward buttons only if appropriate. svn path=/trunk/netsurf/; revision=11494 --- cocoa/BrowserViewController.h | 7 ++++++ cocoa/BrowserViewController.m | 15 +++++++++++ cocoa/BrowserWindowController.h | 7 +++++- cocoa/BrowserWindowController.m | 29 ++++++++++++++++++++++ cocoa/gui.m | 4 ++- cocoa/res/BrowserWindow.xib | 44 ++++++++++++++++++--------------- 6 files changed, 84 insertions(+), 22 deletions(-) diff --git a/cocoa/BrowserViewController.h b/cocoa/BrowserViewController.h index 4ddfb7f76..1e817a4dd 100644 --- a/cocoa/BrowserViewController.h +++ b/cocoa/BrowserViewController.h @@ -32,6 +32,8 @@ struct browser_window; NSString *status; BOOL isProcessing; NSImage *favicon; + BOOL canGoBack; + BOOL canGoForward; } @property (readwrite, assign, nonatomic) struct browser_window *browser; @@ -42,9 +44,14 @@ struct browser_window; @property (readwrite, copy, nonatomic) NSString *status; @property (readwrite, assign, nonatomic) BOOL isProcessing; @property (readwrite, copy, nonatomic) NSImage *favicon; +@property (readwrite, assign, nonatomic) BOOL canGoBack; +@property (readwrite, assign, nonatomic) BOOL canGoForward; - initWithBrowser: (struct browser_window *) bw; +- (void) contentUpdated; +- (void) updateBackForward; + - (IBAction) navigate: (id) sender; - (IBAction) backForwardSelected: (id) sender; diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m index 3d35f8f0a..0afe4b2f7 100644 --- a/cocoa/BrowserViewController.m +++ b/cocoa/BrowserViewController.m @@ -38,6 +38,8 @@ @synthesize status; @synthesize isProcessing; @synthesize favicon; +@synthesize canGoBack; +@synthesize canGoForward; - (void) dealloc; { @@ -95,6 +97,7 @@ { if (browser && history_back_available( browser->history )) { history_back(browser, browser->history); + [self updateBackForward]; } } @@ -102,6 +105,7 @@ { if (browser && history_forward_available( browser->history )) { history_forward(browser, browser->history); + [self updateBackForward]; } } @@ -152,4 +156,15 @@ static inline bool compare_float( float a, float b ) } +- (void) updateBackForward; +{ + [self setCanGoBack: browser != NULL && history_back_available( browser->history )]; + [self setCanGoForward: browser != NULL && history_forward_available( browser->history )]; +} + +- (void) contentUpdated; +{ + [browserView setHistoryVisible: NO]; +} + @end diff --git a/cocoa/BrowserWindowController.h b/cocoa/BrowserWindowController.h index 333a50429..96157e71f 100644 --- a/cocoa/BrowserWindowController.h +++ b/cocoa/BrowserWindowController.h @@ -27,7 +27,8 @@ NSTabView *tabView; URLFieldCell *urlField; NSObjectController *activeBrowserController; - + NSSegmentedControl *navigationControl; + BrowserViewController *activeBrowser; } @@ -35,9 +36,13 @@ @property (readwrite, retain, nonatomic) IBOutlet NSTabView *tabView; @property (readwrite, retain, nonatomic) IBOutlet URLFieldCell *urlField; @property (readwrite, retain, nonatomic) IBOutlet NSObjectController *activeBrowserController; +@property (readwrite, retain, nonatomic) IBOutlet NSSegmentedControl *navigationControl; @property (readwrite, assign, nonatomic) BrowserViewController *activeBrowser; +@property (readwrite, assign, nonatomic) BOOL canGoBack; +@property (readwrite, assign, nonatomic) BOOL canGoForward; + - (IBAction) newTab: (id) sender; - (void) addTab: (BrowserViewController *)browser; diff --git a/cocoa/BrowserWindowController.m b/cocoa/BrowserWindowController.m index 019807513..21e787b03 100644 --- a/cocoa/BrowserWindowController.m +++ b/cocoa/BrowserWindowController.m @@ -30,6 +30,7 @@ @synthesize tabBar; @synthesize tabView; @synthesize urlField; +@synthesize navigationControl; @synthesize activeBrowser; @synthesize activeBrowserController; @@ -46,6 +47,7 @@ [self setTabBar: nil]; [self setTabView: nil]; [self setUrlField: nil]; + [self setNavigationControl: nil]; [super dealloc]; } @@ -64,6 +66,13 @@ [urlField setRefreshAction: @selector(reloadPage:)]; [urlField bind: @"favicon" toObject: activeBrowserController withKeyPath: @"selection.favicon" options: nil]; + + [self bind: @"canGoBack" + toObject: activeBrowserController withKeyPath: @"selection.canGoBack" + options: nil]; + [self bind: @"canGoForward" + toObject: activeBrowserController withKeyPath: @"selection.canGoForward" + options: nil]; } - (void) addTab: (BrowserViewController *)browser; @@ -110,6 +119,26 @@ extern NSString * const kHomepageURL; [self setNextResponder: activeBrowser]; } +- (void) setCanGoBack: (BOOL)can; +{ + [navigationControl setEnabled: can forSegment: 0]; +} + +- (BOOL) canGoBack; +{ + return [navigationControl isEnabledForSegment: 0]; +} + +- (void) setCanGoForward: (BOOL)can; +{ + [navigationControl setEnabled: can forSegment: 1]; +} + +- (BOOL) canGoForward; +{ + return [navigationControl isEnabledForSegment: 1]; +} + #pragma mark - #pragma mark Tab bar delegate diff --git a/cocoa/gui.m b/cocoa/gui.m index 4797bafd5..6f2ce5d74 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -229,11 +229,13 @@ void gui_window_set_url(struct gui_window *g, const char *url) void gui_window_start_throbber(struct gui_window *g) { [(BrowserViewController *)g setIsProcessing: YES]; + [(BrowserViewController *)g updateBackForward]; } void gui_window_stop_throbber(struct gui_window *g) { [(BrowserViewController *)g setIsProcessing: NO]; + [(BrowserViewController *)g updateBackForward]; } void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) @@ -274,7 +276,7 @@ void gui_window_remove_caret(struct gui_window *g) void gui_window_new_content(struct gui_window *g) { - [[(BrowserViewController *)g browserView] setHistoryVisible: NO]; + [(BrowserViewController *)g contentUpdated]; } bool gui_window_scroll_start(struct gui_window *g) diff --git a/cocoa/res/BrowserWindow.xib b/cocoa/res/BrowserWindow.xib index 2af21b77b..7ed0124cb 100644 --- a/cocoa/res/BrowserWindow.xib +++ b/cocoa/res/BrowserWindow.xib @@ -12,7 +12,7 @@ YES - + YES @@ -78,9 +78,10 @@ History - + 268 {{8, 14}, {30, 25}} + YES 67239424 @@ -123,9 +124,10 @@ Back/Forward - + 268 {{5, 14}, {71, 25}} + YES 67239424 @@ -184,9 +186,10 @@ URL - + 268 {{0, 14}, {96, 22}} + YES -1804468671 @@ -646,6 +649,14 @@ 80 + + + navigationControl + + + + 81 + @@ -906,7 +917,7 @@ P4AAAL+AAABDiwAAxAVAAA - {{422, 872}, {616, 0}} + {{355, 703}, {616, 169}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -939,7 +950,7 @@ - 80 + 81 @@ -964,7 +975,6 @@ goForward: navigate: reloadPage: - showHistory: stopLoading: zoomIn: zoomOriginal: @@ -981,7 +991,6 @@ id id id - id @@ -993,7 +1002,6 @@ goForward: navigate: reloadPage: - showHistory: stopLoading: zoomIn: zoomOriginal: @@ -1021,10 +1029,6 @@ reloadPage: id - - showHistory: - id - stopLoading: id @@ -1078,6 +1082,7 @@ YES activeBrowserController + navigationControl tabBar tabView urlField @@ -1085,6 +1090,7 @@ YES NSObjectController + NSSegmentedControl PSMTabBarControl NSTabView URLFieldCell @@ -1095,6 +1101,7 @@ YES activeBrowserController + navigationControl tabBar tabView urlField @@ -1105,6 +1112,10 @@ activeBrowserController NSObjectController + + navigationControl + NSSegmentedControl + tabBar PSMTabBarControl @@ -1145,13 +1156,6 @@ PSMTabBarControl/PSMTabBarControl.h - - PSMTabBarControl - - IBProjectSource - PSMTabBarControl/PSMProgressIndicator.h - - PSMTabBarControl