OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/wrench_menu_controller.h" | 5 #import "chrome/browser/cocoa/wrench_menu_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/menus/menu_model.h" | 8 #include "app/menus/menu_model.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 [[controller_ zoomDisplay] setTitle:SysUTF16ToNSString(level)]; | 47 [[controller_ zoomDisplay] setTitle:SysUTF16ToNSString(level)]; |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 NotificationRegistrar registrar_; | 51 NotificationRegistrar registrar_; |
52 WrenchMenuController* controller_; // Weak; owns this. | 52 WrenchMenuController* controller_; // Weak; owns this. |
53 }; | 53 }; |
54 | 54 |
55 } // namespace WrenchMenuControllerInternal | 55 } // namespace WrenchMenuControllerInternal |
56 | 56 |
57 @implementation WrenchMenuController | 57 @implementation WrenchMenuController |
Robert Sesek
2010/08/24 15:28:07
Add: @synthesize wrenchMenuModel = wrenchMenuModel
| |
58 | 58 |
59 - (id)init { | 59 - (id)init { |
60 if ((self = [super init])) { | 60 if ((self = [super init])) { |
61 observer_.reset(new WrenchMenuControllerInternal::ZoomLevelObserver(self)); | 61 observer_.reset(new WrenchMenuControllerInternal::ZoomLevelObserver(self)); |
62 } | 62 } |
63 return self; | 63 return self; |
64 } | 64 } |
65 | 65 |
66 - (void)setWrenchMenuModel:(WrenchMenuModel*)model { | |
Robert Sesek
2010/08/24 00:31:13
Remove.
Robert Sesek
2010/08/24 15:28:07
Keep this.
| |
67 wrench_model_ = model; | |
68 [self setModel:model->menu_model()]; | |
69 } | |
70 | |
66 - (void)addItemToMenu:(NSMenu*)menu | 71 - (void)addItemToMenu:(NSMenu*)menu |
67 atIndex:(NSInteger)index | 72 atIndex:(NSInteger)index |
68 fromModel:(menus::MenuModel*)model | 73 fromModel:(menus::MenuModel*)model |
69 modelIndex:(int)modelIndex { | 74 modelIndex:(int)modelIndex { |
70 // Non-button item types should be built as normal items. | 75 // Non-button item types should be built as normal items. |
71 menus::MenuModel::ItemType type = model->GetTypeAt(modelIndex); | 76 menus::MenuModel::ItemType type = model->GetTypeAt(modelIndex); |
72 if (type != menus::MenuModel::TYPE_BUTTON_ITEM) { | 77 if (type != menus::MenuModel::TYPE_BUTTON_ITEM) { |
73 [super addItemToMenu:menu | 78 [super addItemToMenu:menu |
74 atIndex:index | 79 atIndex:index |
75 fromModel:model | 80 fromModel:model |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 [self performSelector:@selector(performCommandDispatch:) | 163 [self performSelector:@selector(performCommandDispatch:) |
159 withObject:[NSNumber numberWithInt:tag] | 164 withObject:[NSNumber numberWithInt:tag] |
160 afterDelay:0.0]; | 165 afterDelay:0.0]; |
161 } | 166 } |
162 | 167 |
163 // Used to perform the actual dispatch on the outermost runloop. | 168 // Used to perform the actual dispatch on the outermost runloop. |
164 - (void)performCommandDispatch:(NSNumber*)tag { | 169 - (void)performCommandDispatch:(NSNumber*)tag { |
165 [self wrenchMenuModel]->ExecuteCommand([tag intValue]); | 170 [self wrenchMenuModel]->ExecuteCommand([tag intValue]); |
166 } | 171 } |
167 | 172 |
168 - (WrenchMenuModel*)wrenchMenuModel { | 173 - (WrenchMenuModel*)wrenchMenuModel { |
Robert Sesek
2010/08/24 15:28:07
Remove this (the compiler will generate it).
| |
169 return static_cast<WrenchMenuModel*>(model_); | 174 return wrench_model_; |
Robert Sesek
2010/08/24 00:31:13
Keep this as it was.
| |
170 } | |
171 | |
172 // Inserts the update available notification menu item. | |
173 - (void)insertUpdateAvailableItem { | |
Robert Sesek
2010/08/24 00:31:13
Cocoa's MenuController (and thus the WrenchMenuCon
| |
174 WrenchMenuModel* model = [self wrenchMenuModel]; | |
175 // Don't insert the item multiple times. | |
176 if (!model || model->GetIndexOfCommandId(IDC_ABOUT) != -1) | |
177 return; | |
178 | |
179 // Update the model manually because the model is static because other | |
180 // platforms always have an About item. | |
181 int index = model->GetIndexOfCommandId(IDC_OPTIONS) + 1; | |
182 model->InsertItemAt(index, IDC_ABOUT, | |
183 l10n_util::GetStringFUTF16(IDS_ABOUT, | |
184 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
185 | |
186 // The model does not broadcast change notifications to its delegate, so | |
187 // insert the actual menu item ourselves. | |
188 NSInteger menuIndex = [[self menu] indexOfItemWithTag:index]; | |
189 [self addItemToMenu:[self menu] | |
190 atIndex:menuIndex | |
191 fromModel:model | |
192 modelIndex:index]; | |
193 | |
194 // Since the tag of each menu item is the index within the model, they need | |
195 // to be adjusted after insertion. | |
196 for (NSInteger i = menuIndex + 1; i < [[self menu] numberOfItems]; ++i) { | |
197 NSMenuItem* item = [[self menu] itemAtIndex:i]; | |
198 [item setTag:[item tag] + 1]; | |
199 } | |
200 } | 175 } |
201 | 176 |
202 // Fit the localized strings into the Cut/Copy/Paste control, then resize the | 177 // Fit the localized strings into the Cut/Copy/Paste control, then resize the |
203 // whole menu item accordingly. | 178 // whole menu item accordingly. |
204 - (void)adjustPositioning { | 179 - (void)adjustPositioning { |
205 const CGFloat kButtonPadding = 12; | 180 const CGFloat kButtonPadding = 12; |
206 CGFloat delta = 0; | 181 CGFloat delta = 0; |
207 | 182 |
208 // Go through the three buttons from right-to-left, adjusting the size to fit | 183 // Go through the three buttons from right-to-left, adjusting the size to fit |
209 // the localized strings while keeping them all aligned on their horizontal | 184 // the localized strings while keeping them all aligned on their horizontal |
(...skipping 30 matching lines...) Expand all Loading... | |
240 parentFrame.size.width += delta; | 215 parentFrame.size.width += delta; |
241 parentFrame.origin.x -= delta; | 216 parentFrame.origin.x -= delta; |
242 [[editCut_ superview] setFrame:parentFrame]; | 217 [[editCut_ superview] setFrame:parentFrame]; |
243 } | 218 } |
244 | 219 |
245 - (NSButton*)zoomDisplay { | 220 - (NSButton*)zoomDisplay { |
246 return zoomDisplay_; | 221 return zoomDisplay_; |
247 } | 222 } |
248 | 223 |
249 @end // @implementation WrenchMenuController | 224 @end // @implementation WrenchMenuController |
OLD | NEW |