Enabling back/forward buttons only if appropriate.

svn path=/trunk/netsurf/; revision=11494
This commit is contained in:
Sven Weidauer 2011-01-26 13:35:07 +00:00
parent 7b2694e9f6
commit da01624374
6 changed files with 84 additions and 22 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -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>
@ -1021,10 +1029,6 @@
<string key="name">reloadPage:</string>
<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>
@ -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>
@ -1105,6 +1112,10 @@
<string key="name">activeBrowserController</string>
<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>
@ -1145,13 +1156,6 @@
<string key="minorKey">PSMTabBarControl/PSMTabBarControl.h</string>
</object>
</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"/>