summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/browser_window_controller.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-18 00:57:49 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-18 00:57:49 +0000
commit44b2c885548d647611d908309dfdf6306eac7ed8 (patch)
treec46fd5199ac07df770ca9b01a0b73dc594b6d63d /chrome/browser/cocoa/browser_window_controller.mm
parent9eef357377e89bffd2d5ff9fad9de0c94d8cc934 (diff)
downloadchromium_src-44b2c885548d647611d908309dfdf6306eac7ed8.zip
chromium_src-44b2c885548d647611d908309dfdf6306eac7ed8.tar.gz
chromium_src-44b2c885548d647611d908309dfdf6306eac7ed8.tar.bz2
Mac bookmark work.
- The bookmark menu is populated dynamically with bookmarks, including subfolders --> submenus. E.g. star something --> shows up in menu. Menu items are disabled but always present and current. - Always Show Bookmarks" menu now live; reads from / writes to preference, and shows correct "toggle state". - Bookmark bar on each tab, present if requested. (Currently an empty box). - Random stuff; e.g. bookmark prefs init moved to a x-plat location. This CL does not contain Cole's views. Bried english description of the nib file changes: - add a new view for the bookmark bar in the tab; hook it up to the controller - Many tag sets (e.g. View-->Always Show Bookmarks Bar now 40009) - Remove dummy bookmark menu items Review URL: http://codereview.chromium.org/46078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11936 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/browser_window_controller.mm')
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm52
1 files changed, 44 insertions, 8 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index 8779fed..99499c7 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#import "chrome/app/chrome_dll_resource.h" // IDC_*
#import "chrome/browser/browser.h"
#import "chrome/browser/cocoa/browser_window_cocoa.h"
#import "chrome/browser/cocoa/browser_window_controller.h"
@@ -17,7 +18,8 @@
if ((self = [super initWithWindowNibName:@"BrowserWindow"])) {
browser_ = browser;
DCHECK(browser_);
- windowShim_ = new BrowserWindowCocoa(self, [self window]);
+ windowShim_ = new BrowserWindowCocoa(browser, self, [self window]);
+ windowShim_->Init();
}
return self;
}
@@ -40,12 +42,8 @@
// this window's Browser and the tab strip view. The controller will handle
// registering for the appropriate tab notifications from the back-end and
// managing the creation of new tabs.
- tabStripController_ =
- [[TabStripController alloc]
- initWithView:tabStripView_
- tabModel:browser_->tabstrip_model()
- toolbarModel:browser_->toolbar_model()
- commands:browser_->command_updater()];
+ tabStripController_ = [[TabStripController alloc]
+ initWithView:tabStripView_ browser:browser_];
// Place the tab bar above the content box and add it to the view hierarchy
// as a sibling of the content view so it can overlap with the window frame.
@@ -102,6 +100,27 @@
return YES;
}
+// Update a toggle state for an NSMenuItem if modified.
+// Take care to insure |item| looks like a NSMenuItem.
+// Called by validateUserInterfaceItem:.
+- (void)updateToggleStateWithTag:(NSInteger)tag forItem:(id)item {
+ if (![item respondsToSelector:@selector(state)] ||
+ ![item respondsToSelector:@selector(setState:)])
+ return;
+
+ // On Windows this logic happens in bookmark_bar_view.cc. On the
+ // Mac we're a lot more MVC happy so we've moved it into a
+ // controller. To be clear, this simply updates the menu item; it
+ // does not display the bookmark bar itself.
+ if (tag == IDC_SHOW_BOOKMARK_BAR) {
+ bool toggled = windowShim_->IsBookmarkBarVisible();
+ NSInteger oldState = [item state];
+ NSInteger newState = toggled ? NSOnState : NSOffState;
+ if (oldState != newState)
+ [item setState:newState];
+ }
+}
+
// Called to validate menu and toolbar items when this window is key. All the
// items we care about have been set with the |commandDispatch:| action and
// a target of FirstResponder in IB. If it's not one of those, let it
@@ -117,8 +136,15 @@
BOOL enable = NO;
if (action == @selector(commandDispatch:)) {
NSInteger tag = [item tag];
- if (browser_->command_updater()->SupportsCommand(tag))
+ if (browser_->command_updater()->SupportsCommand(tag)) {
+ // Generate return value (enabled state)
enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO;
+
+ // If the item is toggleable, find it's toggle state and
+ // try to update it. This is a little awkward, but the alternative is
+ // to check after a commandDispatch, which seems worse.
+ [self updateToggleStateWithTag:tag forItem:item];
+ }
}
return enable;
}
@@ -175,4 +201,14 @@
[tabStripController_ focusLocationBar];
}
+- (BOOL)isBookmarkBarVisible {
+ return [tabStripController_ isBookmarkBarVisible];
+
+}
+
+- (void)toggleBookmarkBar {
+ [tabStripController_ toggleBookmarkBar];
+}
+
+
@end