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/autofill/autofill_dialog_controller_mac.h" | 5 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" |
6 #include "app/l10n_util.h" | 6 #include "app/l10n_util.h" |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] | 353 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] |
354 byExtendingSelection:NO]; | 354 byExtendingSelection:NO]; |
355 } | 355 } |
356 [sheet orderOut:self]; | 356 [sheet orderOut:self]; |
357 creditCardSheetController.reset(nil); | 357 creditCardSheetController.reset(nil); |
358 } | 358 } |
359 | 359 |
360 // Deletes selected items; either addresses, credit cards, or a mixture of the | 360 // Deletes selected items; either addresses, credit cards, or a mixture of the |
361 // two depending on the items selected. | 361 // two depending on the items selected. |
362 - (IBAction)deleteSelection:(id)sender { | 362 - (IBAction)deleteSelection:(id)sender { |
363 NSIndexSet* selectedRows = [tableView_ selectedRowIndexes]; | 363 NSIndexSet* selection = [tableView_ selectedRowIndexes]; |
364 NSInteger selectedRow = [tableView_ selectedRow]; | 364 NSInteger selectedRow = [tableView_ selectedRow]; |
365 NSInteger rowCount = [tableView_ numberOfRows]; | |
366 | 365 |
367 // Loop through from last to first deleting selected items as we go. | 366 // Loop through from last to first deleting selected items as we go. |
368 for (NSInteger i = rowCount-1; i>=0; --i) { | 367 for (NSUInteger i = [selection lastIndex]; |
369 if (![selectedRows containsIndex:i]) | 368 i != NSNotFound; |
370 continue; | 369 i = [selection indexLessThanIndex:i]) { |
371 | |
372 // We keep track of the "top most" selection in the list so we know where | 370 // We keep track of the "top most" selection in the list so we know where |
373 // to to set new selection below. | 371 // to set new selection below. |
374 if (i < selectedRow) | 372 selectedRow = i; |
375 selectedRow = i; | |
376 | 373 |
377 if ([self isProfileRow:i]) { | 374 if ([self isProfileRow:i]) { |
378 profiles_.erase( | 375 profiles_.erase( |
379 profiles_.begin() + [self profileIndexFromRow:i]); | 376 profiles_.begin() + [self profileIndexFromRow:i]); |
380 } else if ([self isCreditCardRow:i]) { | 377 } else if ([self isCreditCardRow:i]) { |
381 creditCards_.erase( | 378 creditCards_.erase( |
382 creditCards_.begin() + [self creditCardIndexFromRow:i]); | 379 creditCards_.begin() + [self creditCardIndexFromRow:i]); |
383 } | 380 } |
384 } | 381 } |
385 | 382 |
386 // Select the previous row if possible, else current row, else deselect all. | 383 // Select the previous row if possible, else current row, else deselect all. |
387 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 384 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { |
388 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] | 385 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] |
389 byExtendingSelection:NO]; | 386 byExtendingSelection:NO]; |
390 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { | 387 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { |
391 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] | 388 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] |
392 byExtendingSelection:NO]; | 389 byExtendingSelection:NO]; |
393 } else { | 390 } else { |
394 [tableView_ selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO]; | 391 [tableView_ deselectAll:self]; |
395 } | 392 } |
396 | 393 |
397 UpdateProfileLabels(&profiles_); | 394 UpdateProfileLabels(&profiles_); |
398 [tableView_ reloadData]; | 395 [tableView_ reloadData]; |
399 } | 396 } |
400 | 397 |
401 // Edits the selected item, either address or credit card depending on the item | 398 // Edits the selected item, either address or credit card depending on the item |
402 // selected. | 399 // selected. |
403 - (IBAction)editSelection:(id)sender { | 400 - (IBAction)editSelection:(id)sender { |
404 NSInteger selectedRow = [tableView_ selectedRow]; | 401 NSInteger selectedRow = [tableView_ selectedRow]; |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 if (!image) { | 808 if (!image) { |
812 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); | 809 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); |
813 DCHECK(image); | 810 DCHECK(image); |
814 return image; | 811 return image; |
815 } | 812 } |
816 | 813 |
817 return nil; | 814 return nil; |
818 } | 815 } |
819 | 816 |
820 @end | 817 @end |
OLD | NEW |