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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.mm

Issue 2804903003: [Mac] Remove "Open All Bookmarks" menu items from application and wrench menus (Closed)
Patch Set: Rebase Created 3 years, 7 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 | « no previous file | chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge_unittest.mm » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <AppKit/AppKit.h> 5 #import <AppKit/AppKit.h>
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #import "chrome/browser/app_controller_mac.h" 9 #import "chrome/browser/app_controller_mac.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 bookmark_nodes_.clear(); 219 bookmark_nodes_.clear();
220 // Recursively delete all menus that look like a bookmark. Also delete all 220 // Recursively delete all menus that look like a bookmark. Also delete all
221 // separator items since we explicitly add them back in. This deletes 221 // separator items since we explicitly add them back in. This deletes
222 // everything except the first item ("Add Bookmark..."). 222 // everything except the first item ("Add Bookmark...").
223 NSArray* items = [menu itemArray]; 223 NSArray* items = [menu itemArray];
224 for (NSMenuItem* item in items) { 224 for (NSMenuItem* item in items) {
225 // Convention: items in the bookmark list which are bookmarks have 225 // Convention: items in the bookmark list which are bookmarks have
226 // an action of openBookmarkMenuItem:. Also, assume all items 226 // an action of openBookmarkMenuItem:. Also, assume all items
227 // with submenus are submenus of bookmarks. 227 // with submenus are submenus of bookmarks.
228 if (([item action] == @selector(openBookmarkMenuItem:)) || 228 if (([item action] == @selector(openBookmarkMenuItem:)) ||
229 ([item action] == @selector(openAllBookmarks:)) ||
230 ([item action] == @selector(openAllBookmarksNewWindow:)) ||
231 ([item action] == @selector(openAllBookmarksIncognitoWindow:)) ||
232 [item hasSubmenu] || 229 [item hasSubmenu] ||
233 [item isSeparatorItem]) { 230 [item isSeparatorItem]) {
234 // This will eventually [obj release] all its kids, if it has 231 // This will eventually [obj release] all its kids, if it has
235 // any. 232 // any.
236 [menu removeItem:item]; 233 [menu removeItem:item];
237 } else { 234 } else {
238 // Leave it alone. 235 // Leave it alone.
239 } 236 }
240 } 237 }
241 } 238 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 bookmark_nodes_[child] = item; 275 bookmark_nodes_[child] = item;
279 if (child->is_folder()) { 276 if (child->is_folder()) {
280 [item setImage:folder_image_]; 277 [item setImage:folder_image_];
281 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; 278 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
282 [menu setSubmenu:submenu forItem:item]; 279 [menu setSubmenu:submenu forItem:item];
283 AddNodeToMenu(child, submenu, add_extra_items); // recursive call 280 AddNodeToMenu(child, submenu, add_extra_items); // recursive call
284 } else { 281 } else {
285 ConfigureMenuItem(child, item, false); 282 ConfigureMenuItem(child, item, false);
286 } 283 }
287 } 284 }
288
289 if (add_extra_items) {
290 // Add menus for 'Open All Bookmarks'.
291 [menu addItem:[NSMenuItem separatorItem]];
292 bool enabled = child_count != 0;
293
294 IncognitoModePrefs::Availability incognito_availability =
295 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
296 bool incognito_enabled =
297 enabled && incognito_availability != IncognitoModePrefs::DISABLED;
298
299 AddItemToMenu(IDC_BOOKMARK_BAR_OPEN_ALL, IDS_BOOKMARK_BAR_OPEN_ALL_COUNT,
300 node, menu, enabled);
301 AddItemToMenu(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW,
302 IDS_BOOKMARK_BAR_OPEN_ALL_COUNT_NEW_WINDOW, node, menu,
303 enabled);
304 AddItemToMenu(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO,
305 IDS_BOOKMARK_BAR_OPEN_ALL_COUNT_INCOGNITO, node, menu,
306 incognito_enabled);
307 }
308 }
309
310 void BookmarkMenuBridge::AddItemToMenu(int command_id,
311 int message_id,
312 const BookmarkNode* node,
313 NSMenu* menu,
314 bool enabled) {
315 int count = (message_id == IDS_BOOKMARK_BAR_OPEN_ALL_COUNT_INCOGNITO)
316 ? chrome::OpenCount(nullptr, node, profile_)
317 : chrome::OpenCount(nullptr, node);
318
319 NSString* title = l10n_util::GetPluralNSStringF(message_id, count);
320 SEL action;
321 if (!enabled) {
322 // A nil action makes a menu item appear disabled. NSMenuItem setEnabled
323 // will not reflect the disabled state until the item title is set again.
324 action = nil;
325 } else if (command_id == IDC_BOOKMARK_BAR_OPEN_ALL) {
326 action = @selector(openAllBookmarks:);
327 } else if (command_id == IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW) {
328 action = @selector(openAllBookmarksNewWindow:);
329 } else {
330 action = @selector(openAllBookmarksIncognitoWindow:);
331 }
332 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
333 action:action
334 keyEquivalent:@""] autorelease];
335 [item setTarget:controller_];
336 [item setTag:node->id()];
337 [item setEnabled:enabled];
338 [menu addItem:item];
339 } 285 }
340 286
341 void BookmarkMenuBridge::ConfigureMenuItem(const BookmarkNode* node, 287 void BookmarkMenuBridge::ConfigureMenuItem(const BookmarkNode* node,
342 NSMenuItem* item, 288 NSMenuItem* item,
343 bool set_title) { 289 bool set_title) {
344 if (set_title) 290 if (set_title)
345 [item setTitle:[BookmarkMenuCocoaController menuTitleForNode:node]]; 291 [item setTitle:[BookmarkMenuCocoaController menuTitleForNode:node]];
346 [item setTarget:controller_]; 292 [item setTarget:controller_];
347 [item setAction:@selector(openBookmarkMenuItem:)]; 293 [item setAction:@selector(openBookmarkMenuItem:)];
348 [item setTag:node->id()]; 294 [item setTag:node->id()];
(...skipping 18 matching lines...) Expand all
367 313
368 NSMenuItem* BookmarkMenuBridge::MenuItemForNode(const BookmarkNode* node) { 314 NSMenuItem* BookmarkMenuBridge::MenuItemForNode(const BookmarkNode* node) {
369 if (!node) 315 if (!node)
370 return nil; 316 return nil;
371 std::map<const BookmarkNode*, NSMenuItem*>::iterator it = 317 std::map<const BookmarkNode*, NSMenuItem*>::iterator it =
372 bookmark_nodes_.find(node); 318 bookmark_nodes_.find(node);
373 if (it == bookmark_nodes_.end()) 319 if (it == bookmark_nodes_.end())
374 return nil; 320 return nil;
375 return it->second; 321 return it->second;
376 } 322 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698