Skip to content

Commit

Permalink
Fix #7045.
Browse files Browse the repository at this point in the history
Former-commit-id: 43797c6dd97440e8e9370eb684bfb220897df38c
  • Loading branch information
dkocher committed Aug 18, 2013
1 parent eb86b93 commit fafe102
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
5 changes: 5 additions & 0 deletions source/ch/cyberduck/core/DescriptiveUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ public boolean equals(final Object o) {
public int hashCode() {
return url != null ? url.hashCode() : 0;
}

@Override
public String toString() {
return this.getUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ protected List<DescriptiveUrl> getURLs(Path selected) {
}

@Override
public void handle(final List<String> selected) {
public void handle(final List<DescriptiveUrl> selected) {
final StringBuilder url = new StringBuilder();
for(Iterator<String> iter = selected.iterator(); iter.hasNext(); ) {
url.append(iter.next());
for(Iterator<DescriptiveUrl> iter = selected.iterator(); iter.hasNext(); ) {
url.append(iter.next().getUrl());
if(iter.hasNext()) {
url.append("\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ protected List<DescriptiveUrl> getURLs(Path selected) {
}

@Override
public void handle(final List<String> selected) {
for(String url : selected) {
BrowserLauncherFactory.get().open(url);
public void handle(final List<DescriptiveUrl> selected) {
for(DescriptiveUrl url : selected) {
BrowserLauncherFactory.get().open(url.getUrl());
}
}
}
61 changes: 29 additions & 32 deletions source/ch/cyberduck/ui/cocoa/delegate/URLMenuDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.rococoa.cocoa.foundation.NSInteger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -85,7 +84,7 @@ public NSInteger numberOfItemsInMenu(NSMenu menu) {

@Override
public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger index, boolean cancel) {
List<Path> selected = this.getSelected();
final List<Path> selected = this.getSelected();
if(0 == index.intValue()) {
this.setShortcut(item, this.getKeyEquivalent(), this.getModifierMask());
}
Expand All @@ -100,68 +99,66 @@ public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger ind
item.setImage(null);
}
else {
final StringBuilder builder = new StringBuilder();
for(Iterator<Path> iter = selected.iterator(); iter.hasNext(); ) {
List<DescriptiveUrl> urls = this.getURLs(iter.next());
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) {
// Dummy menu item to preview URL only
item.setEnabled(true);
item.setTarget(this.id());
item.setAction(Foundation.selector("menuItemClicked:"));
item.setImage(IconCacheFactory.<NSImage>get().iconNamed("site.tiff", 16));
Iterator<Path> iter = selected.iterator();
DescriptiveUrl url = this.getURLs(iter.next()).get(index.intValue() / 2);
item.setRepresentedObject(s);
final DescriptiveUrl url = this.getURLs(iter.next()).get(index.intValue() / 2);
item.setRepresentedObject(url.getUrl());
item.setTitle(url.getHelp());
}
else {
// Dummy menu item to preview URL only
if(StringUtils.isNotBlank(s)) {
item.setAttributedTitle(NSAttributedString.attributedStringWithAttributes(s, URL_FONT_ATTRIBUTES));
}
else {
item.setAttributedTitle(NSAttributedString.attributedStringWithAttributes(LocaleFactory.localizedString("Unknown"), URL_FONT_ATTRIBUTES));
}
final List<DescriptiveUrl> target = this.getURLs(index, selected);
item.setAttributedTitle(NSAttributedString.attributedStringWithAttributes(
StringUtils.join(target, '\n'), URL_FONT_ATTRIBUTES));
}
}
return super.menuUpdateItemAtIndex(menu, item, index, cancel);
}

private List<DescriptiveUrl> getURLs(final NSInteger index, final List<Path> selected) {
List<DescriptiveUrl> list = new ArrayList<DescriptiveUrl>();
for(final Path file : selected) {
final List<DescriptiveUrl> urls = this.getURLs(file);
final DescriptiveUrl url = urls.get(index.intValue() / 2);
list.add(url);
}
return list;
}

@Action
public void menuActionSelected(final NSMenu sender) {
public void menuActionSelected(final NSMenu menu) {
if(log.isDebugEnabled()) {
log.debug("menuActionSelected:" + sender);
log.debug("menuActionSelected:" + menu);
}
List<String> selected = new ArrayList<String>();
for(Path path : this.getSelected()) {
selected.add(this.getURLs(path).iterator().next().getUrl());
List<DescriptiveUrl> selected = new ArrayList<DescriptiveUrl>();
for(Path file : this.getSelected()) {
selected.add(this.getURLs(file).iterator().next());
}
this.handle(selected);
}

@Action
public void menuItemClicked(final NSMenuItem sender) {
public void menuItemClicked(final NSMenuItem item) {
if(log.isDebugEnabled()) {
log.debug("menuItemClicked:" + sender);
log.debug("menuItemClicked:" + item);
}
this.handle(Arrays.asList(StringUtils.split(sender.representedObject(), "\n")));
this.handle(this.getURLs(item.menu().indexOfItem(item), this.getSelected()));
}

/**
* @param selected URLs of selected files.
*/
public abstract void handle(final List<String> selected);
public abstract void handle(final List<DescriptiveUrl> selected);

@Override
public boolean validateMenuItem(NSMenuItem item) {
if(this.getSelected().isEmpty()) {
public boolean validateMenuItem(final NSMenuItem item) {
final List<Path> selected = this.getSelected();
if(selected.isEmpty()) {
return false;
}
final Selector action = item.action();
Expand Down
1 change: 1 addition & 0 deletions test/ch/cyberduck/core/DescriptiveUrlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void testEquals() throws Exception {
new DescriptiveUrl(URI.create("http://host.domain"), DescriptiveUrl.Type.provider, "b")));
assertTrue(new DescriptiveUrl(URI.create("http://host.domain"), DescriptiveUrl.Type.provider).equals(
new DescriptiveUrl(URI.create("http://host.domain"), DescriptiveUrl.Type.http)));
assertEquals("http://host.domain", new DescriptiveUrl(URI.create("http://host.domain"), DescriptiveUrl.Type.http).toString());
}

@Test
Expand Down

0 comments on commit fafe102

Please sign in to comment.