Respect the 'always show tabs' preference
This commit is contained in:
parent
dfbf82f0bf
commit
46cd4697a4
|
@ -15,6 +15,10 @@
|
|||
#import "SearchProvider.h"
|
||||
|
||||
#define TAB_TITLE_LEN 20
|
||||
// Everything above the browser. Used to calculate the tabview's height.
|
||||
#define TOP_CONTENT_HEIGHT 74
|
||||
// Any way to get this programatically?
|
||||
#define TAB_ITEM_HEIGHT 13
|
||||
|
||||
static id newTabTarget;
|
||||
|
||||
|
@ -52,10 +56,11 @@ static id newTabTarget;
|
|||
@interface BrowserWindowController (Private)
|
||||
-(void)openUrlString: (NSString*)aUrlString;
|
||||
-(id)addTab: (struct browser_window*)aBrowser;
|
||||
-(void)removeTab: (struct browser_window*)aBrowser;
|
||||
-(void)reconfigureTabLayout;
|
||||
-(void)setActive: (TabContents*)tabContents;
|
||||
-(Website*)currentWebsiteForTab: (id)tab;
|
||||
-(void)updateTabsVisibility;
|
||||
-(void)onPreferencesUpdated: (id)sender;
|
||||
@end
|
||||
|
||||
@implementation BrowserWindowController
|
||||
|
@ -78,6 +83,10 @@ static id newTabTarget;
|
|||
-(void)awakeFromNib {
|
||||
[tabView removeTabViewItem: [tabView tabViewItemAtIndex: 0]];
|
||||
[self addTab: browser];
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||
selector: @selector(onPreferencesUpdated:)
|
||||
name: PreferencesUpdatedNotificationName
|
||||
object: nil];
|
||||
NSLog(@"Browser window loaded");
|
||||
}
|
||||
|
||||
|
@ -115,6 +124,7 @@ static id newTabTarget;
|
|||
for (NSUInteger i = 0; i < [tabs count]; i++) {
|
||||
browser_window_destroy([[tabs objectAtIndex: i] browser]);
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
}
|
||||
|
||||
-(void)close: (id)sender {
|
||||
|
@ -145,6 +155,8 @@ static id newTabTarget;
|
|||
[tabs removeObjectAtIndex: idx];
|
||||
if ([tabs count] < 1) {
|
||||
[super close];
|
||||
} else {
|
||||
[self updateTabsVisibility];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,13 +387,15 @@ static id newTabTarget;
|
|||
[tc release];
|
||||
[newPlotView release];
|
||||
[newScrollView release];
|
||||
@try {
|
||||
[self updateTabsVisibility];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
NSLog(@"%@", e);
|
||||
}
|
||||
return tc;
|
||||
}
|
||||
|
||||
-(void)removeTab: (struct browser_window*)aBrowser {
|
||||
|
||||
}
|
||||
|
||||
-(void)reconfigureTabLayout {
|
||||
|
||||
}
|
||||
|
@ -409,6 +423,29 @@ static id newTabTarget;
|
|||
return [website autorelease];
|
||||
}
|
||||
|
||||
-(void)updateTabsVisibility {
|
||||
BOOL hideTabs = [tabs count] < 2 && ![[Preferences defaultPreferences]
|
||||
alwaysShowTabs];
|
||||
NSRect rect = [tabView frame];
|
||||
rect.size.height = [[self window] frame].size.height - TOP_CONTENT_HEIGHT;
|
||||
if (hideTabs) {
|
||||
[tabView setTabViewType: NSNoTabsNoBorder];
|
||||
} else {
|
||||
[tabView setTabViewType: NSTopTabsBezelBorder];
|
||||
}
|
||||
[tabView setFrame: rect];
|
||||
// Work around a graphical glitch where the tab view doesn't properly readjust itself
|
||||
[tabView selectTabViewItem: [activeTab tabItem]];
|
||||
}
|
||||
|
||||
-(void)onPreferencesUpdated: (id)sender {
|
||||
id dict = [sender object];
|
||||
PreferenceType type = (PreferenceType)[[dict objectForKey: @"type"] integerValue];
|
||||
if (type == PreferenceTypeAlwaysShowTabs) {
|
||||
[self updateTabsVisibility];
|
||||
}
|
||||
}
|
||||
|
||||
+(id)newTabTarget {
|
||||
return newTabTarget;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,12 @@ typedef NS_ENUM(NSInteger, TabLocation) {
|
|||
TabLocationLeft
|
||||
};
|
||||
|
||||
// Certain preferences will notify that they have been updated using this key.
|
||||
#define PreferencesUpdatedNotificationName @"PreferencesUpdatedNotification"
|
||||
typedef NS_ENUM(NSInteger, PreferenceType) {
|
||||
PreferenceTypeAlwaysShowTabs = 0
|
||||
};
|
||||
|
||||
@interface Preferences: NSObject {
|
||||
NSUserDefaults *defaults;
|
||||
}
|
||||
|
@ -36,7 +42,9 @@ typedef NS_ENUM(NSInteger, TabLocation) {
|
|||
-(NSString*)downloadLocationPath;
|
||||
-(void)setDownloadLocationPath: (NSString*)aPath;
|
||||
|
||||
-(BOOL)alwaysShowTabs;
|
||||
-(void)setAlwaysShowTabs: (BOOL)value;
|
||||
|
||||
|
||||
+(Preferences*)defaultPreferences;
|
||||
@end
|
||||
@end
|
||||
|
|
|
@ -9,6 +9,14 @@
|
|||
#define KEY_CONFIRM_OVERWRITE @"confirm_overwrite"
|
||||
#define KEY_DOWNLOAD_LOCATION @"download_location"
|
||||
|
||||
#define KEY_ALWAYS_SHOW_TABS @"always_show_tabs"
|
||||
|
||||
@interface Preferences (Private)
|
||||
|
||||
-(void)notifyPreferenceUpdated: (PreferenceType)type;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Preferences
|
||||
|
||||
-(id)init {
|
||||
|
@ -96,6 +104,20 @@
|
|||
[defaults setObject: aPath forKey: KEY_DOWNLOAD_LOCATION];
|
||||
}
|
||||
|
||||
-(BOOL)alwaysShowTabs {
|
||||
if ([defaults objectForKey: KEY_ALWAYS_SHOW_TABS] != nil) {
|
||||
return [defaults boolForKey: KEY_ALWAYS_SHOW_TABS];
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setAlwaysShowTabs: (BOOL)value {
|
||||
[defaults setBool: value forKey: KEY_ALWAYS_SHOW_TABS];
|
||||
[self notifyPreferenceUpdated: PreferenceTypeAlwaysShowTabs];
|
||||
}
|
||||
|
||||
|
||||
+(Preferences*)defaultPreferences {
|
||||
static Preferences *prefs;
|
||||
if (prefs == nil) {
|
||||
|
@ -103,4 +125,13 @@
|
|||
}
|
||||
return prefs;
|
||||
}
|
||||
@end
|
||||
|
||||
-(void)notifyPreferenceUpdated: (PreferenceType)type {
|
||||
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInteger: type], @"type",
|
||||
nil
|
||||
];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
PreferencesUpdatedNotificationName object: dict];
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
id searchProviderButton;
|
||||
id startupPageField;
|
||||
// APPEARANCE
|
||||
id alwaysShowTabBarButton;
|
||||
id bankNewTabsButton;
|
||||
id developerViewsButton;
|
||||
id urlBarButtonsTypeButton;
|
||||
id switchToTabsButton;
|
||||
id tabPositionButton;
|
||||
id urlSuggestionsButton;
|
||||
id alwaysShowTabBarButton;
|
||||
id bankNewTabsButton;
|
||||
id developerViewsButton;
|
||||
id urlBarButtonsTypeButton;
|
||||
id switchToTabsButton;
|
||||
id tabPositionButton;
|
||||
id urlSuggestionsButton;
|
||||
|
||||
NSMutableArray *downloadLocations;
|
||||
}
|
||||
|
|
|
@ -199,7 +199,8 @@
|
|||
|
||||
// MARK: - APPEARANCE TAB
|
||||
-(void)configureAppearanceTab {
|
||||
|
||||
[alwaysShowTabBarButton setState: [[Preferences defaultPreferences] alwaysShowTabs] ?
|
||||
NSOnState : NSOffState];
|
||||
}
|
||||
|
||||
-(void)didPickDeveloperViews: (id)sender {
|
||||
|
@ -212,6 +213,8 @@
|
|||
|
||||
-(void)didPressAlwaysShowTabBar: (id)sender {
|
||||
NSLog(@"didPressAlwaysShowTabBar");
|
||||
BOOL checked = [sender state] == NSOnState;
|
||||
[[Preferences defaultPreferences] setAlwaysShowTabs: checked];
|
||||
}
|
||||
|
||||
-(void)didPressBlankNewTabs: (id)sender {
|
||||
|
|
Loading…
Reference in New Issue