OLD | NEW |
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/cookies_window_controller.h" | 5 #import "chrome/browser/cocoa/cookies_window_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if (recurse) | 121 if (recurse) |
122 return recurse; | 122 return recurse; |
123 } | 123 } |
124 return nil; // We couldn't find the node. | 124 return nil; // We couldn't find the node. |
125 } | 125 } |
126 | 126 |
127 #pragma mark Window Controller | 127 #pragma mark Window Controller |
128 | 128 |
129 @implementation CookiesWindowController | 129 @implementation CookiesWindowController |
130 | 130 |
| 131 @synthesize removeButtonEnabled = removeButtonEnabled_; |
131 @synthesize treeController = treeController_; | 132 @synthesize treeController = treeController_; |
132 | 133 |
133 - (id)initWithProfile:(Profile*)profile { | 134 - (id)initWithProfile:(Profile*)profile { |
134 DCHECK(profile); | 135 DCHECK(profile); |
135 NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"Cookies" | 136 NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"Cookies" |
136 ofType:@"nib"]; | 137 ofType:@"nib"]; |
137 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 138 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
138 profile_ = profile; | 139 profile_ = profile; |
139 | 140 |
140 [self loadTreeModelFromProfile]; | 141 [self loadTreeModelFromProfile]; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (![child isLeaf]) { | 256 if (![child isLeaf]) { |
256 NSOutlineView* outlineView = [notif object]; | 257 NSOutlineView* outlineView = [notif object]; |
257 // Tell the OutlineView to expand the NSTreeNode, not the model object. | 258 // Tell the OutlineView to expand the NSTreeNode, not the model object. |
258 children = [item childNodes]; | 259 children = [item childNodes]; |
259 DCHECK_EQ([children count], 1U); | 260 DCHECK_EQ([children count], 1U); |
260 [outlineView expandItem:[children lastObject]]; | 261 [outlineView expandItem:[children lastObject]]; |
261 } | 262 } |
262 } | 263 } |
263 } | 264 } |
264 | 265 |
| 266 - (void)outlineViewSelectionDidChange:(NSNotification*)notif { |
| 267 // Multi-selection should be disabled in the UI, but for sanity, double-check |
| 268 // that they can't do it here. |
| 269 NSUInteger count = [[treeController_ selectedObjects] count]; |
| 270 if (count != 1U) { |
| 271 DCHECK_LT(count, 1U) << "User was able to select more than one cookie node!"
; |
| 272 [self setRemoveButtonEnabled:NO]; |
| 273 return; |
| 274 } |
| 275 |
| 276 // Go through the selection's indexPath and make sure that the node that is |
| 277 // being referenced actually exists in the Cocoa model. |
| 278 NSIndexPath* selection = [treeController_ selectionIndexPath]; |
| 279 NSUInteger length = [selection length]; |
| 280 CocoaCookieTreeNode* node = [self cocoaTreeModel]; |
| 281 for (NSUInteger i = 0; i < length; ++i) { |
| 282 NSUInteger childIndex = [selection indexAtPosition:i]; |
| 283 if (childIndex >= [[node children] count]) { |
| 284 [self setRemoveButtonEnabled:NO]; |
| 285 return; |
| 286 } |
| 287 node = [[node children] objectAtIndex:childIndex]; |
| 288 } |
| 289 |
| 290 [self setRemoveButtonEnabled:YES]; |
| 291 } |
| 292 |
265 #pragma mark Unit Testing | 293 #pragma mark Unit Testing |
266 | 294 |
267 - (CookiesTreeModelObserverBridge*)modelObserver { | 295 - (CookiesTreeModelObserverBridge*)modelObserver { |
268 return modelObserver_.get(); | 296 return modelObserver_.get(); |
269 } | 297 } |
270 | 298 |
271 - (NSArray*)icons { | 299 - (NSArray*)icons { |
272 return icons_.get(); | 300 return icons_.get(); |
273 } | 301 } |
274 | 302 |
(...skipping 21 matching lines...) Expand all Loading... |
296 [icons_ addObject:rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER)]; | 324 [icons_ addObject:rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER)]; |
297 | 325 |
298 // Create the Cocoa model. | 326 // Create the Cocoa model. |
299 CookieTreeNode* root = static_cast<CookieTreeNode*>(treeModel_->GetRoot()); | 327 CookieTreeNode* root = static_cast<CookieTreeNode*>(treeModel_->GetRoot()); |
300 scoped_nsobject<CocoaCookieTreeNode> model( | 328 scoped_nsobject<CocoaCookieTreeNode> model( |
301 [[CocoaCookieTreeNode alloc] initWithNode:root]); | 329 [[CocoaCookieTreeNode alloc] initWithNode:root]); |
302 [self setCocoaTreeModel:model.get()]; // Takes ownership. | 330 [self setCocoaTreeModel:model.get()]; // Takes ownership. |
303 } | 331 } |
304 | 332 |
305 @end | 333 @end |
OLD | NEW |