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

Unified Diff: chrome/browser/autofill/autofill_dialog_controller_mac.mm

Issue 3039014: AutoFill Profiles dialog handles multi-select and delete on Mac (Closed)
Patch Set: Merge with trunk. Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_dialog_controller_mac.mm
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
index 377e1cda7ada808bf8c33e782dbc00aa8c134f86..d0e16ae4cdc81c258a55013aaade9f570f74785e 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
@@ -191,6 +191,7 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
@synthesize autoFillEnabled = autoFillEnabled_;
@synthesize auxiliaryEnabled = auxiliaryEnabled_;
@synthesize itemIsSelected = itemIsSelected_;
+@synthesize multipleSelected = multipleSelected_;
+ (void)showAutoFillDialogWithObserver:(AutoFillDialogObserver*)observer
profile:(Profile*)profile
@@ -356,43 +357,45 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
creditCardSheetController.reset(nil);
}
-// Deletes selected item, either address or credit card depending on the item
-// selected.
+// Deletes selected items; either addresses, credit cards, or a mixture of the
+// two depending on the items selected.
- (IBAction)deleteSelection:(id)sender {
+ NSIndexSet* selectedRows = [tableView_ selectedRowIndexes];
NSInteger selectedRow = [tableView_ selectedRow];
- if ([self isProfileRow:selectedRow]) {
- profiles_.erase(profiles_.begin() + [self profileIndexFromRow:selectedRow]);
-
- // Select the previous row if possible, else current row, else deselect all.
- if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
- [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
- byExtendingSelection:NO];
- } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
- [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
- byExtendingSelection:NO];
- } else {
- [tableView_ selectRowIndexes:[NSIndexSet indexSet]
- byExtendingSelection:NO];
+ NSInteger rowCount = [tableView_ numberOfRows];
+
+ // Loop through from last to first deleting selected items as we go.
+ for (NSInteger i = rowCount-1; i>=0; --i) {
Nico 2010/07/20 03:18:20 You want: for (NSUInteger i = [selection last
+ if (![selectedRows containsIndex:i])
+ continue;
+
+ // We keep track of the "top most" selection in the list so we know where
+ // to to set new selection below.
+ if (i < selectedRow)
+ selectedRow = i;
+
+ if ([self isProfileRow:i]) {
+ profiles_.erase(
+ profiles_.begin() + [self profileIndexFromRow:i]);
+ } else if ([self isCreditCardRow:i]) {
+ creditCards_.erase(
+ creditCards_.begin() + [self creditCardIndexFromRow:i]);
}
- UpdateProfileLabels(&profiles_);
- [tableView_ reloadData];
- } else if ([self isCreditCardRow:selectedRow]) {
- creditCards_.erase(
- creditCards_.begin() + [self creditCardIndexFromRow:selectedRow]);
-
- // Select the previous row if possible, else current row, else deselect all.
- if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
- [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
- byExtendingSelection:NO];
- } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
- [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
- byExtendingSelection:NO];
- } else {
- [tableView_ selectRowIndexes:[NSIndexSet indexSet]
- byExtendingSelection:NO];
- }
- [tableView_ reloadData];
}
+
+ // Select the previous row if possible, else current row, else deselect all.
+ if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
+ byExtendingSelection:NO];
+ } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
+ byExtendingSelection:NO];
+ } else {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
+ }
+
+ UpdateProfileLabels(&profiles_);
+ [tableView_ reloadData];
}
// Edits the selected item, either address or credit card depending on the item
@@ -542,14 +545,18 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
return @"";
}
-// We implement this delegate method to update our |itemIsSelected| property.
+// We implement this delegate method to update our |itemIsSelected| and
+// |multipleSelected| properties.
// The "Edit..." and "Remove" buttons' enabled state depends on having a
-// valid selection in the table.
+// valid selection in the table. The "Edit..." button depends on having
+// exactly one item selected.
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
if ([tableView_ selectedRow] >= 0)
[self setItemIsSelected:YES];
else
[self setItemIsSelected:NO];
+
+ [self setMultipleSelected:([[tableView_ selectedRowIndexes] count] > 1UL)];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
@@ -654,6 +661,22 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() {
byExtendingSelection:NO];
}
+- (void)addSelectedAddressAtIndex:(size_t)i {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:
+ [self rowFromProfileIndex:i]]
+ byExtendingSelection:YES];
+}
+
+- (void)addSelectedCreditCardAtIndex:(size_t)i {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:
+ [self rowFromCreditCardIndex:i]]
+ byExtendingSelection:YES];
+}
+
+- (BOOL)editButtonEnabled {
+ return [editButton_ isEnabled];
+}
+
@end
@implementation AutoFillDialogController (PrivateMethods)

Powered by Google App Engine
This is Rietveld 408576698