| 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" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 | 121 |
| 122 - (void)keyDown:(NSEvent*)event { | 122 - (void)keyDown:(NSEvent*)event { |
| 123 NSString* chars = [event charactersIgnoringModifiers]; | 123 NSString* chars = [event charactersIgnoringModifiers]; |
| 124 if ([chars length] == 1) { | 124 if ([chars length] == 1) { |
| 125 switch ([chars characterAtIndex:0]) { | 125 switch ([chars characterAtIndex:0]) { |
| 126 case NSDeleteCharacter: | 126 case NSDeleteCharacter: |
| 127 case NSDeleteFunctionKey: | 127 case NSDeleteFunctionKey: |
| 128 // Delete deletes. | 128 // Delete deletes. |
| 129 if ([[tableView_ selectedRowIndexes] count] > 0) | 129 if ([[tableView_ selectedRowIndexes] count] > 0) |
| 130 [self removeException:self]; | 130 [self removeRow:self]; |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 [super keyDown:event]; | 134 [super keyDown:event]; |
| 135 } | 135 } |
| 136 | 136 |
| 137 - (void)attachSheetTo:(NSWindow*)window { | 137 - (void)attachSheetTo:(NSWindow*)window { |
| 138 [NSApp beginSheet:[self window] | 138 [NSApp beginSheet:[self window] |
| 139 modalForWindow:window | 139 modalForWindow:window |
| 140 modalDelegate:self | 140 modalDelegate:self |
| 141 didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) | 141 didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) |
| 142 contextInfo:nil]; | 142 contextInfo:nil]; |
| 143 } | 143 } |
| 144 | 144 |
| 145 - (void)sheetDidEnd:(NSWindow*)sheet | 145 - (void)sheetDidEnd:(NSWindow*)sheet |
| 146 returnCode:(NSInteger)returnCode | 146 returnCode:(NSInteger)returnCode |
| 147 contextInfo:(void*)context { | 147 contextInfo:(void*)context { |
| 148 [sheet close]; | 148 [sheet close]; |
| 149 [sheet orderOut:self]; | 149 [sheet orderOut:self]; |
| 150 } | 150 } |
| 151 | 151 |
| 152 - (IBAction)closeSheet:(id)sender { | 152 - (IBAction)closeSheet:(id)sender { |
| 153 [NSApp endSheet:[self window]]; | 153 [NSApp endSheet:[self window]]; |
| 154 } | 154 } |
| 155 | 155 |
| 156 - (IBAction)removeException:(id)sender { | 156 - (IBAction)removeRow:(id)sender { |
| 157 GeolocationExceptionsTableModel::Rows rows; | 157 GeolocationExceptionsTableModel::Rows rows; |
| 158 [self selectedRows:&rows]; | 158 [self selectedRows:&rows]; |
| 159 model_->RemoveExceptions(rows); | 159 model_->RemoveRows(rows); |
| 160 } | 160 } |
| 161 | 161 |
| 162 - (IBAction)removeAllExceptions:(id)sender { | 162 - (IBAction)removeAll:(id)sender { |
| 163 model_->RemoveAll(); | 163 model_->RemoveAll(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Table View Data Source ----------------------------------------------------- | 166 // Table View Data Source ----------------------------------------------------- |
| 167 | 167 |
| 168 - (NSInteger)numberOfRowsInTableView:(NSTableView*)table { | 168 - (NSInteger)numberOfRowsInTableView:(NSTableView*)table { |
| 169 return model_->RowCount(); | 169 return model_->RowCount(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 - (id)tableView:(NSTableView*)tv | 172 - (id)tableView:(NSTableView*)tv |
| (...skipping 28 matching lines...) Expand all Loading... |
| 201 for (NSUInteger index = [selection lastIndex]; index != NSNotFound; | 201 for (NSUInteger index = [selection lastIndex]; index != NSNotFound; |
| 202 index = [selection indexLessThanIndex:index]) | 202 index = [selection indexLessThanIndex:index]) |
| 203 rows->insert(index); | 203 rows->insert(index); |
| 204 } | 204 } |
| 205 | 205 |
| 206 // This method appropriately sets the enabled states on the table's editing | 206 // This method appropriately sets the enabled states on the table's editing |
| 207 // buttons. | 207 // buttons. |
| 208 - (void)adjustEditingButtons { | 208 - (void)adjustEditingButtons { |
| 209 GeolocationExceptionsTableModel::Rows rows; | 209 GeolocationExceptionsTableModel::Rows rows; |
| 210 [self selectedRows:&rows]; | 210 [self selectedRows:&rows]; |
| 211 [removeButton_ setEnabled:model_->CanRemoveExceptions(rows)]; | 211 [removeButton_ setEnabled:model_->CanRemoveRows(rows)]; |
| 212 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)]; | 212 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)]; |
| 213 } | 213 } |
| 214 | 214 |
| 215 - (void)modelDidChange { | 215 - (void)modelDidChange { |
| 216 [tableView_ reloadData]; | 216 [tableView_ reloadData]; |
| 217 [self adjustEditingButtons]; | 217 [self adjustEditingButtons]; |
| 218 } | 218 } |
| 219 | 219 |
| 220 @end | 220 @end |
| OLD | NEW |