1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 325773 - Support copy in the Executables View. Fix up line endings.

This commit is contained in:
Ken Ryall 2010-09-21 18:38:43 +00:00
parent 45f057367a
commit a0b5fe2c89

View file

@ -10,6 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.views.executables; package org.eclipse.cdt.debug.internal.ui.views.executables;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
@ -50,22 +53,30 @@ public class ExecutablesViewCopyHandler extends AbstractHandler {
} }
if (selection instanceof IStructuredSelection) { if (selection instanceof IStructuredSelection) {
StringBuilder sb = new StringBuilder(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
Iterator<?> iter = ((IStructuredSelection) selection).iterator(); PrintStream ps = new PrintStream(baos);
Iterator<?> iter = ((IStructuredSelection) selection).iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Object obj = iter.next(); Object obj = iter.next();
if (obj instanceof Executable) { if (obj instanceof Executable) {
Executable exe = (Executable) obj; Executable exe = (Executable) obj;
sb.append(exe.getName()).append("\n"); //$NON-NLS-1$ ps.println(exe.getName());
} else if (obj instanceof ITranslationUnit) { } else if (obj instanceof ITranslationUnit) {
ITranslationUnit tu = (ITranslationUnit) obj; ITranslationUnit tu = (ITranslationUnit) obj;
sb.append(tu.getLocation().toFile().getName()).append("\n"); //$NON-NLS-1$ ps.println(tu.getLocation().toFile().getName());
} else } else
sb.append(obj.toString()).append("\n"); //$NON-NLS-1$ ps.println(obj.toString());
} }
ps.flush();
try {
baos.flush();
} catch (IOException e) {
throw new ExecutionException("", e); //$NON-NLS-1$
}
Clipboard cp = getClipboard(); Clipboard cp = getClipboard();
cp.setContents(new Object[] { sb.toString().trim() }, cp.setContents(new Object[] { baos.toString().trim() },
new Transfer[] { TextTransfer.getInstance() }); new Transfer[] { TextTransfer.getInstance() });
} }