mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 487336 - Add copy text to clipboard action to "OS Resources" view
Change-Id: I3d109ad1194b09f83d3633491c1368255551fd9a Signed-off-by: Teodor Madan <teodor.madan@nxp.com>
This commit is contained in:
parent
15436d74df
commit
eb24d01ad9
4 changed files with 64 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2011, 2012 Mentor Graphics and others.
|
* Copyright (c) 2011, 2016 Mentor Graphics and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -44,6 +44,11 @@ implements ITableLabelProvider, IStructuredContentProvider
|
||||||
this.realProvider = realProvider;
|
this.realProvider = realProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public U getData()
|
||||||
|
{
|
||||||
|
return realProvider;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Image getColumnImage(Object obj, int index) {
|
public Image getColumnImage(Object obj, int index) {
|
||||||
return realProvider.getColumnImage(obj, index);
|
return realProvider.getColumnImage(obj, index);
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class Messages extends NLS {
|
||||||
public static String OSView_15;
|
public static String OSView_15;
|
||||||
public static String OSView_AttachJobName;
|
public static String OSView_AttachJobName;
|
||||||
public static String OSView_AttachTask;
|
public static String OSView_AttachTask;
|
||||||
|
public static String OSView_CopyAction;
|
||||||
static {
|
static {
|
||||||
// initialize resource bundle
|
// initialize resource bundle
|
||||||
NLS.initializeMessages(Messages.class.getName(), Messages.class);
|
NLS.initializeMessages(Messages.class.getName(), Messages.class);
|
||||||
|
|
|
@ -23,3 +23,4 @@ OSView_14=Objects from different debug sessions are selected.
|
||||||
OSView_15=No debug session is selected.
|
OSView_15=No debug session is selected.
|
||||||
OSView_AttachJobName=Connecting debug session to processes
|
OSView_AttachJobName=Connecting debug session to processes
|
||||||
OSView_AttachTask=Connecting to process {0}
|
OSView_AttachTask=Connecting to process {0}
|
||||||
|
OSView_CopyAction=Copy
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
|
||||||
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
|
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
|
||||||
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
|
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
|
||||||
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
|
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
|
||||||
|
import org.eclipse.cdt.dsf.gdb.service.IGDBHardwareAndOS2.IResourcesInformation;
|
||||||
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
||||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||||
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
|
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
|
||||||
|
@ -53,11 +54,15 @@ import org.eclipse.jface.viewers.Viewer;
|
||||||
import org.eclipse.jface.viewers.ViewerComparator;
|
import org.eclipse.jface.viewers.ViewerComparator;
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.dnd.Clipboard;
|
||||||
|
import org.eclipse.swt.dnd.TextTransfer;
|
||||||
|
import org.eclipse.swt.dnd.Transfer;
|
||||||
import org.eclipse.swt.events.SelectionAdapter;
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
import org.eclipse.swt.events.SelectionEvent;
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Event;
|
import org.eclipse.swt.widgets.Event;
|
||||||
import org.eclipse.swt.widgets.Link;
|
import org.eclipse.swt.widgets.Link;
|
||||||
import org.eclipse.swt.widgets.Listener;
|
import org.eclipse.swt.widgets.Listener;
|
||||||
|
@ -65,7 +70,10 @@ import org.eclipse.swt.widgets.Menu;
|
||||||
import org.eclipse.swt.widgets.Table;
|
import org.eclipse.swt.widgets.Table;
|
||||||
import org.eclipse.swt.widgets.TableColumn;
|
import org.eclipse.swt.widgets.TableColumn;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
|
import org.eclipse.ui.ISharedImages;
|
||||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||||
|
import org.eclipse.ui.PlatformUI;
|
||||||
|
import org.eclipse.ui.actions.ActionFactory;
|
||||||
import org.eclipse.ui.part.ViewPart;
|
import org.eclipse.ui.part.ViewPart;
|
||||||
import org.eclipse.ui.progress.UIJob;
|
import org.eclipse.ui.progress.UIJob;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
|
@ -189,6 +197,7 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
bars.getToolBarManager().add(fRefreshAction);
|
bars.getToolBarManager().add(fRefreshAction);
|
||||||
|
bars.setGlobalActionHandler(ActionFactory.COPY.getId(), new CopyAction());
|
||||||
bars.updateActionBars();
|
bars.updateActionBars();
|
||||||
|
|
||||||
createContextMenu();
|
createContextMenu();
|
||||||
|
@ -209,6 +218,7 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded
|
||||||
menuMgr.addMenuListener(new IMenuListener() {
|
menuMgr.addMenuListener(new IMenuListener() {
|
||||||
@Override
|
@Override
|
||||||
public void menuAboutToShow(IMenuManager manager) {
|
public void menuAboutToShow(IMenuManager manager) {
|
||||||
|
manager.add(new CopyAction());
|
||||||
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -717,4 +727,50 @@ public class OSResourcesView extends ViewPart implements DsfSession.SessionEnded
|
||||||
public ICommandControlDMContext getSessionContext() {
|
public ICommandControlDMContext getSessionContext() {
|
||||||
return fSessionData != null ? fSessionData.getContext() : null;
|
return fSessionData != null ? fSessionData.getContext() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retargetted copy to clipboard action
|
||||||
|
*/
|
||||||
|
private final class CopyAction extends Action {
|
||||||
|
private static final char COLUMN_SEPARATOR = ',';
|
||||||
|
private final String EOL_CHAR = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
private CopyAction() {
|
||||||
|
setText(Messages.OSView_CopyAction);
|
||||||
|
setImageDescriptor(
|
||||||
|
PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return !fViewer.getSelection().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ISelection selection = fViewer.getSelection();
|
||||||
|
if (selection.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (selection instanceof IStructuredSelection) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
OSData data = ((ContentLabelProviderWrapper<OSData>) fViewer.getContentProvider()).getData();
|
||||||
|
StringBuilder exportStr = new StringBuilder();
|
||||||
|
for (Object elmnt : ((IStructuredSelection) selection).toList()) {
|
||||||
|
assert elmnt instanceof IResourcesInformation;
|
||||||
|
if (elmnt instanceof IResourcesInformation) {
|
||||||
|
IResourcesInformation ri = (IResourcesInformation) elmnt;
|
||||||
|
exportStr.append(data.getColumnText(ri, 0));
|
||||||
|
for (int i = 1; i < data.getColumnCount(); i++) {
|
||||||
|
exportStr.append(COLUMN_SEPARATOR).append(data.getColumnText(ri, i));
|
||||||
|
}
|
||||||
|
exportStr.append(EOL_CHAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Clipboard cb = new Clipboard(Display.getDefault());
|
||||||
|
TextTransfer textTransfer = TextTransfer.getInstance();
|
||||||
|
cb.setContents(new Object[] { exportStr.toString() }, new Transfer[] { textTransfer });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue