Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(866)

Side by Side Diff: chrome/browser/cocoa/download_item_controller.mm

Issue 149276: Mac version of the download shelf views (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/cocoa/download_item_controller.h"
6
7 #include "app/l10n_util.h"
8 #include "base/mac_util.h"
9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/cocoa/download_item_mac.h"
11 #include "chrome/browser/download/download_item_model.h"
12 #include "chrome/browser/download/download_shelf.h"
13
14 // A class for the chromium-side part of the download shelf context menu.
15
16 class DownloadShelfContextMenuMac : public DownloadShelfContextMenu {
17 public:
18 DownloadShelfContextMenuMac(BaseDownloadItemModel* model)
19 : DownloadShelfContextMenu(model) { }
20
21 using DownloadShelfContextMenu::ExecuteItemCommand;
22 using DownloadShelfContextMenu::ItemIsChecked;
23 using DownloadShelfContextMenu::IsItemCommandEnabled;
24
25 using DownloadShelfContextMenu::SHOW_IN_FOLDER;
26 using DownloadShelfContextMenu::OPEN_WHEN_COMPLETE;
27 using DownloadShelfContextMenu::ALWAYS_OPEN_TYPE;
28 using DownloadShelfContextMenu::CANCEL;
29 };
30
31 // Implementation of DownloadItemController
32
33 @implementation DownloadItemController
34
35 - (id)initWithFrame:(NSRect)frameRect
36 model:(BaseDownloadItemModel*)downloadModel {
37 if ((self = [super initWithNibName:@"DownloadItem"
38 bundle:mac_util::MainAppBundle()])) {
39 // Must be called before [self view], so that bridge_ is set in awakeFromNib
40 bridge_.reset(new DownloadItemMac(downloadModel, self));
41 menuBridge_.reset(new DownloadShelfContextMenuMac(downloadModel));
42
43 [[self view] setFrame:frameRect];
44 }
45 return self;
46 }
47
48 - (void)awakeFromNib {
49 [self setStateFromDownload:bridge_->download_model()];
50 }
51
52 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel {
53 // TODO(thakis): The windows version of this does all kinds of things
54 // (gratituous use of animation, special handling of dangerous downloads)
55 // that we don't currently do.
56
57 // Set correct popup menu.
58 if (downloadModel->download()->state() == DownloadItem::COMPLETE)
59 [popupButton_ setMenu:completeDownloadMenu_];
60 else
61 [popupButton_ setMenu:activeDownloadMenu_];
62
63 // Set name and icon of download.
64 FilePath downloadPath = downloadModel->download()->GetFileName();
65
66 // TODO(thakis): use filename eliding like gtk/windows versions.
67 NSString* titleString = base::SysWideToNSString(downloadPath.ToWStringHack());
68 [[popupButton_ itemAtIndex:0] setTitle:titleString];
69
70 // TODO(paulg): Use IconManager for loading icons on the file thread
71 // (crbug.com/16226).
72 NSString* extension = base::SysUTF8ToNSString(downloadPath.Extension());
73 [[popupButton_ itemAtIndex:0] setImage:
74 [[NSWorkspace sharedWorkspace] iconForFileType:extension]];
75
76 // Set status text.
77 std::wstring statusText = downloadModel->GetStatusText();
78 // Remove the status text label.
79 if (statusText.empty()) {
80 // TODO(thakis): Once there is a status label, hide it here.
81 return;
82 }
83
84 // TODO(thakis): Set status_text as status label.
85 }
86
87 // Sets the enabled and checked state of a particular menu item for this
88 // download. We translate the NSMenuItem selection to menu selections understood
89 // by the non platform specific download context menu.
90 - (BOOL)validateMenuItem:(NSMenuItem *)item {
91 SEL action = [item action];
92
93 int actionId = 0;
94 if (action == @selector(handleOpen:)) {
95 actionId = DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE;
96 } else if (action == @selector(handleAlwaysOpen:)) {
97 actionId = DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE;
98 } else if (action == @selector(handleReveal:)) {
99 actionId = DownloadShelfContextMenuMac::SHOW_IN_FOLDER;
100 } else if (action == @selector(handleCancel:)) {
101 actionId = DownloadShelfContextMenuMac::CANCEL;
102 } else {
103 NOTREACHED();
104 return YES;
105 }
106
107 if (menuBridge_->ItemIsChecked(actionId))
108 [item setState:NSOnState];
109 else
110 [item setState:NSOffState];
111
112 return menuBridge_->IsItemCommandEnabled(actionId) ? YES : NO;
113 }
114
115 - (IBAction)handleOpen:(id)sender {
116 menuBridge_->ExecuteItemCommand(
117 DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE);
118 }
119
120 - (IBAction)handleAlwaysOpen:(id)sender {
121 menuBridge_->ExecuteItemCommand(
122 DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE);
123 }
124
125 - (IBAction)handleReveal:(id)sender {
126 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER);
127 }
128
129 - (IBAction)handleCancel:(id)sender {
130 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL);
131 }
132
133 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/download_item_controller.h ('k') | chrome/browser/cocoa/download_item_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698