Hook up button icon preferences, begin implementing the setting

This commit is contained in:
anthony 2021-04-07 20:59:38 +01:00
parent a1e2dd5be2
commit 3f181a1a84
9 changed files with 53 additions and 1 deletions

View File

@ -66,6 +66,7 @@ static id newTabTarget;
-(Website*)currentWebsiteForTab: (id)tab;
-(void)updateTabsVisibility;
-(void)onPreferencesUpdated: (id)sender;
-(void)reconfigureUrlBarButtons;
@end
@implementation BrowserWindowController
@ -533,11 +534,28 @@ static id newTabTarget;
currentTabLocation = location;
}
-(void)reconfigureUrlBarButtons {
NSLog(@"reconfigure url bar buttons");
UrlBarButtonType buttonType = [[Preferences defaultPreferences] urlBarButtonType];
NSLog(@"type: %d", buttonType);
switch (buttonType) {
case UrlBarButtonTypeImage:
[backButton setImage: [NSImage imageNamed: @"back"]];
break;
case UrlBarButtonTypeText:
break;
default:
break;
}
}
-(void)onPreferencesUpdated: (id)sender {
id dict = [sender object];
PreferenceType type = (PreferenceType)[[dict objectForKey: @"type"] integerValue];
if (type == PreferenceTypeAlwaysShowTabs || type == PreferenceTypeTabLocation) {
[self updateTabsVisibility];
} else if (type == PreferenceTypeUrlBarButtonType) {
[self reconfigureUrlBarButtons];
}
}

View File

@ -102,6 +102,10 @@ E_RESOURCES := \
internal.css \
quirks.css \
SearchEngines \
forward.png \
back.png \
refresh.png \
search.png \
E_RESOURCES := $(addprefix resources/,$(E_RESOURCES))

View File

@ -15,12 +15,18 @@ typedef NS_ENUM(NSInteger, TabLocation) {
TabLocationNone
};
typedef NS_ENUM(NSInteger, UrlBarButtonType) {
UrlBarButtonTypeText = 0,
UrlBarButtonTypeImage
};
// Certain preferences will notify that they have been updated using this key.
#define PreferencesUpdatedNotificationName @"PreferencesUpdatedNotification"
typedef NS_ENUM(NSInteger, PreferenceType) {
PreferenceTypeAlwaysShowTabs = 0,
PreferenceTypeTabLocation,
PreferenceTypeShowUrlSuggestions
PreferenceTypeShowUrlSuggestions,
PreferenceTypeUrlBarButtonType
};
@interface Preferences: NSObject {
@ -63,5 +69,8 @@ typedef NS_ENUM(NSInteger, PreferenceType) {
-(BOOL)showUrlSuggestions;
-(void)setShowUrlSuggestions: (BOOL)value;
-(UrlBarButtonType)urlBarButtonType;
-(void)setUrlBarButtonType: (UrlBarButtonType)buttonType;
+(Preferences*)defaultPreferences;
@end

View File

@ -14,6 +14,7 @@
#define KEY_TAB_LOCATION @"tab_location"
#define KEY_DEVELOPER_VIEW_LOCATION @"developer_view_location"
#define KEY_SHOW_URL_SUGGESTIONS @"show_url_suggestions"
#define KEY_URL_BAR_BUTTON_TYPE @"url_bar_button_type"
@interface Preferences (Private)
@ -186,6 +187,21 @@
[self notifyPreferenceUpdated: PreferenceTypeShowUrlSuggestions];
}
-(UrlBarButtonType)urlBarButtonType {
if ([defaults objectForKey: KEY_URL_BAR_BUTTON_TYPE] != nil) {
return (UrlBarButtonType)[defaults integerForKey:
KEY_URL_BAR_BUTTON_TYPE];
} else {
return UrlBarButtonTypeText;
}
}
-(void)setUrlBarButtonType: (UrlBarButtonType)buttonType {
[defaults setInteger: (NSInteger)buttonType forKey:
KEY_URL_BAR_BUTTON_TYPE];
[self notifyPreferenceUpdated: PreferenceTypeUrlBarButtonType];
}
+(Preferences*)defaultPreferences {
static Preferences *prefs;
if (prefs == nil) {

View File

@ -211,6 +211,8 @@
[developerViewsButton selectItemAtIndex: (NSInteger)viewLocation];
[urlSuggestionsButton setState: [[Preferences defaultPreferences] showUrlSuggestions]
? NSOnState : NSOffState];
UrlBarButtonType buttonType = [[Preferences defaultPreferences] urlBarButtonType];
[urlBarButtonsTypeButton selectItemAtIndex: (NSInteger)buttonType];
}
-(void)didPickDeveloperViews: (id)sender {
@ -251,6 +253,9 @@
-(void)didPickUrlButtonsType: (id)sender {
NSLog(@"didPickUrlButtonsType");
UrlBarButtonType buttonType = (UrlBarButtonType)[sender indexOfItem: [sender
selectedItem]];
[[Preferences defaultPreferences] setUrlBarButtonType: buttonType];
}
@end

BIN
resources/back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

BIN
resources/forward.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

BIN
resources/refresh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 B

BIN
resources/search.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B