summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 19:13:17 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 19:13:17 +0000
commit2df7c5b5a9c31cdcf2623de4c996170d2af28b98 (patch)
tree6b7394dcad468eb6008d07ed6069de69af682d29 /chrome/browser/cocoa
parente65c7713f650bd2bb3f5a8c94e96f33ade2c3812 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/cocoa/autoseparating_menu.h13
-rw-r--r--chrome/browser/cocoa/autoseparating_menu.m26
-rw-r--r--chrome/browser/cocoa/preferences_window_controller.h5
-rw-r--r--chrome/browser/cocoa/preferences_window_controller.mm77
4 files changed, 116 insertions, 5 deletions
diff --git a/chrome/browser/cocoa/autoseparating_menu.h b/chrome/browser/cocoa/autoseparating_menu.h
new file mode 100644
index 0000000..c350561
--- /dev/null
+++ b/chrome/browser/cocoa/autoseparating_menu.h
@@ -0,0 +1,13 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+// By default, NSPopUpButton doesn't allow separator items in its menus. This is
+// an NSMenu subclass that automatically adds separator items when presented
+// with a @"-" string, so it can be set up in the nib to be the menu class.
+@interface AutoseparatingMenu : NSMenu {
+}
+
+@end
diff --git a/chrome/browser/cocoa/autoseparating_menu.m b/chrome/browser/cocoa/autoseparating_menu.m
new file mode 100644
index 0000000..e0f36a7
--- /dev/null
+++ b/chrome/browser/cocoa/autoseparating_menu.m
@@ -0,0 +1,26 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/autoseparating_menu.h"
+
+@implementation AutoseparatingMenu
+
+- (NSMenuItem *)insertItemWithTitle:(NSString *)aString
+ action:(SEL)aSelector
+ keyEquivalent:(NSString *)keyEquiv
+ atIndex:(NSInteger)index {
+ if ([aString isEqualToString:@"-"]) {
+ NSMenuItem* separator = [NSMenuItem separatorItem];
+ [self insertItem:separator
+ atIndex:index];
+ return separator;
+ } else {
+ return [super insertItemWithTitle:aString
+ action:aSelector
+ keyEquivalent:keyEquiv
+ atIndex:index];
+ }
+}
+
+@end
diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h
index f7512fb..d671344 100644
--- a/chrome/browser/cocoa/preferences_window_controller.h
+++ b/chrome/browser/cocoa/preferences_window_controller.h
@@ -48,6 +48,8 @@ class Profile;
// User Data panel
BooleanPrefMember askSavePasswords_;
BooleanPrefMember formAutofill_;
+ scoped_nsobject<NSMutableArray> themeIds_;
+ int themeMenuOffset_;
// Under the hood panel
IBOutlet NSView* advancedView_;
@@ -78,7 +80,8 @@ class Profile;
- (IBAction)showSavedPasswords:(id)sender;
- (IBAction)importData:(id)sender;
- (IBAction)clearData:(id)sender;
-- (IBAction)resetTheme:(id)sender;
+- (NSArray*)availableThemes;
+@property int currentTheme;
- (IBAction)themesGallery:(id)sender;
// Usable from cocoa bindings to hook up the custom home pages table.
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 {