| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // Add address sheet was dismissed. Non-zero |returnCode| indicates a save. | 311 // Add address sheet was dismissed. Non-zero |returnCode| indicates a save. |
| 312 - (void)addressAddDidEnd:(NSWindow*)sheet | 312 - (void)addressAddDidEnd:(NSWindow*)sheet |
| 313 returnCode:(int)returnCode | 313 returnCode:(int)returnCode |
| 314 contextInfo:(void*)contextInfo { | 314 contextInfo:(void*)contextInfo { |
| 315 DCHECK(contextInfo == NULL); | 315 DCHECK(contextInfo == NULL); |
| 316 | 316 |
| 317 if (returnCode) { | 317 if (returnCode) { |
| 318 // Create a new address and save it to the |profiles_| list. | 318 // Create a new address and save it to the |profiles_| list. |
| 319 AutoFillProfile newAddress(string16(), 0); | 319 AutoFillProfile newAddress(string16(), 0); |
| 320 [addressSheetController copyModelToProfile:&newAddress]; | 320 [addressSheetController copyModelToProfile:&newAddress]; |
| 321 profiles_.push_back(newAddress); | 321 if (!newAddress.IsEmpty()) { |
| 322 profiles_.push_back(newAddress); |
| 322 | 323 |
| 323 // Refresh the view based on new data. | 324 // Refresh the view based on new data. |
| 324 UpdateProfileLabels(&profiles_); | 325 UpdateProfileLabels(&profiles_); |
| 325 [tableView_ reloadData]; | 326 [tableView_ reloadData]; |
| 326 | 327 |
| 327 // Update the selection to the newly added item. | 328 // Update the selection to the newly added item. |
| 328 NSInteger row = [self rowFromProfileIndex:profiles_.size() - 1]; | 329 NSInteger row = [self rowFromProfileIndex:profiles_.size() - 1]; |
| 329 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] | 330 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] |
| 330 byExtendingSelection:NO]; | 331 byExtendingSelection:NO]; |
| 332 } |
| 331 } | 333 } |
| 332 [sheet orderOut:self]; | 334 [sheet orderOut:self]; |
| 333 addressSheetController.reset(nil); | 335 addressSheetController.reset(nil); |
| 334 } | 336 } |
| 335 | 337 |
| 336 // Add credit card sheet was dismissed. Non-zero |returnCode| indicates a save. | 338 // Add credit card sheet was dismissed. Non-zero |returnCode| indicates a save. |
| 337 - (void)creditCardAddDidEnd:(NSWindow *)sheet | 339 - (void)creditCardAddDidEnd:(NSWindow *)sheet |
| 338 returnCode:(int)returnCode | 340 returnCode:(int)returnCode |
| 339 contextInfo:(void *)contextInfo { | 341 contextInfo:(void *)contextInfo { |
| 340 DCHECK(contextInfo == NULL); | 342 DCHECK(contextInfo == NULL); |
| 341 | 343 |
| 342 if (returnCode) { | 344 if (returnCode) { |
| 343 // Create a new credit card and save it to the |creditCards_| list. | 345 // Create a new credit card and save it to the |creditCards_| list. |
| 344 CreditCard newCreditCard(string16(), 0); | 346 CreditCard newCreditCard(string16(), 0); |
| 345 [creditCardSheetController copyModelToCreditCard:&newCreditCard]; | 347 [creditCardSheetController copyModelToCreditCard:&newCreditCard]; |
| 346 creditCards_.push_back(newCreditCard); | 348 if (!newCreditCard.IsEmpty()) { |
| 349 creditCards_.push_back(newCreditCard); |
| 347 | 350 |
| 348 // Refresh the view based on new data. | 351 // Refresh the view based on new data. |
| 349 [tableView_ reloadData]; | 352 [tableView_ reloadData]; |
| 350 | 353 |
| 351 // Update the selection to the newly added item. | 354 // Update the selection to the newly added item. |
| 352 NSInteger row = [self rowFromCreditCardIndex:creditCards_.size() - 1]; | 355 NSInteger row = [self rowFromCreditCardIndex:creditCards_.size() - 1]; |
| 353 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] | 356 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] |
| 354 byExtendingSelection:NO]; | 357 byExtendingSelection:NO]; |
| 358 } |
| 355 } | 359 } |
| 356 [sheet orderOut:self]; | 360 [sheet orderOut:self]; |
| 357 creditCardSheetController.reset(nil); | 361 creditCardSheetController.reset(nil); |
| 358 } | 362 } |
| 359 | 363 |
| 360 // Deletes selected items; either addresses, credit cards, or a mixture of the | 364 // Deletes selected items; either addresses, credit cards, or a mixture of the |
| 361 // two depending on the items selected. | 365 // two depending on the items selected. |
| 362 - (IBAction)deleteSelection:(id)sender { | 366 - (IBAction)deleteSelection:(id)sender { |
| 363 NSIndexSet* selection = [tableView_ selectedRowIndexes]; | 367 NSIndexSet* selection = [tableView_ selectedRowIndexes]; |
| 364 NSInteger selectedRow = [tableView_ selectedRow]; | 368 NSInteger selectedRow = [tableView_ selectedRow]; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 451 } |
| 448 | 452 |
| 449 // Edit address sheet was dismissed. Non-zero |returnCode| indicates a save. | 453 // Edit address sheet was dismissed. Non-zero |returnCode| indicates a save. |
| 450 - (void)addressEditDidEnd:(NSWindow *)sheet | 454 - (void)addressEditDidEnd:(NSWindow *)sheet |
| 451 returnCode:(int)returnCode | 455 returnCode:(int)returnCode |
| 452 contextInfo:(void *)contextInfo { | 456 contextInfo:(void *)contextInfo { |
| 453 DCHECK(contextInfo != NULL); | 457 DCHECK(contextInfo != NULL); |
| 454 if (returnCode) { | 458 if (returnCode) { |
| 455 AutoFillProfile* profile = static_cast<AutoFillProfile*>(contextInfo); | 459 AutoFillProfile* profile = static_cast<AutoFillProfile*>(contextInfo); |
| 456 [addressSheetController copyModelToProfile:profile]; | 460 [addressSheetController copyModelToProfile:profile]; |
| 461 |
| 462 if (profile->IsEmpty()) |
| 463 [tableView_ deselectAll:self]; |
| 464 profiles_.erase( |
| 465 std::remove_if(profiles_.begin(), profiles_.end(), |
| 466 std::mem_fun_ref(&AutoFillProfile::IsEmpty)), |
| 467 profiles_.end()); |
| 468 |
| 457 UpdateProfileLabels(&profiles_); | 469 UpdateProfileLabels(&profiles_); |
| 458 [tableView_ reloadData]; | 470 [tableView_ reloadData]; |
| 459 } | 471 } |
| 460 [sheet orderOut:self]; | 472 [sheet orderOut:self]; |
| 461 addressSheetController.reset(nil); | 473 addressSheetController.reset(nil); |
| 462 } | 474 } |
| 463 | 475 |
| 464 // Edit credit card sheet was dismissed. Non-zero |returnCode| indicates a | 476 // Edit credit card sheet was dismissed. Non-zero |returnCode| indicates a |
| 465 // save. | 477 // save. |
| 466 - (void)creditCardEditDidEnd:(NSWindow *)sheet | 478 - (void)creditCardEditDidEnd:(NSWindow *)sheet |
| 467 returnCode:(int)returnCode | 479 returnCode:(int)returnCode |
| 468 contextInfo:(void *)contextInfo { | 480 contextInfo:(void *)contextInfo { |
| 469 DCHECK(contextInfo != NULL); | 481 DCHECK(contextInfo != NULL); |
| 470 if (returnCode) { | 482 if (returnCode) { |
| 471 CreditCard* creditCard = static_cast<CreditCard*>(contextInfo); | 483 CreditCard* creditCard = static_cast<CreditCard*>(contextInfo); |
| 472 [creditCardSheetController copyModelToCreditCard:creditCard]; | 484 [creditCardSheetController copyModelToCreditCard:creditCard]; |
| 485 |
| 486 if (creditCard->IsEmpty()) |
| 487 [tableView_ deselectAll:self]; |
| 488 creditCards_.erase( |
| 489 std::remove_if( |
| 490 creditCards_.begin(), creditCards_.end(), |
| 491 std::mem_fun_ref(&CreditCard::IsEmpty)), |
| 492 creditCards_.end()); |
| 473 [tableView_ reloadData]; | 493 [tableView_ reloadData]; |
| 474 } | 494 } |
| 475 [sheet orderOut:self]; | 495 [sheet orderOut:self]; |
| 476 creditCardSheetController.reset(nil); | 496 creditCardSheetController.reset(nil); |
| 477 } | 497 } |
| 478 | 498 |
| 479 // NSTableView Delegate method. | 499 // NSTableView Delegate method. |
| 480 - (BOOL)tableView:(NSTableView *)tableView isGroupRow:(NSInteger)row { | 500 - (BOOL)tableView:(NSTableView *)tableView isGroupRow:(NSInteger)row { |
| 481 if ([self isProfileGroupRow:row] || [self isCreditCardGroupRow:row]) | 501 if ([self isProfileGroupRow:row] || [self isCreditCardGroupRow:row]) |
| 482 return YES; | 502 return YES; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 if (!image) { | 828 if (!image) { |
| 809 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); | 829 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); |
| 810 DCHECK(image); | 830 DCHECK(image); |
| 811 return image; | 831 return image; |
| 812 } | 832 } |
| 813 | 833 |
| 814 return nil; | 834 return nil; |
| 815 } | 835 } |
| 816 | 836 |
| 817 @end | 837 @end |
| OLD | NEW |