diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-03 19:13:17 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-03 19:13:17 +0000 |
commit | 2df7c5b5a9c31cdcf2623de4c996170d2af28b98 (patch) | |
tree | 6b7394dcad468eb6008d07ed6069de69af682d29 /chrome/browser/cocoa/preferences_window_controller.mm | |
parent | e65c7713f650bd2bb3f5a8c94e96f33ade2c3812 (diff) | |
download | chromium_src-2df7c5b5a9c31cdcf2623de4c996170d2af28b98.zip chromium_src-2df7c5b5a9c31cdcf2623de4c996170d2af28b98.tar.gz chromium_src-2df7c5b5a9c31cdcf2623de4c996170d2af28b98.tar.bz2 |
Get rid of non-functional elements from the themes prefs; add switcher.
BUG=http://crbug.com/18094
TEST=try the theme picker and enjoy!
Review URL: http://codereview.chromium.org/159727
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22296 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/preferences_window_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.mm | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index 57edccd..7eb91cc9 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -14,6 +14,7 @@ #import "chrome/browser/cocoa/clear_browsing_data_controller.h" #import "chrome/browser/cocoa/custom_home_pages_model.h" #import "chrome/browser/cocoa/search_engine_list_model.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/net/dns_global.h" @@ -628,10 +629,78 @@ const int kDisabledIndex = 1; [controller runModalDialog]; } -// Called to reset the theming info back to the defaults. -- (IBAction)resetTheme:(id)sender { - [self recordUserAction:L"Options_ThemesReset"]; - profile_->ClearTheme(); +- (NSArray*)availableThemes { + const ExtensionList* extensions = + profile_->GetExtensionsService()->extensions(); + + NSMutableArray* themes = [NSMutableArray array]; + + for (size_t i = 0; i < extensions->size(); ++i) { + Extension* extension = extensions->at(i); + if (!extension->IsTheme()) + continue; + + NSDictionary* theme = + [NSDictionary dictionaryWithObjectsAndKeys: + [NSString stringWithUTF8String:extension->name().c_str()], @"name", + [NSString stringWithUTF8String:extension->id().c_str()], @"id", + nil]; + [themes addObject:theme]; + } + + NSSortDescriptor* sortDescriptor = + [[[NSSortDescriptor alloc] initWithKey:@"name" + ascending:YES] autorelease]; + + [themes sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; + + NSMutableArray* themeNames = [NSMutableArray array]; + NSMutableArray* themeIds = [NSMutableArray array]; + + for (NSDictionary* themeDict in themes) { + [themeNames addObject:[themeDict objectForKey:@"name"]]; + [themeIds addObject:[themeDict objectForKey:@"id"]]; + } + + themeMenuOffset_ = 0; + if ([themeNames count] > 0) { + [themeNames insertObject:@"-" atIndex:0]; + ++themeMenuOffset_; + } + NSString* defaultLabel = + [NSString stringWithUTF8String: + l10n_util::GetStringUTF8(IDS_THEMES_DEFAULT_THEME_LABEL).c_str()]; + [themeNames insertObject:defaultLabel atIndex:0]; + ++themeMenuOffset_; + + themeIds_.reset([themeIds retain]); + return themeNames; +} + +- (int)currentTheme { + const Extension* theme = profile_->GetTheme(); + + if (theme) { + NSString* themeId = [NSString stringWithUTF8String:theme->id().c_str()]; + return [themeIds_.get() indexOfObject:themeId] + themeMenuOffset_; + } + + return 0; +} + +- (void)setCurrentTheme:(int)newTheme { + newTheme -= themeMenuOffset_; + + if (newTheme < 0) { + [self recordUserAction:L"Options_ThemesReset"]; + profile_->ClearTheme(); + } else { + NSString* themeId = [themeIds_.get() objectAtIndex:newTheme]; + Extension* extension = + profile_->GetExtensionsService()-> + GetExtensionById([themeId UTF8String]); + profile_->SetTheme(extension); + } } - (IBAction)themesGallery:(id)sender { |