mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 325773 - Support copy in the Executables View
This commit is contained in:
parent
ce50ee07e2
commit
3cacbafb08
3 changed files with 156 additions and 2 deletions
|
@ -2392,6 +2392,23 @@
|
|||
class="org.eclipse.cdt.debug.internal.ui.actions.CastToArrayActionHandler"
|
||||
commandId="org.eclipse.cdt.debug.ui.command.castToArray">
|
||||
</handler>
|
||||
</extension>
|
||||
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler commandId="org.eclipse.ui.edit.copy"
|
||||
class="org.eclipse.cdt.debug.internal.ui.views.executables.ExecutablesViewCopyHandler">
|
||||
<enabledWhen>
|
||||
<not>
|
||||
<count value="0" />
|
||||
</not>
|
||||
</enabledWhen>
|
||||
<activeWhen>
|
||||
<with variable="activePartId">
|
||||
<equals value="org.eclipse.cdt.debug.ui.executablesView" />
|
||||
</with>
|
||||
</activeWhen>
|
||||
</handler>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -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<String> 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) {
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue