From 3cacbafb081c488af54877201e94e988c13f65b5 Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Mon, 20 Sep 2010 15:47:04 +0000 Subject: [PATCH] Bug 325773 - Support copy in the Executables View --- debug/org.eclipse.cdt.debug.ui/plugin.xml | 21 +++++- .../ui/views/executables/ExecutablesView.java | 62 +++++++++++++++ .../ExecutablesViewCopyHandler.java | 75 +++++++++++++++++++ 3 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesViewCopyHandler.java diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 63e9ffdfa51..d8aabedb828 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -2392,6 +2392,23 @@ class="org.eclipse.cdt.debug.internal.ui.actions.CastToArrayActionHandler" commandId="org.eclipse.cdt.debug.ui.command.castToArray"> - - + + + + + + + + + + + + + + + + + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesView.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesView.java index 6b7bc77906c..4a35f5c5b0b 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesView.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesView.java @@ -34,6 +34,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; @@ -42,6 +43,8 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; @@ -52,6 +55,7 @@ import org.eclipse.ui.IViewSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.XMLMemento; +import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.dialogs.ListSelectionDialog; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.progress.UIJob; @@ -223,11 +227,13 @@ public class ExecutablesView extends ViewPart { Action refreshAction; Action importAction; Action removeAction; + private Action copyAction; private Action configureColumnsAction; private IMemento memento; private IStructuredSelection oldSelection; + private ISelectionProvider focusedViewer; /** * Create contents of the Executables View @@ -243,9 +249,50 @@ public class ExecutablesView extends ViewPart { // Create the two sub viewers. executablesViewer = new ExecutablesViewer(this, sashForm, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI); + focusedViewer = executablesViewer; ExecutablesManager.getExecutablesManager().addExecutablesChangeListener(executablesViewer); sourceFilesViewer = new SourceFilesViewer(this, sashForm, SWT.BORDER | SWT.MULTI); + executablesViewer.getTree().addFocusListener(new FocusListener() { + + public void focusLost(FocusEvent e) {} + + public void focusGained(FocusEvent e) { + focusedViewer = executablesViewer; + } + }); + + sourceFilesViewer.getTree().addFocusListener(new FocusListener() { + + public void focusLost(FocusEvent e) {} + + public void focusGained(FocusEvent e) { + focusedViewer = sourceFilesViewer; + } + }); + + ExecutablesView.this.getViewSite().setSelectionProvider(new ISelectionProvider() { + + public void setSelection(ISelection selection) { + getFocusedViewer().setSelection(selection); + } + + public void removeSelectionChangedListener( + ISelectionChangedListener listener) { + executablesViewer.removeSelectionChangedListener(listener); + sourceFilesViewer.removeSelectionChangedListener(listener); + } + + public ISelection getSelection() { + return getFocusedViewer().getSelection(); + } + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + executablesViewer.addSelectionChangedListener(listener); + sourceFilesViewer.addSelectionChangedListener(listener); + } + }); + sashForm.setWeights(new int[] { 1, 1 }); // Keep a combined list of all the columns so @@ -298,6 +345,10 @@ public class ExecutablesView extends ViewPart { PlatformUI.getWorkbench().getHelpSystem().setHelp(container, EXECUTABLES_VIEW_CONTEXT); } + protected ISelectionProvider getFocusedViewer() { + return focusedViewer; + } + private void setVisibleColumns(String[] ids) { List visibleNames = Arrays.asList(ids); for (int i = 0; i < columnNames.length; i++) { @@ -348,9 +399,20 @@ public class ExecutablesView extends ViewPart { configureColumnsAction = createConfigureColumnsAction(); toolBarManager.add(configureColumnsAction); + + copyAction = createCopyAction(); + bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction ); } + private Action createCopyAction() { + Action action = new Action("Copy") { //$NON-NLS-1$ + + }; + return action; + + } + private Action createRemoveAction() { Action action = new Action(Messages.ExecutablesView_Remove) { diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesViewCopyHandler.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesViewCopyHandler.java new file mode 100644 index 00000000000..d53443aca30 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesViewCopyHandler.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2010 Nokia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nokia - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.internal.ui.views.executables; + +import java.util.Iterator; + +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.debug.core.executables.Executable; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.handlers.HandlerUtil; + +public class ExecutablesViewCopyHandler extends AbstractHandler { + + private Clipboard clipboard; + + private Clipboard getClipboard() { + if (clipboard == null) + clipboard = new Clipboard(Display.getDefault()); + return clipboard; + } + + @Override + public void dispose() { + super.dispose(); + if (clipboard != null) + clipboard.dispose(); + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = HandlerUtil.getCurrentSelection(event); + + if (selection == null) { + return null; + } + + if (selection instanceof IStructuredSelection) { + StringBuilder sb = new StringBuilder(); + Iterator iter = ((IStructuredSelection) selection).iterator(); + while (iter.hasNext()) { + Object obj = iter.next(); + if (obj instanceof Executable) { + Executable exe = (Executable) obj; + sb.append(exe.getName()).append("\n"); //$NON-NLS-1$ + } else if (obj instanceof ITranslationUnit) { + ITranslationUnit tu = (ITranslationUnit) obj; + sb.append(tu.getLocation().toFile().getName()).append("\n"); //$NON-NLS-1$ + } else + sb.append(obj.toString()).append("\n"); //$NON-NLS-1$ + + } + Clipboard cp = getClipboard(); + cp.setContents(new Object[] { sb.toString().trim() }, + new Transfer[] { TextTransfer.getInstance() }); + } + + return null; + } + +}