Skip to content

Commit

Permalink
Fix #5135.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Sep 16, 2010
1 parent 95a6898 commit 302f304
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
4 changes: 2 additions & 2 deletions source/ch/cyberduck/ui/cocoa/MainController.java
Expand Up @@ -232,7 +232,7 @@ protected List<Path> getSelected() {
return selected;
}
}
return null;
return Collections.emptyList();
}
};
this.urlMenu.setDelegate(urlMenuDelegate.id());
Expand All @@ -259,7 +259,7 @@ protected List<Path> getSelected() {
return selected;
}
}
return null;
return Collections.emptyList();
}
};
this.openUrlMenu.setDelegate(openUrlMenuDelegate.id());
Expand Down
24 changes: 13 additions & 11 deletions source/ch/cyberduck/ui/cocoa/delegate/OpenURLMenuDelegate.java
Expand Up @@ -27,8 +27,10 @@
import ch.cyberduck.ui.cocoa.application.NSEvent;
import ch.cyberduck.ui.cocoa.application.NSMenuItem;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import java.util.Collections;
import java.util.List;


Expand All @@ -53,27 +55,27 @@ protected String getLabel() {
return Locale.localizedString("Open");
}

@Override
protected List<Path> getSelected() {
return Collections.emptyList();
}

/**
* Only select URLs with http://
*
* @param selected
* @return
*/
@Override
protected List<AbstractPath.DescriptiveUrl> getURLs(List<Path> selected) {
return selected.iterator().next().getHttpURLs();
protected List<AbstractPath.DescriptiveUrl> getURLs(Path selected) {
return selected.getHttpURLs();
}

@Action
@Override
public void urlClicked(final NSMenuItem sender) {
this.open(sender.representedObject());
}

/**
* @param url
*/
private void open(String url) {
BundleController.openUrl(url);
for(String url : StringUtils.split(sender.representedObject(), "\n")) {
BundleController.openUrl(url);
}
}
}
}
34 changes: 24 additions & 10 deletions source/ch/cyberduck/ui/cocoa/delegate/URLMenuDelegate.java
Expand Up @@ -41,6 +41,7 @@
import org.apache.log4j.Logger;

import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;

/**
Expand Down Expand Up @@ -74,15 +75,17 @@ public abstract class URLMenuDelegate extends AbstractMenuDelegate {
protected abstract String getLabel();

public NSInteger numberOfItemsInMenu(NSMenu menu) {
List<Path> path = this.getSelected();
if(path.isEmpty()) {
List<Path> selected = this.getSelected();
if(selected.isEmpty()) {
return new NSInteger(1);
}
return new NSInteger(this.getURLs(path).size() * 2);
// Number of URLs for a single path
int urls = this.getURLs(selected.iterator().next()).size();
return new NSInteger(urls * 2);
}

protected List<AbstractPath.DescriptiveUrl> getURLs(List<Path> selected) {
return selected.iterator().next().getURLs();
protected List<AbstractPath.DescriptiveUrl> getURLs(Path selected) {
return selected.getURLs();
}

@Override
Expand All @@ -101,19 +104,30 @@ public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger ind
item.setImage(null);
}
else {
AbstractPath.DescriptiveUrl url = this.getURLs(selected).get(index.intValue() / 2);
item.setRepresentedObject(url.getUrl());
final StringBuilder builder = new StringBuilder();
for(Iterator<Path> iter = selected.iterator(); iter.hasNext();) {
List<AbstractPath.DescriptiveUrl> urls = this.getURLs(iter.next());
AbstractPath.DescriptiveUrl url = urls.get(index.intValue() / 2);
builder.append(url.getUrl());
if(iter.hasNext()) {
builder.append("\n");
}
}
String s = builder.toString();
boolean label = index.intValue() % 2 == 0;
if(label) {
item.setEnabled(true);
item.setImage(IconCache.iconNamed("site.tiff", 16));
item.setAction(Foundation.selector("urlClicked:"));
Iterator<Path> iter = selected.iterator();
AbstractPath.DescriptiveUrl url = this.getURLs(iter.next()).get(index.intValue() / 2);
item.setRepresentedObject(s);
item.setTitle(url.getHelp());
}
else {
item.setImage(IconCache.iconNamed("site.tiff", 16));
// Dummy menu item to preview URL only
if(StringUtils.isNotBlank(url.getUrl())) {
item.setAttributedTitle(NSAttributedString.attributedStringWithAttributes(url.getUrl(), URL_FONT_ATTRIBUTES));
if(StringUtils.isNotBlank(s)) {
item.setAttributedTitle(NSAttributedString.attributedStringWithAttributes(s, URL_FONT_ATTRIBUTES));
}
else {
item.setAttributedTitle(NSAttributedString.attributedStringWithAttributes(Locale.localizedString("Unknown"), URL_FONT_ATTRIBUTES));
Expand Down

0 comments on commit 302f304

Please sign in to comment.