diff options
-rw-r--r-- | chrome/app/nibs/TaskManager.xib | 56 | ||||
-rw-r--r-- | chrome/browser/cocoa/task_manager_mac.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/task_manager_mac.mm | 45 |
3 files changed, 97 insertions, 12 deletions
diff --git a/chrome/app/nibs/TaskManager.xib b/chrome/app/nibs/TaskManager.xib index 30ed88d..a30d2d1 100644 --- a/chrome/app/nibs/TaskManager.xib +++ b/chrome/app/nibs/TaskManager.xib @@ -8,7 +8,7 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="2"/> + <integer value="3"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -154,7 +154,7 @@ </object> </object> <double key="NSRowHeight">1.700000e+01</double> - <int key="NSTvFlags">1388314624</int> + <int key="NSTvFlags">1522532352</int> <int key="NSColumnAutoresizingStyle">4</int> <int key="NSDraggingSourceMaskForLocal">15</int> <int key="NSDraggingSourceMaskForNonLocal">0</int> @@ -345,6 +345,30 @@ </object> <int key="connectionID">30</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">endProcessButton_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="310898064"/> + </object> + <int key="connectionID">31</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">killSelectedProcesses:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="310898064"/> + </object> + <int key="connectionID">32</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">delegate</string> + <reference key="source" ref="573715149"/> + <reference key="destination" ref="1001"/> + </object> + <int key="connectionID">33</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -580,7 +604,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">30</int> + <int key="maxID">33</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -692,12 +716,30 @@ <string key="className">TaskManagerWindowController</string> <string key="superclassName">NSWindowController</string> <object class="NSMutableDictionary" key="actions"> - <string key="NS.key.0">statsLinkClicked:</string> - <string key="NS.object.0">id</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>killSelectedProcesses:</string> + <string>statsLinkClicked:</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>id</string> + </object> </object> <object class="NSMutableDictionary" key="outlets"> - <string key="NS.key.0">tableView_</string> - <string key="NS.object.0">NSTableView</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>endProcessButton_</string> + <string>tableView_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSButton</string> + <string>NSTableView</string> + </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> diff --git a/chrome/browser/cocoa/task_manager_mac.h b/chrome/browser/cocoa/task_manager_mac.h index 2b8f961..07f3fb2 100644 --- a/chrome/browser/cocoa/task_manager_mac.h +++ b/chrome/browser/cocoa/task_manager_mac.h @@ -14,16 +14,22 @@ @interface TaskManagerWindowController : NSWindowController { @private IBOutlet NSTableView* tableView_; + IBOutlet NSButton* endProcessButton_; + TaskManager* taskManager_; // weak TaskManagerModel* model_; // weak } // Creates and shows the task manager's window. -- (id)initWithModel:(TaskManagerModel*)model; +- (id)initWithTaskManager:(TaskManager*)taskManager; // Refreshes all data in the task manager table. - (void)reloadData; +// Callback for "Stats for nerds" link. - (IBAction)statsLinkClicked:(id)sender; + +// Callback for "End process" button. +- (IBAction)killSelectedProcesses:(id)sender; @end // This class listens to task changed events sent by chrome. diff --git a/chrome/browser/cocoa/task_manager_mac.mm b/chrome/browser/cocoa/task_manager_mac.mm index e5b1a04..f03ad05 100644 --- a/chrome/browser/cocoa/task_manager_mac.mm +++ b/chrome/browser/cocoa/task_manager_mac.mm @@ -13,8 +13,8 @@ #include "grit/generated_resources.h" // TODO(thakis): Autoremember window size/pos (and selected columns?) -// TODO(thakis): Activate button iff something is selected, hook it up // TODO(thakis): Column sort comparator +// TODO(thakis): Double-clicking a tab should activate that tab // TODO(thakis): Clicking column header doesn't sort // TODO(thakis): Double-clicking a row seems to do something on win/linux // TODO(thakis): On window close, stop updating @@ -27,6 +27,7 @@ - (void)setUpTableColumns; - (void)setUpTableHeaderContextMenu; - (void)toggleColumn:(id)sender; +- (void)adjustEndProcessButton; @end //////////////////////////////////////////////////////////////////////////////// @@ -34,12 +35,13 @@ @implementation TaskManagerWindowController -- (id)initWithModel:(TaskManagerModel*)model { +- (id)initWithTaskManager:(TaskManager*)taskManager { NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"TaskManager" ofType:@"nib"]; if ((self = [super initWithWindowNibPath:nibpath owner:self])) { - model_ = model; + taskManager_ = taskManager; + model_ = taskManager_->model(); [[self window] makeKeyAndOrderFront:self]; } return self; @@ -47,15 +49,26 @@ - (void)reloadData { [tableView_ reloadData]; + [self adjustEndProcessButton]; } - (IBAction)statsLinkClicked:(id)sender { TaskManager::GetInstance()->OpenAboutMemory(); } +- (IBAction)killSelectedProcesses:(id)sender { + NSIndexSet* selection = [tableView_ selectedRowIndexes]; + for (NSUInteger i = [selection lastIndex]; + i != NSNotFound; + i = [selection indexLessThanIndex:i]) { + taskManager_->KillProcess(i); + } +} + - (void)awakeFromNib { [self setUpTableColumns]; [self setUpTableHeaderContextMenu]; + [self adjustEndProcessButton]; } // Adds a column which has the given string id as title. |isVisible| specifies @@ -131,6 +144,30 @@ [tableView_ setNeedsDisplay]; } +// This function appropriately sets the enabled states on the table's editing +// buttons. +- (void)adjustEndProcessButton { + bool selection_contains_browser_process = false; + + NSIndexSet* selection = [tableView_ selectedRowIndexes]; + for (NSUInteger i = [selection lastIndex]; + i != NSNotFound; + i = [selection indexLessThanIndex:i]) { + if (taskManager_->IsBrowserProcess(i)) { + selection_contains_browser_process = true; + break; + } + } + + bool enabled = [selection count] > 0 && !selection_contains_browser_process; + [endProcessButton_ setEnabled:enabled]; +} + +// Table view delegate method. +- (void)tableViewSelectionDidChange:(NSNotification*)aNotification { + [self adjustEndProcessButton]; +} + @end @implementation TaskManagerWindowController (NSTableDataSource) @@ -216,7 +253,7 @@ TaskManagerMac::TaskManagerMac() : task_manager_(TaskManager::GetInstance()), model_(TaskManager::GetInstance()->model()) { window_controller_.reset( - [[TaskManagerWindowController alloc] initWithModel:model_]); + [[TaskManagerWindowController alloc] initWithTaskManager:task_manager_]); model_->AddObserver(this); } |