Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (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 "download_item_controller.h" | |
|
pink (ping after 24hrs)
2009/07/06 21:45:20
use the full path (chrome/browser/cocoa/...)
| |
| 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 download:(BaseDownloadItemModel*)download_model { | |
| 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(download_model, self)); | |
| 41 menu_bridge_.reset(new DownloadShelfContextMenuMac(download_model)); | |
| 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*)download_model { | |
| 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 (download_model->download()->state() == DownloadItem::COMPLETE) | |
| 59 [popupButton_ setMenu:completeDownloadMenu_]; | |
| 60 else | |
| 61 [popupButton_ setMenu:activeDownloadMenu_]; | |
| 62 | |
| 63 // Set name and icon of download | |
| 64 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
| |
| 65 | |
| 66 // TODO(thakis): use filename eliding like gtk/windows versions | |
| 67 NSString* titleString = base::SysWideToNSString( | |
| 68 download_path.ToWStringHack()); | |
| 69 [[popupButton_ itemAtIndex:0] setTitle:titleString]; | |
| 70 | |
| 71 NSString* extension = base::SysUTF8ToNSString(download_path.Extension()); | |
| 72 [[popupButton_ itemAtIndex:0] setImage: | |
| 73 [[NSWorkspace sharedWorkspace] iconForFileType:extension]]; | |
|
pink (ping after 24hrs)
2009/07/06 21:45:20
we should use IconManager for this. We've discusse
| |
| 74 | |
| 75 // Set status text | |
| 76 std::wstring status_text = download_model->GetStatusText(); | |
| 77 // Remove the status text label. | |
| 78 if (status_text.empty()) { | |
| 79 // TODO(thakis): Once there is a status label, hide it here | |
| 80 return; | |
| 81 } | |
| 82 | |
| 83 // TODO(thakis): Set status_text as status label | |
| 84 } | |
| 85 | |
| 86 - (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
| |
| 87 SEL action = [item action]; | |
| 88 | |
| 89 int actionId = 0; | |
| 90 if (action == @selector(handleOpen:)) { | |
| 91 actionId = DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE; | |
| 92 } else if (action == @selector(handleAlwaysOpen:)) { | |
| 93 actionId = DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE; | |
| 94 } else if (action == @selector(handleReveal:)) { | |
| 95 actionId = DownloadShelfContextMenuMac::SHOW_IN_FOLDER; | |
| 96 } else if (action == @selector(handleCancel:)) { | |
| 97 actionId = DownloadShelfContextMenuMac::CANCEL; | |
| 98 } else { | |
| 99 NOTREACHED(); | |
| 100 return YES; | |
| 101 } | |
| 102 | |
| 103 if (menu_bridge_->ItemIsChecked(actionId)) | |
| 104 [item setState:NSOnState]; | |
| 105 else | |
| 106 [item setState: NSOffState]; | |
| 107 | |
| 108 return menu_bridge_->IsItemCommandEnabled(actionId) ? YES : NO; | |
| 109 } | |
| 110 | |
| 111 - (IBAction)handleOpen:(id)sender { | |
| 112 menu_bridge_->ExecuteItemCommand( | |
| 113 DownloadShelfContextMenuMac::OPEN_WHEN_COMPLETE); | |
| 114 } | |
| 115 | |
| 116 - (IBAction)handleAlwaysOpen:(id)sender { | |
| 117 menu_bridge_->ExecuteItemCommand( | |
| 118 DownloadShelfContextMenuMac::ALWAYS_OPEN_TYPE); | |
| 119 } | |
| 120 | |
| 121 - (IBAction)handleReveal:(id)sender { | |
| 122 menu_bridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER); | |
| 123 } | |
| 124 | |
| 125 - (IBAction)handleCancel:(id)sender { | |
| 126 menu_bridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL); | |
| 127 } | |
| 128 | |
| 129 @end | |
| OLD | NEW |