| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/cocoa/extensions/chooser_dialog_cocoa_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #import "chrome/browser/ui/cocoa/chooser_content_view.h" | 9 #import "chrome/browser/ui/cocoa/chooser_content_view.h" |
| 10 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa.h" | 10 #import "chrome/browser/ui/cocoa/extensions/chooser_dialog_cocoa.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 - (void)onOptionsInitialized { | 103 - (void)onOptionsInitialized { |
| 104 [self updateTableView]; | 104 [self updateTableView]; |
| 105 } | 105 } |
| 106 | 106 |
| 107 - (void)onOptionAdded:(NSInteger)index { | 107 - (void)onOptionAdded:(NSInteger)index { |
| 108 [self updateTableView]; | 108 [self updateTableView]; |
| 109 } | 109 } |
| 110 | 110 |
| 111 - (void)onOptionRemoved:(NSInteger)index { | 111 - (void)onOptionRemoved:(NSInteger)index { |
| 112 // |tableView_| will automatically selects the next item if the current | 112 // |tableView_| will automatically select the removed item's next item. |
| 113 // item is removed, so here it tracks if the removed item is the item | 113 // So here it tracks if the removed item is the item that was currently |
| 114 // that was previously selected, if so, deselect it. | 114 // selected, if so, deselect it. Also if the removed item is before the |
| 115 if ([tableView_ selectedRow] == index) | 115 // currently selected item, the currently selected item's index needs to |
| 116 // be adjusted by one. |
| 117 NSInteger selectedRow = [tableView_ selectedRow]; |
| 118 if (selectedRow == index) |
| 116 [tableView_ deselectRow:index]; | 119 [tableView_ deselectRow:index]; |
| 120 else if (selectedRow > index) |
| 121 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow - 1] |
| 122 byExtendingSelection:NO]; |
| 117 | 123 |
| 118 [self updateTableView]; | 124 [self updateTableView]; |
| 119 } | 125 } |
| 120 | 126 |
| 121 - (void)updateTableView { | 127 - (void)updateTableView { |
| 122 [tableView_ setEnabled:chooserController_->NumOptions() > 0]; | 128 [tableView_ setEnabled:chooserController_->NumOptions() > 0]; |
| 123 [tableView_ reloadData]; | 129 [tableView_ reloadData]; |
| 124 } | 130 } |
| 125 | 131 |
| 126 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { | 132 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 140 | 146 |
| 141 - (void)onHelpPressed:(id)sender { | 147 - (void)onHelpPressed:(id)sender { |
| 142 chooserController_->OpenHelpCenterUrl(); | 148 chooserController_->OpenHelpCenterUrl(); |
| 143 } | 149 } |
| 144 | 150 |
| 145 - (ChooserContentView*)chooserContentView { | 151 - (ChooserContentView*)chooserContentView { |
| 146 return chooserContentView_.get(); | 152 return chooserContentView_.get(); |
| 147 } | 153 } |
| 148 | 154 |
| 149 @end | 155 @end |
| OLD | NEW |