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

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

Issue 1588703002: Slight clean-up of the bookmark bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | 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) 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 "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" 9 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 12 matching lines...) Expand all
23 #include "content/public/browser/notification_observer.h" 23 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
27 #include "ui/base/l10n/l10n_util_mac.h" 27 #include "ui/base/l10n/l10n_util_mac.h"
28 28
29 using base::UserMetricsAction; 29 using base::UserMetricsAction;
30 using bookmarks::BookmarkModel; 30 using bookmarks::BookmarkModel;
31 using bookmarks::BookmarkNode; 31 using bookmarks::BookmarkNode;
32 32
33 // An object to represent the ChooseAnotherFolder item in the pop up.
34 @interface ChooseAnotherFolder : NSObject
35 @end
36
37 @implementation ChooseAnotherFolder
38 @end
39
40 @interface BookmarkBubbleController (PrivateAPI) 33 @interface BookmarkBubbleController (PrivateAPI)
41 - (void)updateBookmarkNode; 34 - (void)updateBookmarkNode;
42 - (void)fillInFolderList; 35 - (void)fillInFolderList;
43 @end 36 @end
44 37
45 @implementation BookmarkBubbleController 38 @implementation BookmarkBubbleController
46 39
47 @synthesize node = node_; 40 @synthesize node = node_;
48 41
49 + (id)chooseAnotherFolderObject {
50 // Singleton object to act as a representedObject for the "choose another 42 // Singleton object to act as a representedObject for the "choose another
51 // folder" item in the pop up. 43 // folder" item in the pop up.
52 static ChooseAnotherFolder* object = nil; 44 + (id)chooseAnotherFolderObject {
53 if (!object) { 45 static id object = [[NSObject alloc] init];
54 object = [[ChooseAnotherFolder alloc] init];
55 }
56 return object; 46 return object;
57 } 47 }
58 48
59 - (id)initWithParentWindow:(NSWindow*)parentWindow 49 - (id)initWithParentWindow:(NSWindow*)parentWindow
60 bubbleObserver:(bookmarks::BookmarkBubbleObserver*)bubbleObserver 50 bubbleObserver:(bookmarks::BookmarkBubbleObserver*)bubbleObserver
61 managed:(bookmarks::ManagedBookmarkService*)managed 51 managed:(bookmarks::ManagedBookmarkService*)managed
62 model:(BookmarkModel*)model 52 model:(BookmarkModel*)model
63 node:(const BookmarkNode*)node 53 node:(const BookmarkNode*)node
64 alreadyBookmarked:(BOOL)alreadyBookmarked { 54 alreadyBookmarked:(BOOL)alreadyBookmarked {
65 DCHECK(managed); 55 DCHECK(managed);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // The controller is the target of the pop up button box action so it can 223 // The controller is the target of the pop up button box action so it can
234 // handle when "choose another folder" was picked. 224 // handle when "choose another folder" was picked.
235 - (IBAction)folderChanged:(id)sender { 225 - (IBAction)folderChanged:(id)sender {
236 DCHECK([sender isEqual:folderPopUpButton_]); 226 DCHECK([sender isEqual:folderPopUpButton_]);
237 // It is possible that due to model change our parent window has been closed 227 // It is possible that due to model change our parent window has been closed
238 // but the popup is still showing and able to notify the controller of a 228 // but the popup is still showing and able to notify the controller of a
239 // folder change. We ignore the sender in this case. 229 // folder change. We ignore the sender in this case.
240 if (!self.parentWindow) 230 if (!self.parentWindow)
241 return; 231 return;
242 NSMenuItem* selected = [folderPopUpButton_ selectedItem]; 232 NSMenuItem* selected = [folderPopUpButton_ selectedItem];
243 ChooseAnotherFolder* chooseItem = [[self class] chooseAnotherFolderObject]; 233 if ([selected representedObject] ==
244 if ([[selected representedObject] isEqual:chooseItem]) { 234 [[self class] chooseAnotherFolderObject]) {
245 content::RecordAction( 235 content::RecordAction(
246 UserMetricsAction("BookmarkBubble_EditFromCombobox")); 236 UserMetricsAction("BookmarkBubble_EditFromCombobox"));
247 [self showEditor]; 237 [self showEditor];
248 } 238 }
249 } 239 }
250 240
251 // The controller is the delegate of the window so it receives did resign key 241 // The controller is the delegate of the window so it receives did resign key
252 // notifications. When key is resigned mirror Windows behavior and close the 242 // notifications. When key is resigned mirror Windows behavior and close the
253 // window. 243 // window.
254 - (void)windowDidResignKey:(NSNotification*)notification { 244 - (void)windowDidResignKey:(NSNotification*)notification {
(...skipping 16 matching lines...) Expand all
271 NSString* newTitle = [nameTextField_ stringValue]; 261 NSString* newTitle = [nameTextField_ stringValue];
272 if (![oldTitle isEqual:newTitle]) { 262 if (![oldTitle isEqual:newTitle]) {
273 model_->SetTitle(node_, base::SysNSStringToUTF16(newTitle)); 263 model_->SetTitle(node_, base::SysNSStringToUTF16(newTitle));
274 content::RecordAction( 264 content::RecordAction(
275 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 265 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
276 } 266 }
277 // Then the parent folder. 267 // Then the parent folder.
278 const BookmarkNode* oldParent = node_->parent(); 268 const BookmarkNode* oldParent = node_->parent();
279 NSMenuItem* selectedItem = [folderPopUpButton_ selectedItem]; 269 NSMenuItem* selectedItem = [folderPopUpButton_ selectedItem];
280 id representedObject = [selectedItem representedObject]; 270 id representedObject = [selectedItem representedObject];
281 if ([representedObject isEqual:[[self class] chooseAnotherFolderObject]]) { 271 if (representedObject == [[self class] chooseAnotherFolderObject]) {
282 // "Choose another folder..." 272 // "Choose another folder..."
283 return; 273 return;
284 } 274 }
285 const BookmarkNode* newParent = 275 const BookmarkNode* newParent =
286 static_cast<const BookmarkNode*>([representedObject pointerValue]); 276 static_cast<const BookmarkNode*>([representedObject pointerValue]);
287 DCHECK(newParent); 277 DCHECK(newParent);
288 if (oldParent != newParent) { 278 if (oldParent != newParent) {
289 int index = newParent->child_count(); 279 int index = newParent->child_count();
290 model_->Move(node_, newParent, index); 280 model_->Move(node_, newParent, index);
291 content::RecordAction(UserMetricsAction("BookmarkBubble_ChangeParent")); 281 content::RecordAction(UserMetricsAction("BookmarkBubble_ChangeParent"));
292 } 282 }
293 } 283 }
294 284
295 // Fill in all information related to the folder pop up button. 285 // Fill in all information related to the folder pop up button.
296 - (void)fillInFolderList { 286 - (void)fillInFolderList {
297 [nameTextField_ setStringValue:base::SysUTF16ToNSString(node_->GetTitle())]; 287 [nameTextField_ setStringValue:base::SysUTF16ToNSString(node_->GetTitle())];
298 DCHECK([folderPopUpButton_ numberOfItems] == 0); 288 DCHECK([folderPopUpButton_ numberOfItems] == 0);
299 [self addFolderNodes:model_->root_node() 289 [self addFolderNodes:model_->root_node()
300 toPopUpButton:folderPopUpButton_ 290 toPopUpButton:folderPopUpButton_
301 indentation:0]; 291 indentation:0];
302 NSMenu* menu = [folderPopUpButton_ menu]; 292 NSMenu* menu = [folderPopUpButton_ menu];
303 [menu addItem:[NSMenuItem separatorItem]]; 293 [menu addItem:[NSMenuItem separatorItem]];
304 NSString* title = [[self class] chooseAnotherFolderString]; 294 NSString* title = [[self class] chooseAnotherFolderString];
305 NSMenuItem *item = [menu addItemWithTitle:title 295 NSMenuItem *item = [menu addItemWithTitle:title
306 action:NULL 296 action:NULL
307 keyEquivalent:@""]; 297 keyEquivalent:@""];
308 ChooseAnotherFolder* obj = [[self class] chooseAnotherFolderObject]; 298 [item setRepresentedObject:[[self class] chooseAnotherFolderObject]];
309 [item setRepresentedObject:obj];
310 // Finally, select the current parent. 299 // Finally, select the current parent.
311 NSValue* parentValue = [NSValue valueWithPointer:node_->parent()]; 300 NSValue* parentValue = [NSValue valueWithPointer:node_->parent()];
312 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 301 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
313 [folderPopUpButton_ selectItemAtIndex:idx]; 302 [folderPopUpButton_ selectItemAtIndex:idx];
314 } 303 }
315 304
316 @end // BookmarkBubbleController 305 @end // BookmarkBubbleController
317 306
318 307
319 @implementation BookmarkBubbleController (ExposedForUnitTesting) 308 @implementation BookmarkBubbleController (ExposedForUnitTesting)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 361 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
373 DCHECK(idx != -1); 362 DCHECK(idx != -1);
374 [folderPopUpButton_ selectItemAtIndex:idx]; 363 [folderPopUpButton_ selectItemAtIndex:idx];
375 } 364 }
376 365
377 - (NSPopUpButton*)folderPopUpButton { 366 - (NSPopUpButton*)folderPopUpButton {
378 return folderPopUpButton_; 367 return folderPopUpButton_;
379 } 368 }
380 369
381 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) 370 @end // implementation BookmarkBubbleController(ExposedForUnitTesting)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698