summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/download_item_mac.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_mac.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_mac.mm')
-rw-r--r--chrome/browser/cocoa/download_item_mac.mm145
1 files changed, 4 insertions, 141 deletions
diff --git a/chrome/browser/cocoa/download_item_mac.mm b/chrome/browser/cocoa/download_item_mac.mm
index e9d86d2..05d4717 100644
--- a/chrome/browser/cocoa/download_item_mac.mm
+++ b/chrome/browser/cocoa/download_item_mac.mm
@@ -4,145 +4,15 @@
#include "chrome/browser/cocoa/download_item_mac.h"
-#include "base/basictypes.h"
-#include "base/string_util.h"
-#include "base/sys_string_conversions.h"
-#import "chrome/browser/cocoa/download_shelf_controller.h"
-#import "chrome/browser/cocoa/download_shelf_mac.h"
-#import "chrome/browser/cocoa/download_shelf_view.h"
+#import "chrome/browser/cocoa/download_item_controller.h"
#include "chrome/browser/download/download_item_model.h"
-#include "chrome/browser/download/download_manager.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,
- DownloadShelfContextMenuBridge* bridge)
- : DownloadShelfContextMenu(model), bridge_(bridge) {
- }
-
- NSMenu* GetCocoaMenu();
-
- using DownloadShelfContextMenu::ExecuteItemCommand;
-
- private:
- DownloadShelfContextMenuBridge* bridge_; // weak, owns us
-};
-
-NSMenu* DownloadShelfContextMenuMac::GetCocoaMenu() {
- // TODO(thakis): win/gtk show slightly different menus when the download is
- // in progress/done (mainly the first item)
- // TODO(thakis): this probably wants to be in a xib file or at least use
- // localized strings
-
- NSMenuItem* item;
- NSMenu* menu =
- [[[NSMenu alloc] initWithTitle:@"DownloadItemPopup"] autorelease];
- SEL action = @selector(performAction:);
-
- item = [menu addItemWithTitle:@"Open" action:action keyEquivalent:@""];
- // [item addItemWithTitle:@"Open when complete" ...]; // In-progress text.
- [item setTag:OPEN_WHEN_COMPLETE];
- [item setTarget:bridge_];
-
- // TODO(thakis): Set correct checkbox state, make this a checkbox item
- item = [menu addItemWithTitle:@"Always open type"
- action:action
- keyEquivalent:@""];
- [item setTag:ALWAYS_OPEN_TYPE];
- [item setTarget:bridge_];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:@"Reveal in Finder"
- action:action
- keyEquivalent:@""];
- [item setTag:SHOW_IN_FOLDER];
- [item setTarget:bridge_];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:@"Cancel" action:action keyEquivalent:@""];
- [item setTag:CANCEL];
- [item setTarget:bridge_];
-
- return menu;
-}
-
-
-// A class for the cocoa side of the download shelf context menu.
-
-@interface DownloadShelfContextMenuBridge : NSObject {
- @private
- scoped_ptr<DownloadShelfContextMenuMac> contextMenu_;
-}
-
-- (DownloadShelfContextMenuBridge*)initWithModel:(BaseDownloadItemModel*)model;
-@end
-
-@interface DownloadShelfContextMenuBridge(Private)
-- (void)performAction:(id)sender;
-- (NSMenu*)menu;
-@end
-
-@implementation DownloadShelfContextMenuBridge
-
-- (DownloadShelfContextMenuBridge*)initWithModel:(BaseDownloadItemModel*)model {
- if ((self = [super init]) == nil) {
- return nil;
- }
- contextMenu_.reset(new DownloadShelfContextMenuMac(model, self));
- return self;
-}
-
-@end
-
-@implementation DownloadShelfContextMenuBridge(Private)
-
-- (void)performAction:(id)sender {
- contextMenu_->ExecuteItemCommand([sender tag]);
-}
-
-- (NSMenu*)menu {
- return contextMenu_->GetCocoaMenu();
-}
-
-@end
-
// DownloadItemMac -------------------------------------------------------------
DownloadItemMac::DownloadItemMac(BaseDownloadItemModel* download_model,
- NSRect frame,
- DownloadShelfController* parent)
- : download_model_(download_model), parent_(parent) {
+ DownloadItemController* controller)
+ : download_model_(download_model), item_controller_(controller) {
download_model_->download()->AddObserver(this);
-
- // 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.
-
- scoped_nsobject<NSPopUpButton> view(
- [[NSPopUpButton alloc] initWithFrame:frame pullsDown:YES]);
- [parent_ addDownloadItem:view.get()];
-
- FilePath download_path = download_model->download()->GetFileName();
-
- // TODO(thakis): use filename eliding like gtk/windows versions
- NSString* titleString = base::SysWideToNSString(
- download_path.ToWStringHack());
-
- menu_.reset([[DownloadShelfContextMenuBridge alloc]
- initWithModel:download_model_.get()]);
- [view.get() setMenu:[menu_.get() menu]];
-
- [view.get() insertItemWithTitle:titleString atIndex:0];
-
- NSString* extension = base::SysUTF8ToNSString(download_path.Extension());
- [[view.get() itemAtIndex:0] setImage:
- [[NSWorkspace sharedWorkspace] iconForFileType:extension]];
}
DownloadItemMac::~DownloadItemMac() {
@@ -152,12 +22,5 @@ DownloadItemMac::~DownloadItemMac() {
void DownloadItemMac::OnDownloadUpdated(DownloadItem* download) {
DCHECK_EQ(download, download_model_->download());
- 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
+ [item_controller_ setStateFromDownload:download_model_.get()];
}