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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 creditCards:personal_data_manager_->credit_cards()]; | 184 creditCards:personal_data_manager_->credit_cards()]; |
185 } | 185 } |
186 | 186 |
187 } // namespace AutoFillDialogControllerInternal | 187 } // namespace AutoFillDialogControllerInternal |
188 | 188 |
189 @implementation AutoFillDialogController | 189 @implementation AutoFillDialogController |
190 | 190 |
191 @synthesize autoFillEnabled = autoFillEnabled_; | 191 @synthesize autoFillEnabled = autoFillEnabled_; |
192 @synthesize auxiliaryEnabled = auxiliaryEnabled_; | 192 @synthesize auxiliaryEnabled = auxiliaryEnabled_; |
193 @synthesize itemIsSelected = itemIsSelected_; | 193 @synthesize itemIsSelected = itemIsSelected_; |
194 @synthesize multipleSelected = multipleSelected_; | |
194 | 195 |
195 + (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer | 196 + (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer |
196 profile:(Profile*)profile | 197 profile:(Profile*)profile |
197 importedProfile:(AutoFillProfile*) importedProfile | 198 importedProfile:(AutoFillProfile*) importedProfile |
198 importedCreditCard:(CreditCard*) importedCreditCard { | 199 importedCreditCard:(CreditCard*) importedCreditCard { |
199 AutoFillDialogController* controller = | 200 AutoFillDialogController* controller = |
200 [AutoFillDialogController controllerWithObserver:observer | 201 [AutoFillDialogController controllerWithObserver:observer |
201 profile:profile | 202 profile:profile |
202 importedProfile:importedProfile | 203 importedProfile:importedProfile |
203 importedCreditCard:importedCreditCard]; | 204 importedCreditCard:importedCreditCard]; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 | 350 |
350 // Update the selection to the newly added item. | 351 // Update the selection to the newly added item. |
351 NSInteger row = [self rowFromCreditCardIndex:creditCards_.size() - 1]; | 352 NSInteger row = [self rowFromCreditCardIndex:creditCards_.size() - 1]; |
352 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] | 353 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] |
353 byExtendingSelection:NO]; | 354 byExtendingSelection:NO]; |
354 } | 355 } |
355 [sheet orderOut:self]; | 356 [sheet orderOut:self]; |
356 creditCardSheetController.reset(nil); | 357 creditCardSheetController.reset(nil); |
357 } | 358 } |
358 | 359 |
359 // Deletes selected item, either address or credit card depending on the item | 360 // Deletes selected items; either addresses, credit cards, or a mixture of the |
360 // selected. | 361 // two depending on the items selected. |
361 - (IBAction)deleteSelection:(id)sender { | 362 - (IBAction)deleteSelection:(id)sender { |
363 NSIndexSet* selectedRows = [tableView_ selectedRowIndexes]; | |
362 NSInteger selectedRow = [tableView_ selectedRow]; | 364 NSInteger selectedRow = [tableView_ selectedRow]; |
363 if ([self isProfileRow:selectedRow]) { | 365 NSInteger rowCount = [tableView_ numberOfRows]; |
364 profiles_.erase(profiles_.begin() + [self profileIndexFromRow:selectedRow]); | |
365 | 366 |
366 // Select the previous row if possible, else current row, else deselect all. | 367 // Loop through from last to first deleting selected items as we go. |
367 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 368 for (NSInteger i = rowCount-1; i>=0; --i) { |
Nico
2010/07/20 03:18:20
You want:
for (NSUInteger i = [selection last
| |
368 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] | 369 if (![selectedRows containsIndex:i]) |
369 byExtendingSelection:NO]; | 370 continue; |
370 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { | 371 |
371 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] | 372 // We keep track of the "top most" selection in the list so we know where |
372 byExtendingSelection:NO]; | 373 // to to set new selection below. |
373 } else { | 374 if (i < selectedRow) |
374 [tableView_ selectRowIndexes:[NSIndexSet indexSet] | 375 selectedRow = i; |
375 byExtendingSelection:NO]; | 376 |
377 if ([self isProfileRow:i]) { | |
378 profiles_.erase( | |
379 profiles_.begin() + [self profileIndexFromRow:i]); | |
380 } else if ([self isCreditCardRow:i]) { | |
381 creditCards_.erase( | |
382 creditCards_.begin() + [self creditCardIndexFromRow:i]); | |
376 } | 383 } |
377 UpdateProfileLabels(&profiles_); | 384 } |
378 [tableView_ reloadData]; | |
379 } else if ([self isCreditCardRow:selectedRow]) { | |
380 creditCards_.erase( | |
381 creditCards_.begin() + [self creditCardIndexFromRow:selectedRow]); | |
382 | 385 |
383 // Select the previous row if possible, else current row, else deselect all. | 386 // Select the previous row if possible, else current row, else deselect all. |
384 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 387 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { |
385 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] | 388 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] |
386 byExtendingSelection:NO]; | 389 byExtendingSelection:NO]; |
387 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { | 390 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { |
388 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] | 391 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] |
389 byExtendingSelection:NO]; | 392 byExtendingSelection:NO]; |
390 } else { | 393 } else { |
391 [tableView_ selectRowIndexes:[NSIndexSet indexSet] | 394 [tableView_ selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO]; |
392 byExtendingSelection:NO]; | |
393 } | |
394 [tableView_ reloadData]; | |
395 } | 395 } |
396 | |
397 UpdateProfileLabels(&profiles_); | |
398 [tableView_ reloadData]; | |
396 } | 399 } |
397 | 400 |
398 // Edits the selected item, either address or credit card depending on the item | 401 // Edits the selected item, either address or credit card depending on the item |
399 // selected. | 402 // selected. |
400 - (IBAction)editSelection:(id)sender { | 403 - (IBAction)editSelection:(id)sender { |
401 NSInteger selectedRow = [tableView_ selectedRow]; | 404 NSInteger selectedRow = [tableView_ selectedRow]; |
402 if ([self isProfileRow:selectedRow]) { | 405 if ([self isProfileRow:selectedRow]) { |
403 if (!addressSheetController.get()) { | 406 if (!addressSheetController.get()) { |
404 int i = [self profileIndexFromRow:selectedRow]; | 407 int i = [self profileIndexFromRow:selectedRow]; |
405 | 408 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 creditCards_[ | 538 creditCards_[ |
536 [self creditCardIndexFromRow:row]].PreviewSummary()); | 539 [self creditCardIndexFromRow:row]].PreviewSummary()); |
537 } | 540 } |
538 | 541 |
539 return @""; | 542 return @""; |
540 } | 543 } |
541 | 544 |
542 return @""; | 545 return @""; |
543 } | 546 } |
544 | 547 |
545 // We implement this delegate method to update our |itemIsSelected| property. | 548 // We implement this delegate method to update our |itemIsSelected| and |
549 // |multipleSelected| properties. | |
546 // The "Edit..." and "Remove" buttons' enabled state depends on having a | 550 // The "Edit..." and "Remove" buttons' enabled state depends on having a |
547 // valid selection in the table. | 551 // valid selection in the table. The "Edit..." button depends on having |
552 // exactly one item selected. | |
548 - (void)tableViewSelectionDidChange:(NSNotification *)aNotification { | 553 - (void)tableViewSelectionDidChange:(NSNotification *)aNotification { |
549 if ([tableView_ selectedRow] >= 0) | 554 if ([tableView_ selectedRow] >= 0) |
550 [self setItemIsSelected:YES]; | 555 [self setItemIsSelected:YES]; |
551 else | 556 else |
552 [self setItemIsSelected:NO]; | 557 [self setItemIsSelected:NO]; |
558 | |
559 [self setMultipleSelected:([[tableView_ selectedRowIndexes] count] > 1UL)]; | |
553 } | 560 } |
554 | 561 |
555 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { | 562 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { |
556 if (tableView == tableView_) { | 563 if (tableView == tableView_) { |
557 // 1 section header, the profiles, 1 section header, the credit cards. | 564 // 1 section header, the profiles, 1 section header, the credit cards. |
558 return 1 + profiles_.size() + 1 + creditCards_.size(); | 565 return 1 + profiles_.size() + 1 + creditCards_.size(); |
559 } | 566 } |
560 | 567 |
561 return 0; | 568 return 0; |
562 } | 569 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 [self rowFromProfileIndex:i]] | 654 [self rowFromProfileIndex:i]] |
648 byExtendingSelection:NO]; | 655 byExtendingSelection:NO]; |
649 } | 656 } |
650 | 657 |
651 - (void)selectCreditCardAtIndex:(size_t)i { | 658 - (void)selectCreditCardAtIndex:(size_t)i { |
652 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex: | 659 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex: |
653 [self rowFromCreditCardIndex:i]] | 660 [self rowFromCreditCardIndex:i]] |
654 byExtendingSelection:NO]; | 661 byExtendingSelection:NO]; |
655 } | 662 } |
656 | 663 |
664 - (void)addSelectedAddressAtIndex:(size_t)i { | |
665 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex: | |
666 [self rowFromProfileIndex:i]] | |
667 byExtendingSelection:YES]; | |
668 } | |
669 | |
670 - (void)addSelectedCreditCardAtIndex:(size_t)i { | |
671 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex: | |
672 [self rowFromCreditCardIndex:i]] | |
673 byExtendingSelection:YES]; | |
674 } | |
675 | |
676 - (BOOL)editButtonEnabled { | |
677 return [editButton_ isEnabled]; | |
678 } | |
679 | |
657 @end | 680 @end |
658 | 681 |
659 @implementation AutoFillDialogController (PrivateMethods) | 682 @implementation AutoFillDialogController (PrivateMethods) |
660 | 683 |
661 // Run application modal. | 684 // Run application modal. |
662 - (void)runModalDialog { | 685 - (void)runModalDialog { |
663 // Use stored window geometry if it exists. | 686 // Use stored window geometry if it exists. |
664 if (g_browser_process && g_browser_process->local_state()) { | 687 if (g_browser_process && g_browser_process->local_state()) { |
665 sizeSaver_.reset([[WindowSizeAutosaver alloc] | 688 sizeSaver_.reset([[WindowSizeAutosaver alloc] |
666 initWithWindow:[self window] | 689 initWithWindow:[self window] |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 if (!image) { | 811 if (!image) { |
789 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); | 812 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); |
790 DCHECK(image); | 813 DCHECK(image); |
791 return image; | 814 return image; |
792 } | 815 } |
793 | 816 |
794 return nil; | 817 return nil; |
795 } | 818 } |
796 | 819 |
797 @end | 820 @end |
OLD | NEW |