diff options
author | Sven Weidauer <sven.weidauer@gmail.com> | 2011-01-26 13:35:07 +0000 |
---|---|---|
committer | Sven Weidauer <sven.weidauer@gmail.com> | 2011-01-26 13:35:07 +0000 |
commit | da01624374ea884fffb15d10a295ded84c6619af (patch) | |
tree | 4686c7d2ba11f2f0a34c814d10d8072078366165 /cocoa | |
parent | 7b2694e9f6c35d9f50c3fb3cf38b0fc766478162 (diff) | |
download | netsurf-da01624374ea884fffb15d10a295ded84c6619af.tar.gz netsurf-da01624374ea884fffb15d10a295ded84c6619af.tar.bz2 |
Enabling back/forward buttons only if appropriate.
svn path=/trunk/netsurf/; revision=11494
Diffstat (limited to 'cocoa')
-rw-r--r-- | cocoa/BrowserViewController.h | 7 | ||||
-rw-r--r-- | cocoa/BrowserViewController.m | 15 | ||||
-rw-r--r-- | cocoa/BrowserWindowController.h | 7 | ||||
-rw-r--r-- | cocoa/BrowserWindowController.m | 29 | ||||
-rw-r--r-- | cocoa/gui.m | 4 | ||||
-rw-r--r-- | 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 @@ </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="1"/> + <integer value="73"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -78,9 +78,10 @@ <string key="NSToolbarItemPaletteLabel">History</string> <nil key="NSToolbarItemToolTip"/> <object class="NSButton" key="NSToolbarItemView" id="229385913"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">268</int> <string key="NSFrame">{{8, 14}, {30, 25}}</string> + <reference key="NSSuperview"/> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="296571644"> <int key="NSCellFlags">67239424</int> @@ -123,9 +124,10 @@ <string key="NSToolbarItemPaletteLabel">Back/Forward</string> <nil key="NSToolbarItemToolTip"/> <object class="NSSegmentedControl" key="NSToolbarItemView" id="692457026"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">268</int> <string key="NSFrame">{{5, 14}, {71, 25}}</string> + <reference key="NSSuperview"/> <bool key="NSEnabled">YES</bool> <object class="NSSegmentedCell" key="NSCell" id="845979064"> <int key="NSCellFlags">67239424</int> @@ -184,9 +186,10 @@ <string key="NSToolbarItemPaletteLabel">URL</string> <nil key="NSToolbarItemToolTip"/> <object class="NSTextField" key="NSToolbarItemView" id="77748234"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">268</int> <string key="NSFrame">{{0, 14}, {96, 22}}</string> + <reference key="NSSuperview"/> <bool key="NSEnabled">YES</bool> <object class="NSTextFieldCell" key="NSCell" id="1053649244"> <int key="NSCellFlags">-1804468671</int> @@ -646,6 +649,14 @@ </object> <int key="connectionID">80</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">navigationControl</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="692457026"/> + </object> + <int key="connectionID">81</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -906,7 +917,7 @@ <object class="NSAffineTransform"> <bytes key="NSTransformStruct">P4AAAL+AAABDiwAAxAVAAA</bytes> </object> - <string>{{422, 872}, {616, 0}}</string> + <string>{{355, 703}, {616, 169}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -939,7 +950,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">80</int> + <int key="maxID">81</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -964,7 +975,6 @@ <string>goForward:</string> <string>navigate:</string> <string>reloadPage:</string> - <string>showHistory:</string> <string>stopLoading:</string> <string>zoomIn:</string> <string>zoomOriginal:</string> @@ -981,7 +991,6 @@ <string>id</string> <string>id</string> <string>id</string> - <string>id</string> </object> </object> <object class="NSMutableDictionary" key="actionInfosByName"> @@ -993,7 +1002,6 @@ <string>goForward:</string> <string>navigate:</string> <string>reloadPage:</string> - <string>showHistory:</string> <string>stopLoading:</string> <string>zoomIn:</string> <string>zoomOriginal:</string> @@ -1022,10 +1030,6 @@ <string key="candidateClassName">id</string> </object> <object class="IBActionInfo"> - <string key="name">showHistory:</string> - <string key="candidateClassName">id</string> - </object> - <object class="IBActionInfo"> <string key="name">stopLoading:</string> <string key="candidateClassName">id</string> </object> @@ -1078,6 +1082,7 @@ <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>activeBrowserController</string> + <string>navigationControl</string> <string>tabBar</string> <string>tabView</string> <string>urlField</string> @@ -1085,6 +1090,7 @@ <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSObjectController</string> + <string>NSSegmentedControl</string> <string>PSMTabBarControl</string> <string>NSTabView</string> <string>URLFieldCell</string> @@ -1095,6 +1101,7 @@ <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>activeBrowserController</string> + <string>navigationControl</string> <string>tabBar</string> <string>tabView</string> <string>urlField</string> @@ -1106,6 +1113,10 @@ <string key="candidateClassName">NSObjectController</string> </object> <object class="IBToOneOutletInfo"> + <string key="name">navigationControl</string> + <string key="candidateClassName">NSSegmentedControl</string> + </object> + <object class="IBToOneOutletInfo"> <string key="name">tabBar</string> <string key="candidateClassName">PSMTabBarControl</string> </object> @@ -1147,13 +1158,6 @@ </object> <object class="IBPartialClassDescription"> <string key="className">PSMTabBarControl</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> - <string key="minorKey">PSMTabBarControl/PSMProgressIndicator.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> - <string key="className">PSMTabBarControl</string> <reference key="sourceIdentifier" ref="472370996"/> </object> <object class="IBPartialClassDescription"> |