| Index: chrome/browser/cocoa/simple_content_exceptions_window_controller.mm
|
| diff --git a/chrome/browser/cocoa/simple_content_exceptions_window_controller.mm b/chrome/browser/cocoa/simple_content_exceptions_window_controller.mm
|
| index 7be52a93fbe36a3ac8704d169ecb46f1e3a303af..a054b54827801978f1f6c79e89f7d2ac1cc034c0 100644
|
| --- a/chrome/browser/cocoa/simple_content_exceptions_window_controller.mm
|
| +++ b/chrome/browser/cocoa/simple_content_exceptions_window_controller.mm
|
| @@ -4,8 +4,6 @@
|
|
|
| #import "chrome/browser/cocoa/simple_content_exceptions_window_controller.h"
|
|
|
| -#include <set>
|
| -
|
| #include "app/l10n_util_mac.h"
|
| #include "app/table_model_observer.h"
|
| #import "base/mac_util.h"
|
| @@ -16,35 +14,8 @@
|
|
|
| @interface SimpleContentExceptionsWindowController (Private)
|
| - (id)initWithTableModel:(RemoveRowsTableModel*)model;
|
| -- (void)selectedRows:(RemoveRowsTableModel::Rows*)rows;
|
| -- (void)adjustEditingButtons;
|
| -- (void)modelDidChange;
|
| @end
|
|
|
| -// Observer for a RemoveRowsTableModel.
|
| -class RemoveRowsObserverBridge : public TableModelObserver {
|
| - public:
|
| - RemoveRowsObserverBridge(SimpleContentExceptionsWindowController* controller)
|
| - : controller_(controller) {}
|
| - virtual ~RemoveRowsObserverBridge() {}
|
| -
|
| - virtual void OnModelChanged() {
|
| - [controller_ modelDidChange];
|
| - }
|
| - virtual void OnItemsChanged(int start, int length) {
|
| - [controller_ modelDidChange];
|
| - }
|
| - virtual void OnItemsAdded(int start, int length) {
|
| - [controller_ modelDidChange];
|
| - }
|
| - virtual void OnItemsRemoved(int start, int length) {
|
| - [controller_ modelDidChange];
|
| - }
|
| -
|
| - private:
|
| - SimpleContentExceptionsWindowController* controller_; // weak
|
| -};
|
| -
|
| namespace {
|
|
|
| const CGFloat kButtonBarHeight = 35.0;
|
| @@ -69,8 +40,6 @@ SimpleContentExceptionsWindowController* g_exceptionWindow = nil;
|
| ofType:@"nib"];
|
| if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
|
| model_.reset(model);
|
| - tableObserver_.reset(new RemoveRowsObserverBridge(self));
|
| - model_->SetObserver(tableObserver_.get());
|
|
|
| // TODO(thakis): autoremember window rect.
|
| // TODO(thakis): sorting support.
|
| @@ -82,15 +51,19 @@ SimpleContentExceptionsWindowController* g_exceptionWindow = nil;
|
| DCHECK([self window]);
|
| DCHECK_EQ(self, [[self window] delegate]);
|
| DCHECK(tableView_);
|
| - DCHECK_EQ(self, [tableView_ dataSource]);
|
| - DCHECK_EQ(self, [tableView_ delegate]);
|
| + DCHECK(arrayController_);
|
|
|
| CGFloat minWidth = [[removeButton_ superview] bounds].size.width +
|
| [[doneButton_ superview] bounds].size.width;
|
| [[self window] setMinSize:NSMakeSize(minWidth,
|
| [[self window] minSize].height)];
|
| -
|
| - [self adjustEditingButtons];
|
| + NSDictionary* columns = [NSDictionary dictionaryWithObjectsAndKeys:
|
| + [NSNumber numberWithInt:IDS_EXCEPTIONS_HOSTNAME_HEADER], @"hostname",
|
| + [NSNumber numberWithInt:IDS_EXCEPTIONS_ACTION_HEADER], @"action",
|
| + nil];
|
| + [arrayController_ bindToTableModel:model_.get()
|
| + withColumns:columns
|
| + groupTitleColumn:@"hostname"];
|
| }
|
|
|
| - (void)setMinWidth:(CGFloat)minWidth {
|
| @@ -104,9 +77,6 @@ SimpleContentExceptionsWindowController* g_exceptionWindow = nil;
|
| }
|
|
|
| - (void)windowWillClose:(NSNotification*)notification {
|
| - // Without this, some of the unit tests fail on 10.6:
|
| - [tableView_ setDataSource:nil];
|
| -
|
| g_exceptionWindow = nil;
|
| [self autorelease];
|
| }
|
| @@ -124,7 +94,7 @@ SimpleContentExceptionsWindowController* g_exceptionWindow = nil;
|
| case NSDeleteFunctionKey:
|
| // Delete deletes.
|
| if ([[tableView_ selectedRowIndexes] count] > 0)
|
| - [self removeRow:self];
|
| + [arrayController_ remove:event];
|
| return;
|
| }
|
| }
|
| @@ -150,68 +120,5 @@ SimpleContentExceptionsWindowController* g_exceptionWindow = nil;
|
| [NSApp endSheet:[self window]];
|
| }
|
|
|
| -- (IBAction)removeRow:(id)sender {
|
| - RemoveRowsTableModel::Rows rows;
|
| - [self selectedRows:&rows];
|
| - model_->RemoveRows(rows);
|
| -}
|
| -
|
| -- (IBAction)removeAll:(id)sender {
|
| - model_->RemoveAll();
|
| -}
|
| -
|
| -// Table View Data Source -----------------------------------------------------
|
| -
|
| -- (NSInteger)numberOfRowsInTableView:(NSTableView*)table {
|
| - return model_->RowCount();
|
| -}
|
| -
|
| -- (id)tableView:(NSTableView*)tv
|
| - objectValueForTableColumn:(NSTableColumn*)tableColumn
|
| - row:(NSInteger)row {
|
| - NSObject* result = nil;
|
| - NSString* identifier = [tableColumn identifier];
|
| - if ([identifier isEqualToString:@"hostname"]) {
|
| - std::wstring host = model_->GetText(row, IDS_EXCEPTIONS_HOSTNAME_HEADER);
|
| - result = base::SysWideToNSString(host);
|
| - } else if ([identifier isEqualToString:@"action"]) {
|
| - std::wstring action = model_->GetText(row, IDS_EXCEPTIONS_ACTION_HEADER);
|
| - result = base::SysWideToNSString(action);
|
| - } else {
|
| - NOTREACHED();
|
| - }
|
| - return result;
|
| -}
|
| -
|
| -// Table View Delegate --------------------------------------------------------
|
| -
|
| -// When the selection in the table view changes, we need to adjust buttons.
|
| -- (void)tableViewSelectionDidChange:(NSNotification*)notification {
|
| - [self adjustEditingButtons];
|
| -}
|
| -
|
| -// Private --------------------------------------------------------------------
|
| -
|
| -// Returns the selected rows.
|
| -- (void)selectedRows:(RemoveRowsTableModel::Rows*)rows {
|
| - NSIndexSet* selection = [tableView_ selectedRowIndexes];
|
| - for (NSUInteger index = [selection lastIndex]; index != NSNotFound;
|
| - index = [selection indexLessThanIndex:index])
|
| - rows->insert(index);
|
| -}
|
| -
|
| -// This method appropriately sets the enabled states on the table's editing
|
| -// buttons.
|
| -- (void)adjustEditingButtons {
|
| - RemoveRowsTableModel::Rows rows;
|
| - [self selectedRows:&rows];
|
| - [removeButton_ setEnabled:model_->CanRemoveRows(rows)];
|
| - [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)];
|
| -}
|
| -
|
| -- (void)modelDidChange {
|
| - [tableView_ reloadData];
|
| - [self adjustEditingButtons];
|
| -}
|
|
|
| @end
|
|
|