diff options
author | pinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-21 22:04:44 +0000 |
---|---|---|
committer | pinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-21 22:04:44 +0000 |
commit | 88d749436bf04c540448065a1601ece53bfdb312 (patch) | |
tree | 4be4d6d86a0884932d13efd92a2a18d60a7f962f /chrome/browser/app_controller_mac.mm | |
parent | 1c36b962d877273125d92c4996a136fc1ac7e806 (diff) | |
download | chromium_src-88d749436bf04c540448065a1601ece53bfdb312.zip chromium_src-88d749436bf04c540448065a1601ece53bfdb312.tar.gz chromium_src-88d749436bf04c540448065a1601ece53bfdb312.tar.bz2 |
add basic command handling for browser window and for where there are no windows open. Can now create new browser windows.
Review URL: http://codereview.chromium.org/18458
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8387 0039d316-1c4b-4281-b951-d872f2087c98
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 |