Search in sources :

Example 76 with TextTransfer

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();
    }
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 77 with TextTransfer

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;
}
Also used : RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

TextTransfer (org.eclipse.swt.dnd.TextTransfer)77 Clipboard (org.eclipse.swt.dnd.Clipboard)65 Point (org.eclipse.swt.graphics.Point)19 Transfer (org.eclipse.swt.dnd.Transfer)18 TableItem (org.eclipse.swt.widgets.TableItem)14 StyledText (org.eclipse.swt.custom.StyledText)10 Control (org.eclipse.swt.widgets.Control)8 Text (org.eclipse.swt.widgets.Text)6 IAction (org.eclipse.jface.action.IAction)5 HTMLTransfer (org.eclipse.swt.dnd.HTMLTransfer)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Button (org.eclipse.swt.widgets.Button)5 Composite (org.eclipse.swt.widgets.Composite)5 ArrayList (java.util.ArrayList)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Label (org.eclipse.swt.widgets.Label)4