| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/cocoa/task_manager_mac.h" | 5 #include "chrome/browser/cocoa/task_manager_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "app/l10n_util_mac.h" | 10 #include "app/l10n_util_mac.h" |
| 11 #include "base/mac_util.h" | 11 #include "base/mac_util.h" |
| 12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 14 #import "chrome/browser/cocoa/window_size_autosaver.h" |
| 15 #include "chrome/common/pref_names.h" |
| 13 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 14 | 17 |
| 15 // TODO(thakis): Autoremember window size/pos (and selected columns?) | |
| 16 // TODO(thakis): Better resizing behavior (and think about storing column sizes) | 18 // TODO(thakis): Better resizing behavior (and think about storing column sizes) |
| 17 // TODO(thakis): Column sort comparator | 19 // TODO(thakis): Column sort comparator |
| 18 // TODO(thakis): Clicking column header doesn't sort | 20 // TODO(thakis): Clicking column header doesn't sort |
| 19 // TODO(thakis): Default sort column | 21 // TODO(thakis): Default sort column |
| 20 | 22 |
| 21 @interface TaskManagerWindowController (Private) | 23 @interface TaskManagerWindowController (Private) |
| 22 - (NSTableColumn*)addColumnWithId:(int)columnId visible:(BOOL)isVisible; | 24 - (NSTableColumn*)addColumnWithId:(int)columnId visible:(BOOL)isVisible; |
| 23 - (void)setUpTableColumns; | 25 - (void)setUpTableColumns; |
| 24 - (void)setUpTableHeaderContextMenu; | 26 - (void)setUpTableHeaderContextMenu; |
| 25 - (void)toggleColumn:(id)sender; | 27 - (void)toggleColumn:(id)sender; |
| 26 - (void)adjustEndProcessButton; | 28 - (void)adjustEndProcessButton; |
| 27 @end | 29 @end |
| 28 | 30 |
| 29 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 30 // TaskManagerWindowController implementation: | 32 // TaskManagerWindowController implementation: |
| 31 | 33 |
| 32 @implementation TaskManagerWindowController | 34 @implementation TaskManagerWindowController |
| 33 | 35 |
| 34 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver { | 36 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver { |
| 35 NSString* nibpath = [mac_util::MainAppBundle() | 37 NSString* nibpath = [mac_util::MainAppBundle() |
| 36 pathForResource:@"TaskManager" | 38 pathForResource:@"TaskManager" |
| 37 ofType:@"nib"]; | 39 ofType:@"nib"]; |
| 38 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 40 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 39 taskManagerObserver_ = taskManagerObserver; | 41 taskManagerObserver_ = taskManagerObserver; |
| 40 taskManager_ = taskManagerObserver_->task_manager(); | 42 taskManager_ = taskManagerObserver_->task_manager(); |
| 41 model_ = taskManager_->model(); | 43 model_ = taskManager_->model(); |
| 44 |
| 45 if (g_browser_process && g_browser_process->local_state()) { |
| 46 size_saver_.reset([[WindowSizeAutosaver alloc] |
| 47 initWithWindow:[self window] |
| 48 prefService:g_browser_process->local_state() |
| 49 path:prefs::kTaskManagerWindowPlacement |
| 50 state:kSaveWindowRect]); |
| 51 } |
| 42 [[self window] makeKeyAndOrderFront:self]; | 52 [[self window] makeKeyAndOrderFront:self]; |
| 43 } | 53 } |
| 44 return self; | 54 return self; |
| 45 } | 55 } |
| 46 | 56 |
| 47 - (void)reloadData { | 57 - (void)reloadData { |
| 48 [tableView_ reloadData]; | 58 [tableView_ reloadData]; |
| 49 [self adjustEndProcessButton]; | 59 [self adjustEndProcessButton]; |
| 50 } | 60 } |
| 51 | 61 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 192 |
| 183 bool enabled = [selection count] > 0 && !selectionContainsBrowserProcess; | 193 bool enabled = [selection count] > 0 && !selectionContainsBrowserProcess; |
| 184 [endProcessButton_ setEnabled:enabled]; | 194 [endProcessButton_ setEnabled:enabled]; |
| 185 } | 195 } |
| 186 | 196 |
| 187 // Table view delegate method. | 197 // Table view delegate method. |
| 188 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { | 198 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { |
| 189 [self adjustEndProcessButton]; | 199 [self adjustEndProcessButton]; |
| 190 } | 200 } |
| 191 | 201 |
| 192 // Called when the window is being closed. Send out a notification that the user | |
| 193 // is done editing preferences. Make sure there are no pending field editors | |
| 194 // by clearing the first responder. | |
| 195 - (void)windowWillClose:(NSNotification*)notification { | |
| 196 if (taskManagerObserver_) { | |
| 197 taskManagerObserver_->WindowWasClosed(); | |
| 198 taskManagerObserver_ = nil; | |
| 199 } | |
| 200 [self autorelease]; | |
| 201 } | |
| 202 | |
| 203 @end | 202 @end |
| 204 | 203 |
| 205 @implementation TaskManagerWindowController (NSTableDataSource) | 204 @implementation TaskManagerWindowController (NSTableDataSource) |
| 206 | 205 |
| 207 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | 206 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { |
| 208 DCHECK(tableView == tableView_ || tableView_ == nil); | 207 DCHECK(tableView == tableView_ || tableView_ == nil); |
| 209 return model_->ResourceCount(); | 208 return model_->ResourceCount(); |
| 210 } | 209 } |
| 211 | 210 |
| 212 - (NSString*)modelTextForRow:(int)row column:(int)columnId { | 211 - (NSString*)modelTextForRow:(int)row column:(int)columnId { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 void TaskManagerMac::Show() { | 362 void TaskManagerMac::Show() { |
| 364 if (instance_) { | 363 if (instance_) { |
| 365 // If there's a Task manager window open already, just activate it. | 364 // If there's a Task manager window open already, just activate it. |
| 366 [[instance_->window_controller_ window] | 365 [[instance_->window_controller_ window] |
| 367 makeKeyAndOrderFront:instance_->window_controller_]; | 366 makeKeyAndOrderFront:instance_->window_controller_]; |
| 368 } else { | 367 } else { |
| 369 instance_ = new TaskManagerMac; | 368 instance_ = new TaskManagerMac; |
| 370 instance_->model_->StartUpdating(); | 369 instance_->model_->StartUpdating(); |
| 371 } | 370 } |
| 372 } | 371 } |
| OLD | NEW |