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 #import "chrome/browser/cocoa/download_item_controller.h" | 5 #import "chrome/browser/cocoa/download_item_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | |
8 #include "base/mac_util.h" | 7 #include "base/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 8 #import "chrome/browser/cocoa/download_item_cell.h" |
10 #include "chrome/browser/cocoa/download_item_mac.h" | 9 #include "chrome/browser/cocoa/download_item_mac.h" |
11 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
12 #include "chrome/browser/download/download_shelf.h" | 11 #include "chrome/browser/download/download_shelf.h" |
| 12 #include "chrome/browser/download/download_util.h" |
| 13 |
13 | 14 |
14 // A class for the chromium-side part of the download shelf context menu. | 15 // A class for the chromium-side part of the download shelf context menu. |
15 | 16 |
16 class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { | 17 class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { |
17 public: | 18 public: |
18 DownloadShelfContextMenuMac(BaseDownloadItemModel* model) | 19 DownloadShelfContextMenuMac(BaseDownloadItemModel* model) |
19 : DownloadShelfContextMenu(model) { } | 20 : DownloadShelfContextMenu(model) { } |
20 | 21 |
21 using DownloadShelfContextMenu::ExecuteItemCommand; | 22 using DownloadShelfContextMenu::ExecuteItemCommand; |
22 using DownloadShelfContextMenu::ItemIsChecked; | 23 using DownloadShelfContextMenu::ItemIsChecked; |
(...skipping 29 matching lines...) Expand all Loading... |
52 [self setStateFromDownload:bridge_->download_model()]; | 53 [self setStateFromDownload:bridge_->download_model()]; |
53 } | 54 } |
54 | 55 |
55 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel { | 56 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel { |
56 // TODO(thakis): The windows version of this does all kinds of things | 57 // TODO(thakis): The windows version of this does all kinds of things |
57 // (gratituous use of animation, special handling of dangerous downloads) | 58 // (gratituous use of animation, special handling of dangerous downloads) |
58 // that we don't currently do. | 59 // that we don't currently do. |
59 | 60 |
60 // Set correct popup menu. | 61 // Set correct popup menu. |
61 if (downloadModel->download()->state() == DownloadItem::COMPLETE) | 62 if (downloadModel->download()->state() == DownloadItem::COMPLETE) |
62 [popupButton_ setMenu:completeDownloadMenu_]; | 63 currentMenu_ = completeDownloadMenu_; |
63 else | 64 else |
64 [popupButton_ setMenu:activeDownloadMenu_]; | 65 currentMenu_ = activeDownloadMenu_; |
65 | 66 |
66 // Set name and icon of download. | 67 [progressView_ setMenu:currentMenu_]; // for context menu |
67 FilePath downloadPath = downloadModel->download()->GetFileName(); | 68 [cell_ setStateFromDownload:downloadModel]; |
68 | |
69 // TODO(thakis): use filename eliding like gtk/windows versions. | |
70 NSString* titleString = base::SysWideToNSString(downloadPath.ToWStringHack()); | |
71 [[popupButton_ itemAtIndex:0] setTitle:titleString]; | |
72 | |
73 // TODO(paulg): Use IconManager for loading icons on the file thread | |
74 // (crbug.com/16226). | |
75 NSString* extension = base::SysUTF8ToNSString(downloadPath.Extension()); | |
76 [[popupButton_ itemAtIndex:0] setImage: | |
77 [[NSWorkspace sharedWorkspace] iconForFileType:extension]]; | |
78 | |
79 // Set status text. | |
80 std::wstring statusText = downloadModel->GetStatusText(); | |
81 // Remove the status text label. | |
82 if (statusText.empty()) { | |
83 // TODO(thakis): Once there is a status label, hide it here. | |
84 return; | |
85 } | |
86 | |
87 // TODO(thakis): Set status_text as status label. | |
88 } | 69 } |
89 | 70 |
90 - (void)remove { | 71 - (void)remove { |
91 // We are deleted after this! | 72 // We are deleted after this! |
92 [shelf_ remove:self]; | 73 [shelf_ remove:self]; |
93 } | 74 } |
94 | 75 |
| 76 - (IBAction)handleButtonClick:(id)sender { |
| 77 if ([cell_ isButtonPartPressed]) { |
| 78 DownloadItem* download = bridge_->download_model()->download(); |
| 79 if (download->state() == DownloadItem::IN_PROGRESS) { |
| 80 download->set_open_when_complete(!download->open_when_complete()); |
| 81 } else if (download->state() == DownloadItem::COMPLETE) { |
| 82 download_util::OpenDownload(download); |
| 83 } |
| 84 } else { |
| 85 // TODO(thakis): Align menu nicely with left view edge |
| 86 [NSMenu popUpContextMenu:currentMenu_ |
| 87 withEvent:[NSApp currentEvent] |
| 88 forView:progressView_]; |
| 89 } |
| 90 } |
| 91 |
95 // Sets the enabled and checked state of a particular menu item for this | 92 // Sets the enabled and checked state of a particular menu item for this |
96 // download. We translate the NSMenuItem selection to menu selections understood | 93 // download. We translate the NSMenuItem selection to menu selections understood |
97 // by the non platform specific download context menu. | 94 // by the non platform specific download context menu. |
98 - (BOOL)validateMenuItem:(NSMenuItem *)item { | 95 - (BOOL)validateMenuItem:(NSMenuItem *)item { |
99 SEL action = [item action]; | 96 SEL action = [item action]; |
100 | 97 |
101 int actionId = 0; | 98 int actionId = 0; |
102 if (action == @selector(handleOpen:)) { | 99 if (action == @selector(handleOpen:)) { |
103 actionId = DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE; | 100 actionId = DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE; |
104 } else if (action == @selector(handleAlwaysOpen:)) { | 101 } else if (action == @selector(handleAlwaysOpen:)) { |
(...skipping 27 matching lines...) Expand all Loading... |
132 | 129 |
133 - (IBAction)handleReveal:(id)sender { | 130 - (IBAction)handleReveal:(id)sender { |
134 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER); | 131 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER); |
135 } | 132 } |
136 | 133 |
137 - (IBAction)handleCancel:(id)sender { | 134 - (IBAction)handleCancel:(id)sender { |
138 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL); | 135 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL); |
139 } | 136 } |
140 | 137 |
141 @end | 138 @end |
OLD | NEW |