Fix transcript in transfer window.
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / delegate / TransferMenuDelegate.java
blob3193af4fe3908fa2c1c52d8e952d7f9035a7df07
1 package ch.cyberduck.ui.cocoa.delegate;
3 /*
4 * Copyright (c) 2007 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * dkocher@cyberduck.ch
21 import ch.cyberduck.binding.application.NSImage;
22 import ch.cyberduck.binding.application.NSMenu;
23 import ch.cyberduck.binding.application.NSMenuItem;
24 import ch.cyberduck.core.LocalFactory;
25 import ch.cyberduck.core.local.RevealService;
26 import ch.cyberduck.core.local.RevealServiceFactory;
27 import ch.cyberduck.core.resources.IconCacheFactory;
28 import ch.cyberduck.core.transfer.Transfer;
29 import ch.cyberduck.core.transfer.TransferItem;
30 import ch.cyberduck.ui.cocoa.Action;
32 import org.rococoa.Foundation;
33 import org.rococoa.Selector;
34 import org.rococoa.cocoa.foundation.NSInteger;
36 import java.util.ArrayList;
38 /**
39 * @version $Id$
41 public class TransferMenuDelegate extends AbstractMenuDelegate {
43 private Transfer transfer;
45 private RevealService reveal = RevealServiceFactory.get();
47 public TransferMenuDelegate(final Transfer transfer) {
48 this.transfer = transfer;
51 @Override
52 public NSInteger numberOfItemsInMenu(NSMenu menu) {
53 if(this.isPopulated()) {
54 // If you return a negative value, the number of items is left unchanged
55 // and menu:updateItem:atIndex:shouldCancel: is not called.
56 return new NSInteger(-1);
58 return new NSInteger(transfer.getRoots().size());
61 @Override
62 public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger index, boolean cancel) {
63 final TransferItem entry
64 = new ArrayList<TransferItem>(transfer.getRoots()).get(index.intValue());
65 item.setTitle(entry.remote.getName());
66 if(entry.local != null) {
67 item.setRepresentedObject(entry.local.getAbsolute());
68 if(entry.local.exists()) {
69 item.setEnabled(true);
70 item.setTarget(this.id());
71 item.setAction(this.getDefaultAction());
73 else {
74 item.setEnabled(false);
75 item.setTarget(null);
78 else {
79 item.setRepresentedObject(entry.remote.getAbsolute());
81 item.setImage(IconCacheFactory.<NSImage>get().fileIcon(entry.remote, 16));
82 return super.menuUpdateItemAtIndex(menu, item, index, cancel);
85 @Action
86 public void revealMenuClicked(final NSMenuItem sender) {
87 reveal.reveal(LocalFactory.get(sender.representedObject()));
90 @Override
91 protected Selector getDefaultAction() {
92 return Foundation.selector("revealMenuClicked:");