From: Hannu Niemistö Date: Fri, 24 Nov 2017 11:53:15 +0000 (+0200) Subject: Copy-paste in SCL issues view X-Git-Tag: v1.31.0~17 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F1262%2F3;p=simantics%2Fplatform.git Copy-paste in SCL issues view refs #7643 Change-Id: I3a417ccaba81e3df9a0dfa796756ebb9362603eb --- diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java index 10e2288e1..9f4994eb1 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/issues/SCLIssuesView.java @@ -1,5 +1,10 @@ package org.simantics.scl.ui.issues; +import java.util.Iterator; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.resource.ImageRegistry; @@ -11,6 +16,9 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; 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.ControlAdapter; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.graphics.Image; @@ -23,6 +31,7 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.ui.IMemento; import org.eclipse.ui.IViewSite; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.part.ViewPart; import org.simantics.scl.compiler.errors.ErrorSeverity; import org.simantics.scl.osgi.SCLOsgi; @@ -43,6 +52,8 @@ public class SCLIssuesView extends ViewPart { SCLIssuesContentProvider issuesContentProvider = new SCLIssuesContentProvider(); + Clipboard clipboard; + public SCLIssuesView() { super(); imageRegistry = Activator.getInstance().getImageRegistry(); @@ -65,10 +76,12 @@ public class SCLIssuesView extends ViewPart { @Override public void createPartControl(Composite parent) { + this.clipboard = new Clipboard(parent.getDisplay()); + this.parent = parent; parent.setLayout(new FillLayout()); tableViewer = new TableViewer(parent, - SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL); + SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); ColumnViewerToolTipSupport.enableFor(tableViewer); tableViewer.setContentProvider(issuesContentProvider); @@ -148,6 +161,25 @@ public class SCLIssuesView extends ViewPart { entry.openLocation(); } }); + + IHandlerService serv = (IHandlerService) getSite().getService(IHandlerService.class); + serv.activateHandler(org.eclipse.ui.IWorkbenchCommandConstants.EDIT_COPY, new CopyHandler()); + } + + class CopyHandler extends AbstractHandler { + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IStructuredSelection selection = tableViewer.getStructuredSelection(); + if(!selection.isEmpty()) { + StringBuilder b = new StringBuilder(); + for(Iterator it=selection.iterator();it.hasNext();) { + SCLIssuesTableEntry entry = (SCLIssuesTableEntry)it.next(); + b.append(entry.moduleName).append('\t').append(entry.error.description).append('\n'); + } + clipboard.setContents(new Object[] { b.toString() }, new Transfer[] { TextTransfer.getInstance() }); + } + return null; + } } private void resizeColumns() { @@ -179,6 +211,10 @@ public class SCLIssuesView extends ViewPart { public void dispose() { super.dispose(); issuesContentProvider.dispose(); + if(clipboard != null) { + clipboard.dispose(); + clipboard = null; + } } }