| 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 #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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 class SortHelper { | 55 class SortHelper { |
| 56 public: | 56 public: |
| 57 SortHelper(TaskManagerModel* model, NSSortDescriptor* column) | 57 SortHelper(TaskManagerModel* model, NSSortDescriptor* column) |
| 58 : sort_column_([[column key] intValue]), | 58 : sort_column_([[column key] intValue]), |
| 59 ascending_([column ascending]), | 59 ascending_([column ascending]), |
| 60 model_(model) {} | 60 model_(model) {} |
| 61 | 61 |
| 62 bool operator()(int a, int b) { | 62 bool operator()(int a, int b) { |
| 63 std::pair<int, int> group_range1 = model_->GetGroupRangeForResource(a); | 63 int cmp_result = model_->CompareValues(a, b, sort_column_ ); |
| 64 std::pair<int, int> group_range2 = model_->GetGroupRangeForResource(b); | |
| 65 if (group_range1 == group_range2) { | |
| 66 // The two rows are in the same group, sort so that items in the same | |
| 67 // group always appear in the same order. |ascending_| is intentionally | |
| 68 // ignored. | |
| 69 return a < b; | |
| 70 } | |
| 71 // Sort by the first entry of each of the groups. | |
| 72 int cmp_result = model_->CompareValues( | |
| 73 group_range1.first, group_range2.first, sort_column_); | |
| 74 if (!ascending_) | 64 if (!ascending_) |
| 75 cmp_result = -cmp_result; | 65 cmp_result = -cmp_result; |
| 66 // TODO(thakis): Do grouping like on GTK. |
| 76 return cmp_result < 0; | 67 return cmp_result < 0; |
| 77 } | 68 } |
| 78 private: | 69 private: |
| 79 int sort_column_; | 70 int sort_column_; |
| 80 bool ascending_; | 71 bool ascending_; |
| 81 TaskManagerModel* model_; // weak; | 72 TaskManagerModel* model_; // weak; |
| 82 }; | 73 }; |
| 83 | 74 |
| 84 } // namespace | 75 } // namespace |
| 85 | 76 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 row:(NSInteger)rowIndex { | 403 row:(NSInteger)rowIndex { |
| 413 NSCell* cell = [tableColumn dataCellForRow:rowIndex]; | 404 NSCell* cell = [tableColumn dataCellForRow:rowIndex]; |
| 414 | 405 |
| 415 // Set the favicon and title for the task in the name column. | 406 // Set the favicon and title for the task in the name column. |
| 416 if ([[tableColumn identifier] intValue] == IDS_TASK_MANAGER_PAGE_COLUMN) { | 407 if ([[tableColumn identifier] intValue] == IDS_TASK_MANAGER_PAGE_COLUMN) { |
| 417 DCHECK([cell isKindOfClass:[NSButtonCell class]]); | 408 DCHECK([cell isKindOfClass:[NSButtonCell class]]); |
| 418 NSButtonCell* buttonCell = static_cast<NSButtonCell*>(cell); | 409 NSButtonCell* buttonCell = static_cast<NSButtonCell*>(cell); |
| 419 NSString* title = [self modelTextForRow:rowIndex | 410 NSString* title = [self modelTextForRow:rowIndex |
| 420 column:[[tableColumn identifier] intValue]]; | 411 column:[[tableColumn identifier] intValue]]; |
| 421 [buttonCell setTitle:title]; | 412 [buttonCell setTitle:title]; |
| 422 [buttonCell setImage: | 413 [buttonCell setImage:taskManagerObserver_->GetImageForRow(rowIndex)]; |
| 423 taskManagerObserver_->GetImageForRow(indexShuffle_[rowIndex])]; | |
| 424 [buttonCell setRefusesFirstResponder:YES]; // Don't push in like a button. | 414 [buttonCell setRefusesFirstResponder:YES]; // Don't push in like a button. |
| 425 [buttonCell setHighlightsBy:NSNoCellMask]; | 415 [buttonCell setHighlightsBy:NSNoCellMask]; |
| 426 } | 416 } |
| 427 | 417 |
| 428 return cell; | 418 return cell; |
| 429 } | 419 } |
| 430 | 420 |
| 431 - (void) tableView:(NSTableView*)tableView | 421 - (void) tableView:(NSTableView*)tableView |
| 432 sortDescriptorsDidChange:(NSArray*)oldDescriptors { | 422 sortDescriptorsDidChange:(NSArray*)oldDescriptors { |
| 433 NSArray* newDescriptors = [tableView sortDescriptors]; | 423 NSArray* newDescriptors = [tableView sortDescriptors]; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 void TaskManagerMac::Show() { | 493 void TaskManagerMac::Show() { |
| 504 if (instance_) { | 494 if (instance_) { |
| 505 // If there's a Task manager window open already, just activate it. | 495 // If there's a Task manager window open already, just activate it. |
| 506 [[instance_->window_controller_ window] | 496 [[instance_->window_controller_ window] |
| 507 makeKeyAndOrderFront:instance_->window_controller_]; | 497 makeKeyAndOrderFront:instance_->window_controller_]; |
| 508 } else { | 498 } else { |
| 509 instance_ = new TaskManagerMac(TaskManager::GetInstance()); | 499 instance_ = new TaskManagerMac(TaskManager::GetInstance()); |
| 510 instance_->model_->StartUpdating(); | 500 instance_->model_->StartUpdating(); |
| 511 } | 501 } |
| 512 } | 502 } |
| OLD | NEW |