1 package ch
.cyberduck
.ui
.cocoa
.delegate
;
4 * Copyright (c) 2002-2010 David Kocher. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * Bug fixes, suggestions and comments should be sent to:
19 * dkocher@cyberduck.ch
22 import ch
.cyberduck
.core
.DescriptiveUrl
;
23 import ch
.cyberduck
.core
.Path
;
24 import ch
.cyberduck
.core
.UrlProvider
;
25 import ch
.cyberduck
.core
.cdn
.DistributionConfiguration
;
26 import ch
.cyberduck
.binding
.application
.NSEvent
;
27 import ch
.cyberduck
.binding
.application
.NSPasteboard
;
28 import ch
.cyberduck
.binding
.foundation
.NSArray
;
29 import ch
.cyberduck
.binding
.foundation
.NSString
;
31 import org
.apache
.log4j
.Logger
;
33 import java
.util
.ArrayList
;
34 import java
.util
.Iterator
;
35 import java
.util
.List
;
40 public abstract class CopyURLMenuDelegate
extends URLMenuDelegate
{
41 private static final Logger log
= Logger
.getLogger(CopyURLMenuDelegate
.class);
44 protected String
getKeyEquivalent() {
49 protected int getModifierMask() {
50 return NSEvent
.NSCommandKeyMask
| NSEvent
.NSShiftKeyMask
;
54 protected List
<DescriptiveUrl
> getURLs(Path selected
) {
55 final ArrayList
<DescriptiveUrl
> list
= new ArrayList
<DescriptiveUrl
>();
56 final UrlProvider provider
= this.getSession().getFeature(UrlProvider
.class);
57 if(provider
!= null) {
58 list
.addAll(provider
.toUrl(selected
));
60 final DistributionConfiguration feature
= this.getSession().getFeature(DistributionConfiguration
.class);
62 list
.addAll(feature
.toUrl(selected
));
68 public void handle(final List
<DescriptiveUrl
> selected
) {
69 final StringBuilder url
= new StringBuilder();
70 for(Iterator
<DescriptiveUrl
> iter
= selected
.iterator(); iter
.hasNext(); ) {
71 url
.append(iter
.next().getUrl());
76 final NSPasteboard pboard
= NSPasteboard
.generalPasteboard();
77 pboard
.declareTypes(NSArray
.arrayWithObject(NSString
.stringWithString(NSPasteboard
.StringPboardType
)), null);
78 if(!pboard
.setStringForType(url
.toString(), NSPasteboard
.StringPboardType
)) {
79 log
.error(String
.format("Error writing URL to %s", NSPasteboard
.StringPboardType
));