diff options
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 16073d8..f2face3 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -5,10 +5,27 @@ #import "app_controller_mac.h" #import "base/message_loop.h" +#import "chrome/app/chrome_dll_resource.h" +#import "chrome/browser/browser.h" #import "chrome/browser/browser_list.h" +#import "chrome/browser/command_updater.h" + +@interface AppController(PRIVATE) +- (void)initMenuState; +@end @implementation AppController +- (void)awakeFromNib { + // set up the command updater for when there are no windows open + [self initMenuState]; +} + +- (void)dealloc { + delete menuState_; + [super dealloc]; +} + // We can't use the standard terminate: method because it will abrubptly exit // the app and leave things on the stack in an unfinalized state. We need to // post a quit message to our run loop so the stack can gracefully unwind. @@ -32,5 +49,42 @@ MessageLoopForUI::current()->Quit(); } +// Called to validate menu items when there are no key windows. 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 +// continue up the responder chain to be handled elsewhere. We pull out the +// tag as the cross-platform constant to differentiate and dispatch the +// various commands. +- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { + SEL action = [item action]; + BOOL enable = NO; + if (action == @selector(commandDispatch:)) { + NSInteger tag = [item tag]; + if (menuState_->SupportsCommand(tag)) + enable = menuState_->IsCommandEnabled(tag) ? YES : NO; + } else if (action == @selector(quit:)) { + enable = YES; + } + return enable; +} + +// Called when the user picks a menu item when there are no key windows. Calls +// through to the browser object to execute the command. This assumes that the +// command is supported and doesn't check, otherwise it would have been disabled +// in the UI in validateUserInterfaceItem:. +- (void)commandDispatch:(id)sender { + NSInteger tag = [sender tag]; + switch (tag) { + case IDC_NEW_WINDOW: + Browser::OpenEmptyWindow(NULL); + break; + }; +} + +- (void)initMenuState { + menuState_ = new CommandUpdater(NULL); + menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); + // TODO(pinkerton): ...more to come... +} @end |