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/cocoa/geolocation_exceptions_window_controller.h" | 5 #import "chrome/browser/cocoa/geolocation_exceptions_window_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
10 #include "app/table_model_observer.h" | 10 #include "app/table_model_observer.h" |
11 #import "base/mac_util.h" | 11 #import "base/mac_util.h" |
12 #import "base/scoped_nsobject.h" | 12 #import "base/scoped_nsobject.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 14 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
15 #include "chrome/browser/geolocation/geolocation_content_settings_table_model.h" | 15 #include "chrome/browser/geolocation/geolocation_content_settings_table_model.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 17 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
18 | 18 |
19 @interface GeolocationExceptionsWindowController (Private) | 19 @interface GeolocationExceptionsWindowController (Private) |
20 - (id)initWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap; | 20 - (id)initWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap; |
21 - (void)selectedRemovableIndices:(std::set<int>*)indices; | 21 - (void)selectedRows:(GeolocationContentSettingsTableModel::Rows*)rows; |
22 - (int)countSelectedRemovable; | |
23 - (void)adjustEditingButtons; | 22 - (void)adjustEditingButtons; |
24 - (void)modelDidChange; | 23 - (void)modelDidChange; |
25 @end | 24 @end |
26 | 25 |
27 // Observer for the geolocation table model. | 26 // Observer for the geolocation table model. |
28 class GeolocationObserverBridge : public TableModelObserver { | 27 class GeolocationObserverBridge : public TableModelObserver { |
29 public: | 28 public: |
30 GeolocationObserverBridge(GeolocationExceptionsWindowController* controller) | 29 GeolocationObserverBridge(GeolocationExceptionsWindowController* controller) |
31 : controller_(controller) {} | 30 : controller_(controller) {} |
32 virtual ~GeolocationObserverBridge() {} | 31 virtual ~GeolocationObserverBridge() {} |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Delete deletes. | 127 // Delete deletes. |
129 if ([[tableView_ selectedRowIndexes] count] > 0) | 128 if ([[tableView_ selectedRowIndexes] count] > 0) |
130 [self removeException:self]; | 129 [self removeException:self]; |
131 return; | 130 return; |
132 } | 131 } |
133 } | 132 } |
134 [super keyDown:event]; | 133 [super keyDown:event]; |
135 } | 134 } |
136 | 135 |
137 - (IBAction)removeException:(id)sender { | 136 - (IBAction)removeException:(id)sender { |
138 std::set<int> indices; | 137 GeolocationContentSettingsTableModel::Rows rows; |
139 [self selectedRemovableIndices:&indices]; | 138 [self selectedRows:&rows]; |
140 | 139 model_->RemoveExceptions(rows); |
141 for (std::set<int>::reverse_iterator i = indices.rbegin(); | |
142 i != indices.rend(); ++i) { | |
143 model_->RemoveException(*i); | |
144 } | |
145 } | 140 } |
146 | 141 |
147 - (IBAction)removeAllExceptions:(id)sender { | 142 - (IBAction)removeAllExceptions:(id)sender { |
148 model_->RemoveAll(); | 143 model_->RemoveAll(); |
149 } | 144 } |
150 | 145 |
151 // Table View Data Source ----------------------------------------------------- | 146 // Table View Data Source ----------------------------------------------------- |
152 | 147 |
153 - (NSInteger)numberOfRowsInTableView:(NSTableView*)table { | 148 - (NSInteger)numberOfRowsInTableView:(NSTableView*)table { |
154 return model_->RowCount(); | 149 return model_->RowCount(); |
(...skipping 18 matching lines...) Expand all Loading... |
173 | 168 |
174 // Table View Delegate -------------------------------------------------------- | 169 // Table View Delegate -------------------------------------------------------- |
175 | 170 |
176 // When the selection in the table view changes, we need to adjust buttons. | 171 // When the selection in the table view changes, we need to adjust buttons. |
177 - (void)tableViewSelectionDidChange:(NSNotification*)notification { | 172 - (void)tableViewSelectionDidChange:(NSNotification*)notification { |
178 [self adjustEditingButtons]; | 173 [self adjustEditingButtons]; |
179 } | 174 } |
180 | 175 |
181 // Private -------------------------------------------------------------------- | 176 // Private -------------------------------------------------------------------- |
182 | 177 |
183 // Returns the indices of all selected rows that are removable. | 178 // Returns the selected rows. |
184 - (void)selectedRemovableIndices:(std::set<int>*)indices { | 179 - (void)selectedRows:(GeolocationContentSettingsTableModel::Rows*)rows { |
185 NSIndexSet* selection = [tableView_ selectedRowIndexes]; | 180 NSIndexSet* selection = [tableView_ selectedRowIndexes]; |
186 for (NSUInteger index = [selection lastIndex]; index != NSNotFound; | 181 for (NSUInteger index = [selection lastIndex]; index != NSNotFound; |
187 index = [selection indexLessThanIndex:index]) { | 182 index = [selection indexLessThanIndex:index]) |
188 if (model_->CanRemoveException(index)) | 183 rows->insert(index); |
189 indices->insert(index); | |
190 } | |
191 } | |
192 | |
193 // Returns how many of the selected rows are removable. | |
194 - (int)countSelectedRemovable { | |
195 std::set<int> indices; | |
196 [self selectedRemovableIndices:&indices]; | |
197 return indices.size(); | |
198 } | 184 } |
199 | 185 |
200 // This method appropriately sets the enabled states on the table's editing | 186 // This method appropriately sets the enabled states on the table's editing |
201 // buttons. | 187 // buttons. |
202 - (void)adjustEditingButtons { | 188 - (void)adjustEditingButtons { |
203 [removeButton_ setEnabled:([self countSelectedRemovable] > 0)]; | 189 GeolocationContentSettingsTableModel::Rows rows; |
| 190 [self selectedRows:&rows]; |
| 191 [removeButton_ setEnabled:model_->CanRemoveExceptions(rows)]; |
204 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)]; | 192 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)]; |
205 } | 193 } |
206 | 194 |
207 - (void)modelDidChange { | 195 - (void)modelDidChange { |
208 [tableView_ reloadData]; | 196 [tableView_ reloadData]; |
209 [self adjustEditingButtons]; | 197 [self adjustEditingButtons]; |
210 } | 198 } |
211 | 199 |
212 @end | 200 @end |
OLD | NEW |