use of org.eclipse.swt.dnd.TextTransfer in project egit by eclipse.
the class StagingView method copyPathOfSelectionToClipboard.
private void copyPathOfSelectionToClipboard(final TreeViewer viewer) {
Clipboard cb = new Clipboard(viewer.getControl().getDisplay());
TextTransfer t = TextTransfer.getInstance();
String text = getTextFrom((IStructuredSelection) viewer.getSelection());
try {
if (text != null) {
cb.setContents(new Object[] { text }, new Transfer[] { t });
}
} finally {
cb.dispose();
}
}
use of org.eclipse.swt.dnd.TextTransfer in project egit by eclipse.
the class CopyPathCommand method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
RepositoryTreeNode node = getSelectedNodes(event).get(0);
String path;
switch(node.getType()) {
case REPO:
path = node.getRepository().getDirectory().toString();
break;
case WORKINGDIR:
if (node.getRepository().isBare())
return null;
path = node.getRepository().getWorkTree().toString();
break;
case FILE:
path = ((FileNode) node).getObject().getPath().toString();
break;
case FOLDER:
path = ((FolderNode) node).getObject().getPath().toString();
break;
default:
return null;
}
Clipboard clipboard = new Clipboard(null);
try {
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { path };
clipboard.setContents(data, transfers);
} finally {
clipboard.dispose();
}
return null;
}
Aggregations