1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.io.ByteArrayOutputStream ; 14 import java.io.PrintStream ; 15 16 import org.eclipse.core.resources.mapping.ResourceMapping; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.swt.dnd.*; 19 import org.eclipse.team.internal.ccvs.core.CVSException; 20 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 21 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 22 import org.eclipse.ui.IWorkbenchPart; 23 24 public class ClipboardDiffOperation extends DiffOperation { 25 26 private static final Object DESTINATION_CLIPBOARD = CVSUIMessages.ClipboardDiffOperation_Clipboard; 27 28 final ByteArrayOutputStream os = new ByteArrayOutputStream (); 29 30 public ClipboardDiffOperation(IWorkbenchPart part, ResourceMapping[] mappings, LocalOption[] options, boolean isMultiPatch, boolean includeFullPathInformation, IPath patchRoot) { 31 super(part, mappings, options, isMultiPatch, includeFullPathInformation, patchRoot, DESTINATION_CLIPBOARD); 32 } 33 34 public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 35 super.execute(monitor); 36 37 if (os.size() == 0 || 38 (!patchHasContents && !patchHasNewFiles)) { 39 reportEmptyDiff(); 40 } else { 41 copyToClipboard(os); 42 } 43 } 44 45 private void copyToClipboard(final ByteArrayOutputStream baos) { 46 getShell().getDisplay().syncExec(new Runnable () { 47 public void run() { 48 TextTransfer plainTextTransfer = TextTransfer.getInstance(); 49 Clipboard clipboard = new Clipboard(getShell().getDisplay()); 50 clipboard.setContents( 51 new String []{baos.toString()}, 52 new Transfer[]{plainTextTransfer}); 53 clipboard.dispose(); 54 } 55 }); 56 } 57 58 61 protected PrintStream openStream() { 62 return new PrintStream (os); 63 } 64 } 65 | Popular Tags |