summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/download_item_controller.mm
diff options
context:
space:
mode:
authorpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 23:02:08 +0000
committerpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 23:02:08 +0000
commit8358105e6826be9bbb7ef2a43671d596aa492ba6 (patch)
treef3aa6026df83d2ab8befec964f6abb3bb4bde9d6 /chrome/browser/cocoa/download_item_controller.mm
parenta796793059916e64b9c45191c1945868f4bff2a5 (diff)
downloadchromium_src-8358105e6826be9bbb7ef2a43671d596aa492ba6.zip
chromium_src-8358105e6826be9bbb7ef2a43671d596aa492ba6.tar.gz
chromium_src-8358105e6826be9bbb7ef2a43671d596aa492ba6.tar.bz2
The Mac version of the download shelf from the original CL by thakis:
http://codereview.chromium.org/150216 Original description: Move download item to its own view and a xib, paving the way for a custom download item view. I didn't change the look of the download items yet. The context menu is now in the download item xib as well. BUG=14659,15098,14660 TEST=Download something. Everything should look like before (except for the smaller icon), but the context menu items should be disabled/enabled and checked/unchecked correctly. Review URL: http://codereview.chromium.org/149276 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20200 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/download_item_controller.mm')
-rw-r--r--chrome/browser/cocoa/download_item_controller.mm133
1 files changed, 133 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/download_item_controller.mm b/chrome/browser/cocoa/download_item_controller.mm
new file mode 100644
index 0000000..c189c66
--- /dev/null
+++ b/chrome/browser/cocoa/download_item_controller.mm
@@ -0,0 +1,133 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/download_item_controller.h"
+
+#include "app/l10n_util.h"
+#include "base/mac_util.h"
+#include "base/sys_string_conversions.h"
+#include "chrome/browser/cocoa/download_item_mac.h"
+#include "chrome/browser/download/download_item_model.h"
+#include "chrome/browser/download/download_shelf.h"
+
+// A class for the chromium-side part of the download shelf context menu.
+
+class DownloadShelfContextMenuMac : public DownloadShelfContextMenu {
+ public:
+ DownloadShelfContextMenuMac(BaseDownloadItemModel* model)
+ : DownloadShelfContextMenu(model) { }
+
+ using DownloadShelfContextMenu::ExecuteItemCommand;
+ using DownloadShelfContextMenu::ItemIsChecked;
+ using DownloadShelfContextMenu::IsItemCommandEnabled;
+
+ using DownloadShelfContextMenu::SHOW_IN_FOLDER;
+ using DownloadShelfContextMenu::OPEN_WHEN_COMPLETE;
+ using DownloadShelfContextMenu::ALWAYS_OPEN_TYPE;
+ using DownloadShelfContextMenu::CANCEL;
+};
+
+// Implementation of DownloadItemController
+
+@implementation DownloadItemController
+
+- (id)initWithFrame:(NSRect)frameRect
+ model:(BaseDownloadItemModel*)downloadModel {
+ if ((self = [super initWithNibName:@"DownloadItem"
+ bundle:mac_util::MainAppBundle()])) {
+ // Must be called before [self view], so that bridge_ is set in awakeFromNib
+ bridge_.reset(new DownloadItemMac(downloadModel, self));
+ menuBridge_.reset(new DownloadShelfContextMenuMac(downloadModel));
+
+ [[self view] setFrame:frameRect];
+ }
+ return self;
+}
+
+- (void)awakeFromNib {
+ [self setStateFromDownload:bridge_->download_model()];
+}
+
+- (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel {
+ // TODO(thakis): The windows version of this does all kinds of things
+ // (gratituous use of animation, special handling of dangerous downloads)
+ // that we don't currently do.
+
+ // Set correct popup menu.
+ if (downloadModel->download()->state() == DownloadItem::COMPLETE)
+ [popupButton_ setMenu:completeDownloadMenu_];
+ else
+ [popupButton_ setMenu:activeDownloadMenu_];
+
+ // Set name and icon of download.
+ FilePath downloadPath = downloadModel->download()->GetFileName();
+
+ // TODO(thakis): use filename eliding like gtk/windows versions.
+ NSString* titleString = base::SysWideToNSString(downloadPath.ToWStringHack());
+ [[popupButton_ itemAtIndex:0] setTitle:titleString];
+
+ // TODO(paulg): Use IconManager for loading icons on the file thread
+ // (crbug.com/16226).
+ NSString* extension = base::SysUTF8ToNSString(downloadPath.Extension());
+ [[popupButton_ itemAtIndex:0] setImage:
+ [[NSWorkspace sharedWorkspace] iconForFileType:extension]];
+
+ // Set status text.
+ std::wstring statusText = downloadModel->GetStatusText();
+ // Remove the status text label.
+ if (statusText.empty()) {
+ // TODO(thakis): Once there is a status label, hide it here.
+ return;
+ }
+
+ // TODO(thakis): Set status_text as status label.
+}
+
+// Sets the enabled and checked state of a particular menu item for this
+// download. We translate the NSMenuItem selection to menu selections understood
+// by the non platform specific download context menu.
+- (BOOL)validateMenuItem:(NSMenuItem *)item {
+ SEL action = [item action];
+
+ int actionId = 0;
+ if (action == @selector(handleOpen:)) {
+ actionId = DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE;
+ } else if (action == @selector(handleAlwaysOpen:)) {
+ actionId = DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE;
+ } else if (action == @selector(handleReveal:)) {
+ actionId = DownloadShelfContextMenuMac::SHOW_IN_FOLDER;
+ } else if (action == @selector(handleCancel:)) {
+ actionId = DownloadShelfContextMenuMac::CANCEL;
+ } else {
+ NOTREACHED();
+ return YES;
+ }
+
+ if (menuBridge_->ItemIsChecked(actionId))
+ [item setState:NSOnState];
+ else
+ [item setState:NSOffState];
+
+ return menuBridge_->IsItemCommandEnabled(actionId) ? YES : NO;
+}
+
+- (IBAction)handleOpen:(id)sender {
+ menuBridge_->ExecuteItemCommand(
+ DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE);
+}
+
+- (IBAction)handleAlwaysOpen:(id)sender {
+ menuBridge_->ExecuteItemCommand(
+ DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE);
+}
+
+- (IBAction)handleReveal:(id)sender {
+ menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER);
+}
+
+- (IBAction)handleCancel:(id)sender {
+ menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL);
+}
+
+@end