Index: chrome/browser/cocoa/download_item_controller.mm |
=================================================================== |
--- chrome/browser/cocoa/download_item_controller.mm (revision 0) |
+++ chrome/browser/cocoa/download_item_controller.mm (revision 0) |
@@ -0,0 +1,129 @@ |
+// 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 "download_item_controller.h" |
pink (ping after 24hrs)
2009/07/06 21:45:20
use the full path (chrome/browser/cocoa/...)
|
+ |
+#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 |
+ download:(BaseDownloadItemModel*)download_model { |
+ 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(download_model, self)); |
+ menu_bridge_.reset(new DownloadShelfContextMenuMac(download_model)); |
+ |
+ [[self view] setFrame:frameRect]; |
+ } |
+ return self; |
+} |
+ |
+- (void)awakeFromNib { |
+ [self setStateFromDownload:bridge_->download_model()]; |
+} |
+ |
+- (void)setStateFromDownload:(BaseDownloadItemModel*)download_model { |
+ // 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 (download_model->download()->state() == DownloadItem::COMPLETE) |
+ [popupButton_ setMenu:completeDownloadMenu_]; |
+ else |
+ [popupButton_ setMenu:activeDownloadMenu_]; |
+ |
+ // Set name and icon of download |
+ FilePath download_path = download_model->download()->GetFileName(); |
pink (ping after 24hrs)
2009/07/06 21:45:20
obj-C naming for local variables. Elsewhere in the
|
+ |
+ // TODO(thakis): use filename eliding like gtk/windows versions |
+ NSString* titleString = base::SysWideToNSString( |
+ download_path.ToWStringHack()); |
+ [[popupButton_ itemAtIndex:0] setTitle:titleString]; |
+ |
+ NSString* extension = base::SysUTF8ToNSString(download_path.Extension()); |
+ [[popupButton_ itemAtIndex:0] setImage: |
+ [[NSWorkspace sharedWorkspace] iconForFileType:extension]]; |
pink (ping after 24hrs)
2009/07/06 21:45:20
we should use IconManager for this. We've discusse
|
+ |
+ // Set status text |
+ std::wstring status_text = download_model->GetStatusText(); |
+ // Remove the status text label. |
+ if (status_text.empty()) { |
+ // TODO(thakis): Once there is a status label, hide it here |
+ return; |
+ } |
+ |
+ // TODO(thakis): Set status_text as status label |
+} |
+ |
+- (BOOL)validateMenuItem:(NSMenuItem *)item { |
pink (ping after 24hrs)
2009/07/06 21:45:20
I think it's ok to put the tags in the nib. Our ma
|
+ 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 (menu_bridge_->ItemIsChecked(actionId)) |
+ [item setState:NSOnState]; |
+ else |
+ [item setState: NSOffState]; |
+ |
+ return menu_bridge_->IsItemCommandEnabled(actionId) ? YES : NO; |
+} |
+ |
+- (IBAction)handleOpen:(id)sender { |
+ menu_bridge_->ExecuteItemCommand( |
+ DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE); |
+} |
+ |
+- (IBAction)handleAlwaysOpen:(id)sender { |
+ menu_bridge_->ExecuteItemCommand( |
+ DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE); |
+} |
+ |
+- (IBAction)handleReveal:(id)sender { |
+ menu_bridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER); |
+} |
+ |
+- (IBAction)handleCancel:(id)sender { |
+ menu_bridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL); |
+} |
+ |
+@end |
Property changes on: chrome/browser/cocoa/download_item_controller.mm |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |