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

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

Issue 3124002: [Mac] Insert the Update Chrome item to existing Wrench menus when notified. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Rename method Created 10 years, 4 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
« no previous file with comments | « chrome/browser/cocoa/wrench_menu_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/menus/menu_model.h" 8 #include "app/menus/menu_model.h"
8 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
9 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_window.h" 12 #include "chrome/browser/browser_window.h"
12 #import "chrome/browser/cocoa/menu_tracked_root_view.h" 13 #import "chrome/browser/cocoa/menu_tracked_root_view.h"
13 #import "chrome/browser/cocoa/toolbar_controller.h" 14 #import "chrome/browser/cocoa/toolbar_controller.h"
14 #include "chrome/browser/wrench_menu_model.h" 15 #include "chrome/browser/wrench_menu_model.h"
16 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h"
15 18
16 @interface WrenchMenuController (Private) 19 @interface WrenchMenuController (Private)
17 - (void)adjustPositioning; 20 - (void)adjustPositioning;
18 - (void)performCommandDispatch:(NSNumber*)tag; 21 - (void)performCommandDispatch:(NSNumber*)tag;
19 @end 22 @end
20 23
21 @implementation WrenchMenuController 24 @implementation WrenchMenuController
22 25
23 - (id)init { 26 - (id)init {
24 self = [super init]; 27 self = [super init];
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 117
115 // Used to perform the actual dispatch on the outermost runloop. 118 // Used to perform the actual dispatch on the outermost runloop.
116 - (void)performCommandDispatch:(NSNumber*)tag { 119 - (void)performCommandDispatch:(NSNumber*)tag {
117 [self wrenchMenuModel]->ExecuteCommand([tag intValue]); 120 [self wrenchMenuModel]->ExecuteCommand([tag intValue]);
118 } 121 }
119 122
120 - (WrenchMenuModel*)wrenchMenuModel { 123 - (WrenchMenuModel*)wrenchMenuModel {
121 return static_cast<WrenchMenuModel*>(model_); 124 return static_cast<WrenchMenuModel*>(model_);
122 } 125 }
123 126
127 // Inserts the update available notification menu item.
128 - (void)insertUpdateAvailableItem {
129 WrenchMenuModel* model = [self wrenchMenuModel];
130 // Don't insert the item multiple times.
131 if (!model || model->GetIndexOfCommandId(IDC_ABOUT) != -1)
132 return;
133
134 // Update the model manually because the model is static because other
135 // platforms always have an About item.
136 int index = model->GetIndexOfCommandId(IDC_OPTIONS) + 1;
137 model->InsertItemAt(index, IDC_ABOUT,
138 l10n_util::GetStringFUTF16(IDS_ABOUT,
139 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
140
141 // The model does not broadcast change notifications to its delegate, so
142 // insert the actual menu item ourselves.
143 NSInteger menuIndex = [[self menu] indexOfItemWithTag:index];
144 [self addItemToMenu:[self menu]
145 atIndex:menuIndex
146 fromModel:model
147 modelIndex:index];
148
149 // Since the tag of each menu item is the index within the model, they need
150 // to be adjusted after insertion.
151 for (NSInteger i = menuIndex + 1; i < [[self menu] numberOfItems]; ++i) {
152 NSMenuItem* item = [[self menu] itemAtIndex:i];
153 [item setTag:[item tag] + 1];
154 }
155 }
156
124 // Fit the localized strings into the Cut/Copy/Paste control, then resize the 157 // Fit the localized strings into the Cut/Copy/Paste control, then resize the
125 // whole menu item accordingly. 158 // whole menu item accordingly.
126 - (void)adjustPositioning { 159 - (void)adjustPositioning {
127 const CGFloat kButtonPadding = 12; 160 const CGFloat kButtonPadding = 12;
128 CGFloat delta = 0; 161 CGFloat delta = 0;
129 162
130 // Go through the three buttons from right-to-left, adjusting the size to fit 163 // Go through the three buttons from right-to-left, adjusting the size to fit
131 // the localized strings while keeping them all aligned on their horizontal 164 // the localized strings while keeping them all aligned on their horizontal
132 // edges. 165 // edges.
133 const size_t kAdjustViewCount = 3; 166 const size_t kAdjustViewCount = 3;
(...skipping 24 matching lines...) Expand all
158 191
159 // Also resize the superview of the buttons, which is an NSView used to slide 192 // Also resize the superview of the buttons, which is an NSView used to slide
160 // when the item title is too big and GTM resizes it. 193 // when the item title is too big and GTM resizes it.
161 NSRect parentFrame = [[editCut_ superview] frame]; 194 NSRect parentFrame = [[editCut_ superview] frame];
162 parentFrame.size.width += delta; 195 parentFrame.size.width += delta;
163 parentFrame.origin.x -= delta; 196 parentFrame.origin.x -= delta;
164 [[editCut_ superview] setFrame:parentFrame]; 197 [[editCut_ superview] setFrame:parentFrame];
165 } 198 }
166 199
167 @end // @implementation WrenchMenuController 200 @end // @implementation WrenchMenuController
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/wrench_menu_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698