Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: chrome/browser/cocoa/back_forward_menu_controller.mm

Issue 501168: Make back forward menu model a MenuModel.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import "chrome/browser/cocoa/back_forward_menu_controller.h" 5 #import "chrome/browser/cocoa/back_forward_menu_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/back_forward_menu_model.h" 10 #include "chrome/browser/back_forward_menu_model.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 // Methods as delegate: 43 // Methods as delegate:
44 44
45 // Called by backForwardMenu_ just before tracking begins. 45 // Called by backForwardMenu_ just before tracking begins.
46 //TODO(viettrungluu): should we do anything for chapter stops (see model)? 46 //TODO(viettrungluu): should we do anything for chapter stops (see model)?
47 - (void)menuNeedsUpdate:(NSMenu*)menu { 47 - (void)menuNeedsUpdate:(NSMenu*)menu {
48 DCHECK(menu == backForwardMenu_); 48 DCHECK(menu == backForwardMenu_);
49 49
50 // Remove old menu items (backwards order is as good as any). 50 // Remove old menu items (backwards order is as good as any).
51 for (NSInteger i = [menu numberOfItems]; i > 0; i--) 51 for (NSInteger i = [menu numberOfItems]; i > 0; i--)
52 [menu removeItemAtIndex:(i-1)]; 52 [menu removeItemAtIndex:(i - 1)];
53 53
54 // 0-th item must be blank. (This is because we use a pulldown list, for which 54 // 0-th item must be blank. (This is because we use a pulldown list, for which
55 // Cocoa uses the 0-th item as "title" in the button.) 55 // Cocoa uses the 0-th item as "title" in the button.)
56 [menu insertItemWithTitle:@"" 56 [menu insertItemWithTitle:@""
57 action:nil 57 action:nil
58 keyEquivalent:@"" 58 keyEquivalent:@""
59 atIndex:0]; 59 atIndex:0];
60 for (int menuID = 1; menuID <= model_->GetTotalItemCount(); menuID++) { 60 for (int menuID = 0; menuID < model_->GetItemCount(); menuID++) {
61 if (model_->IsSeparator(menuID)) { 61 if (model_->IsSeparator(menuID)) {
62 [menu insertItem:[NSMenuItem separatorItem] 62 [menu insertItem:[NSMenuItem separatorItem]
63 atIndex:menuID]; 63 atIndex:(menuID + 1)];
64 } else { 64 } else {
65 // Create a menu item with the right label. 65 // Create a menu item with the right label.
66 NSMenuItem* menuItem = [[NSMenuItem alloc] 66 NSMenuItem* menuItem = [[NSMenuItem alloc]
67 initWithTitle:SysUTF16ToNSString(model_->GetItemLabel(menuID)) 67 initWithTitle:SysUTF16ToNSString(model_->GetLabelAt(menuID))
68 action:nil 68 action:nil
69 keyEquivalent:@""]; 69 keyEquivalent:@""];
70 [menuItem autorelease]; 70 [menuItem autorelease];
71 71
72 // Only enable it if it's supposed to do something. 72 SkBitmap icon;
73 [menuItem setEnabled:(model_->ItemHasCommand(menuID) ? YES : NO)];
74
75 // Icon (if it has one). 73 // Icon (if it has one).
76 if (model_->ItemHasIcon(menuID)) 74 if (model_->GetIconAt(menuID, &icon))
77 [menuItem setImage:SkBitmapToNSImage(model_->GetItemIcon(menuID))]; 75 [menuItem setImage:SkBitmapToNSImage(icon)];
78 76
79 // This will make it call our |-executeMenuItem:| method. We store the 77 // This will make it call our |-executeMenuItem:| method. We store the
80 // |menuID| (or |menu_id|) in the tag. 78 // |menuID| (or |menu_id|) in the tag.
81 [menuItem setTag:menuID]; 79 [menuItem setTag:menuID];
82 [menuItem setTarget:self]; 80 [menuItem setTarget:self];
83 [menuItem setAction:@selector(executeMenuItem:)]; 81 [menuItem setAction:@selector(executeMenuItem:)];
84 82
85 // Put it in the menu! 83 // Put it in the menu!
86 [menu insertItem:menuItem 84 [menu insertItem:menuItem
87 atIndex:menuID]; 85 atIndex:(menuID + 1)];
88 } 86 }
89 } 87 }
90 } 88 }
91 89
92 // Action methods: 90 // Action methods:
93 91
94 - (void)executeMenuItem:(id)sender { 92 - (void)executeMenuItem:(id)sender {
95 DCHECK([sender isKindOfClass:[NSMenuItem class]]); 93 DCHECK([sender isKindOfClass:[NSMenuItem class]]);
96 int menuID = [sender tag]; 94 int menuID = [sender tag];
97 model_->ExecuteCommandById(menuID); 95 model_->ActivatedAt(menuID);
98 } 96 }
99 97
100 @end // @implementation BackForwardMenuController 98 @end // @implementation BackForwardMenuController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698