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