OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac_util.h" | 5 #include "base/mac_util.h" |
6 #include "base/sys_string_conversions.h" | 6 #include "base/sys_string_conversions.h" |
7 #include "chrome/app/chrome_dll_resource.h" // IDC_* | 7 #include "chrome/app/chrome_dll_resource.h" // IDC_* |
8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // too early to tell. | 302 // too early to tell. |
303 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 303 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
304 SEL action = [item action]; | 304 SEL action = [item action]; |
305 BOOL enable = NO; | 305 BOOL enable = NO; |
306 if (action == @selector(commandDispatch:)) { | 306 if (action == @selector(commandDispatch:)) { |
307 NSInteger tag = [item tag]; | 307 NSInteger tag = [item tag]; |
308 if (browser_->command_updater()->SupportsCommand(tag)) { | 308 if (browser_->command_updater()->SupportsCommand(tag)) { |
309 // Generate return value (enabled state) | 309 // Generate return value (enabled state) |
310 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; | 310 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; |
311 | 311 |
| 312 // Disable "close tab" if we're not the key window or if there's only |
| 313 // one tab. |
| 314 if (tag == IDC_CLOSE_TAB) |
| 315 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow]; |
| 316 |
312 // If the item is toggleable, find it's toggle state and | 317 // If the item is toggleable, find it's toggle state and |
313 // try to update it. This is a little awkward, but the alternative is | 318 // try to update it. This is a little awkward, but the alternative is |
314 // to check after a commandDispatch, which seems worse. | 319 // to check after a commandDispatch, which seems worse. |
315 [self updateToggleStateWithTag:tag forItem:item]; | 320 [self updateToggleStateWithTag:tag forItem:item]; |
316 } | 321 } |
317 } | 322 } |
318 return enable; | 323 return enable; |
319 } | 324 } |
320 | 325 |
321 // Called when the user picks a menu or toolbar item when this window is key. | 326 // Called when the user picks a menu or toolbar item when this window is key. |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 else if ([event deltaY] < -0.5) | 692 else if ([event deltaY] < -0.5) |
688 ; // TODO(pinkerton): figure out page-down | 693 ; // TODO(pinkerton): figure out page-down |
689 | 694 |
690 // Ensure the command is valid first (ExecuteCommand() won't do that) and | 695 // Ensure the command is valid first (ExecuteCommand() won't do that) and |
691 // then make it so. | 696 // then make it so. |
692 if (browser_->command_updater()->IsCommandEnabled(command)) | 697 if (browser_->command_updater()->IsCommandEnabled(command)) |
693 browser_->ExecuteCommand(command); | 698 browser_->ExecuteCommand(command); |
694 } | 699 } |
695 | 700 |
696 @end | 701 @end |
OLD | NEW |