diff options
| author | Martin Karpisek | 2016-10-06 16:01:41 +0000 |
|---|---|---|
| committer | Lars Vogel | 2016-10-11 06:38:36 +0000 |
| commit | 23ebaaa6b197036805bbba45ec2221b7c8bf0b0f (patch) | |
| tree | 72fc95883b806eaec1dad2d2fab466babf983dbb | |
| parent | 64962b342f63ef0f5ba74b7c27aea704c88d2cda (diff) | |
| download | eclipse.platform.ui-23ebaaa6b197036805bbba45ec2221b7c8bf0b0f.tar.gz eclipse.platform.ui-23ebaaa6b197036805bbba45ec2221b7c8bf0b0f.tar.xz eclipse.platform.ui-23ebaaa6b197036805bbba45ec2221b7c8bf0b0f.zip | |
Bug 160802: [Markers] Problems View, Errors: must copy whole line
- patch adds Copy Details submenu with additional commands (inspired by
similar use case in Mylyn, consistent naming)
- submenu contains "Description" and "Qualified Name" (inspired by JDT)
items for copying these information into clipboard
- patch intentionally do not put menu item for each possible attribute
as it would be too much and not usefull (just most usefull ones)
- main "copy" item remain unchanged - for generating tab-separated
report of all visible information as until now
- patch works for different kinds of markers (errors, warnings in
"Problems View" or tasks in "Task View")
- fixes also similar bug 244965
Change-Id: I510d61ef7599992e769ca5cd4b33f7a5701d397a
Signed-off-by: Martin Karpisek <martin.karpisek@gmail.com>
5 files changed, 170 insertions, 1 deletions
diff --git a/bundles/org.eclipse.ui.ide/icons/full/elcl16/cpyqual_menu.png b/bundles/org.eclipse.ui.ide/icons/full/elcl16/cpyqual_menu.png Binary files differnew file mode 100644 index 00000000000..16a838b58eb --- /dev/null +++ b/bundles/org.eclipse.ui.ide/icons/full/elcl16/cpyqual_menu.png diff --git a/bundles/org.eclipse.ui.ide/plugin.properties b/bundles/org.eclipse.ui.ide/plugin.properties index 1add4c0b3d7..cf1b45aa66d 100644 --- a/bundles/org.eclipse.ui.ide/plugin.properties +++ b/bundles/org.eclipse.ui.ide/plugin.properties @@ -188,7 +188,12 @@ command.copyBuildIdCommand.name=Copy Build Id Information To Clipboard command.copyBuildIdCommand.description=Copies the build identification information to the clipboard. command.copyConfigCommand.name=Copy Configuration Data To Clipboard command.copyConfigCommand.description=Copies the configuration data (system properties, installed bundles, etc) to the clipboard. - +command.copyDescription.name=Copy Description To Clipboard +command.copyDescription.label=Description +command.copyDescription.description=Copies markers description field to the clipboard +command.copyMarkerResourceQualifiedName.name=Copy Resource Qualified Name To Clipboard +command.copyMarkerResourceQualifiedName.label=Resource Qualified Name +command.copyMarkerResourceQualifiedName.description=Copies markers resource qualified name to the clipboard command.showInQuickMenu.name= Show In... @@ -327,6 +332,8 @@ menu.window.appearance.label=Appearance menu.window.appearance.mnemonic=a menu.window.appearance.tooltip=Change appearance of Windows and Toolbars +menu.copyDetails.label=Copy Details + systemEditorThenTextEditor=System Editor; if none: Text Editor askUserViaPopup=Ask via pop-up textEditor=Text Editor diff --git a/bundles/org.eclipse.ui.ide/plugin.xml b/bundles/org.eclipse.ui.ide/plugin.xml index 7720ade10b1..afe4466f20c 100644 --- a/bundles/org.eclipse.ui.ide/plugin.xml +++ b/bundles/org.eclipse.ui.ide/plugin.xml @@ -1038,6 +1038,20 @@ optional="true"> </commandParameter> </command> + <command + categoryId="org.eclipse.ui.category.edit" + description="%command.copyDescription.description" + id="org.eclipse.ui.ide.markers.copyDescription" + name="%command.copyDescription.name" + defaultHandler="org.eclipse.ui.internal.views.markers.CopyMarkerDescriptionHandler"> + </command> + <command + categoryId="org.eclipse.ui.category.edit" + description="%command.copyMarkerResourceQualifiedName.description" + id="org.eclipse.ui.ide.markers.copyMarkerResourceQualifiedName" + name="%command.copyMarkerResourceQualifiedName.name" + defaultHandler="org.eclipse.ui.internal.views.markers.CopyMarkerResourceQualifiedNameHandler"> + </command> </extension> <extension @@ -1752,6 +1766,25 @@ <command commandId="org.eclipse.ui.edit.copy"> </command> + <menu + id="org.eclipse.ui.ide.markers.copyDetailsMenu" + label="%menu.copyDetails.label"> + <command + commandId="org.eclipse.ui.ide.markers.copyDescription" + label="%command.copyDescription.label" + style="push"> + </command> + <command + commandId="org.eclipse.ui.ide.markers.copyMarkerResourceQualifiedName" + icon="icons/full/elcl16/cpyqual_menu.png" + label="%command.copyMarkerResourceQualifiedName.label" + style="push"> + </command> + <dynamic + class="org.eclipse.ui.ExtensionFactory:copyDetailsContribution" + id="org.eclipse.ui.menus.dynamicCopyDetailsMenu"> + </dynamic> + </menu> <command commandId="org.eclipse.ui.edit.delete"> </command> diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CopyMarkerDescriptionHandler.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CopyMarkerDescriptionHandler.java new file mode 100644 index 00000000000..825531f2faa --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CopyMarkerDescriptionHandler.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2016 Martin Karpisek 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: + * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.views.markers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IMarker; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.ui.part.MarkerTransfer; +import org.eclipse.ui.views.markers.MarkerViewHandler; + +/** + * Handler to copy from selected marker its description into clipboard. + * In case more then one markers are selected, descriptions in clipboard are separated by newline. + * @since 4.7 + */ +public class CopyMarkerDescriptionHandler extends MarkerViewHandler { + /** + * Generates for provided markers text which will be in clipboard if this + * handler is executed. + */ + static String createMarkersReport(final IMarker[] markers) { + final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$ + + final StringBuffer report = new StringBuffer(); + for (int i = 0; i < markers.length; i++) { + if (i > 0) { + report.append(NEWLINE); + } + Object message = markers[i].getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$ + if (message != null) { + report.append(message); + } + } + return report.toString(); + } + + @Override + public Object execute(final ExecutionEvent event) { + final ExtendedMarkersView view = getView(event); + if (view == null) { + return null; + } + + setClipboard(view); + return this; + } + + private void setClipboard(final ExtendedMarkersView view) { + final IMarker[] markers = view.getSelectedMarkers(); + final String markerReport = createMarkersReport(markers); + + Object[] data = new Object[] { markers, markerReport }; + Transfer[] transferTypes = new Transfer[] { MarkerTransfer.getInstance(), TextTransfer.getInstance() }; + + view.getClipboard().setContents(data, transferTypes); + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CopyMarkerResourceQualifiedNameHandler.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CopyMarkerResourceQualifiedNameHandler.java new file mode 100644 index 00000000000..f03385c81c5 --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CopyMarkerResourceQualifiedNameHandler.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2016 Martin Karpisek 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: + * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.views.markers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IMarker; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.ui.part.MarkerTransfer; +import org.eclipse.ui.views.markers.MarkerViewHandler; + +/** + * Handler to copy from selected marker its resource qualified name into clipboard. + * In case more then one markers are selected, resource names in clipboard are separated by newline. + * @since 4.7 + */ +public class CopyMarkerResourceQualifiedNameHandler extends MarkerViewHandler { + /** + * Generates for provided markers text which will be in clipboard if this + * handler is executed. + */ + static String createMarkersReport(final IMarker[] markers) { + final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$ + + final StringBuffer report = new StringBuffer(); + for (int i = 0; i < markers.length; i++) { + if (i > 0) { + report.append(NEWLINE); + } + report.append(markers[i].getResource().getFullPath()); + } + return report.toString(); + } + + @Override + public Object execute(final ExecutionEvent event) { + final ExtendedMarkersView view = getView(event); + if (view == null) { + return null; + } + + setClipboard(view); + return this; + } + + private void setClipboard(final ExtendedMarkersView view) { + final IMarker[] markers = view.getSelectedMarkers(); + final String markerReport = createMarkersReport(markers); + + Object[] data = new Object[] { markers, markerReport }; + Transfer[] transferTypes = new Transfer[] { MarkerTransfer.getInstance(), TextTransfer.getInstance() }; + + view.getClipboard().setContents(data, transferTypes); + } +} |
