Skip to content

Commit

Permalink
Copy as path for resources
Browse files Browse the repository at this point in the history
A new copy button is introduced in properties dialog

Fixes eclipse-platform#998
Review points incorporated.

Fixes eclipse-platform#998
  • Loading branch information
Dinesh0723 authored and vogella committed Dec 1, 2023
1 parent 898a0a0 commit a2113d4
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ public class IDEWorkbenchMessages extends NLS {
public static String ResourceInfo_type;
public static String ResourceInfo_location;
public static String ResourceInfo_location_button_tooltip;
public static String ResourceInfo_path_button_tooltip;
public static String ResourceInfo_resolvedLocation;
public static String ResourceInfo_size;
public static String ResourceInfo_bytes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,9 +14,13 @@
* Serge Beauchamp (Freescale Semiconductor) - [229633] Project Path Variable Support
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 474273
* Simon Scholz <simon.scholz@vogella.com> - Bug 486777
* Dinesh Palanisamy (ETAS GmbH) - Issue #998 Copy as path for resources
*******************************************************************************/
package org.eclipse.ui.internal.ide.dialogs;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -79,6 +83,7 @@
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor;
Expand Down Expand Up @@ -147,6 +152,8 @@ private interface IResourceChange {

private static String LOCATION_BUTTON_TOOLTIP = IDEWorkbenchMessages.ResourceInfo_location_button_tooltip;

private static String PATH_BUTTON_TOOLTIP = IDEWorkbenchMessages.ResourceInfo_path_button_tooltip;

private static String RESOLVED_LOCATION_TITLE = IDEWorkbenchMessages.ResourceInfo_resolvedLocation;

private static String SIZE_TITLE = IDEWorkbenchMessages.ResourceInfo_size;
Expand Down Expand Up @@ -183,7 +190,7 @@ private Composite createBasicInfoGroup(Composite parent, IResource resource) {

Composite basicInfoComposite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
layout.numColumns = 4;
layout.marginWidth = 0;
layout.marginHeight = 0;
basicInfoComposite.setLayout(layout);
Expand All @@ -209,7 +216,7 @@ private Composite createBasicInfoGroup(Composite parent, IResource resource) {
gd.widthHint = convertWidthInCharsToPixels(MAX_VALUE_WIDTH);
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
gd.horizontalSpan = 2;
gd.horizontalSpan = 3;
pathValueText.setLayoutData(gd);
pathValueText.setBackground(pathValueText.getDisplay().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
Expand All @@ -219,7 +226,7 @@ private Composite createBasicInfoGroup(Composite parent, IResource resource) {
typeTitle.setText(TYPE_TITLE);

Text typeValue = new Text(basicInfoComposite, SWT.LEFT | SWT.READ_ONLY);
GridDataFactory.swtDefaults().span(2, SWT.DEFAULT).applyTo(typeValue);
GridDataFactory.swtDefaults().span(3, SWT.DEFAULT).applyTo(typeValue);
typeValue.setText(IDEResourceInfoUtils.getTypeString(resource,
getContentDescription(resource)));
typeValue.setBackground(typeValue.getDisplay().getSystemColor(
Expand All @@ -245,7 +252,7 @@ private Composite createBasicInfoGroup(Composite parent, IResource resource) {
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.TOP;
gd.horizontalAlignment = GridData.FILL;
gd.horizontalSpan = 2;
gd.horizontalSpan = 3;
locationComposite.setLayoutData(gd);

locationValue = new Text(locationComposite, SWT.WRAP
Expand All @@ -268,7 +275,7 @@ private Composite createBasicInfoGroup(Composite parent, IResource resource) {
((GridData) editButton.getLayoutData()).verticalAlignment = SWT.TOP;
int locationValueHeight = locationValue.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).y;
int editButtonHeight = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).y;
int verticalIndent = (editButtonHeight - locationValueHeight) / 2 ;
int verticalIndent = (editButtonHeight - locationValueHeight) / 2;
((GridData) locationTitle.getLayoutData()).verticalIndent = verticalIndent;
((GridData) locationValue.getLayoutData()).verticalIndent = verticalIndent;
editButton.addSelectionListener(new SelectionListener() {
Expand Down Expand Up @@ -299,7 +306,7 @@ public void widgetSelected(SelectionEvent e) {
gd.widthHint = convertWidthInCharsToPixels(MAX_VALUE_WIDTH);
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
gd.horizontalSpan = 2;
gd.horizontalSpan = 3;
resolvedLocationValue.setLayoutData(gd);
resolvedLocationValue.setBackground(resolvedLocationValue
.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
Expand Down Expand Up @@ -350,6 +357,18 @@ public void widgetSelected(SelectionEvent e) {
}
}
});

Button pathCopy = new Button(basicInfoComposite, SWT.PUSH);
pathCopy.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
pathCopy.setToolTipText(PATH_BUTTON_TOOLTIP);
pathCopy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StringSelection strSelection = new StringSelection(locationStr);
Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
systemClipboard.setContents(strSelection, null);
}
});
}
if (resource.getType() == IResource.FILE) {
// The group for size
Expand All @@ -363,7 +382,7 @@ public void widgetSelected(SelectionEvent e) {
gd.widthHint = convertWidthInCharsToPixels(MAX_VALUE_WIDTH);
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
gd.horizontalSpan = 2;
gd.horizontalSpan = 3;
sizeValue.setLayoutData(gd);
sizeValue.setBackground(sizeValue.getDisplay().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
Expand All @@ -379,7 +398,7 @@ public void widgetSelected(SelectionEvent e) {
timeStampValue.setBackground(timeStampValue.getDisplay()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
gridData.horizontalSpan = 2;
gridData.horizontalSpan = 3;
timeStampValue.setLayoutData(gridData);

return basicInfoComposite;
Expand Down Expand Up @@ -485,7 +504,7 @@ protected Control createContents(Composite parent) {
setPermissionsSelection(previousPermissionsValue);
}
}
//We can't save and load the preferences for closed project
// We can't save and load the preferences for closed project
if (resource.getProject().isOpen()) {
encodingEditor = new ResourceEncodingFieldEditor(
getFieldEditorLabel(resource), composite, resource);
Expand Down Expand Up @@ -1049,11 +1068,11 @@ public void performChange(IResource resource) {
};
}

private List/*<IResource>*/ getResourcesToVisit(IResource resource) throws CoreException {
private List/* <IResource> */ getResourcesToVisit(IResource resource) throws CoreException {
// use set for fast lookup
final Set/*<URI>*/ visited = new HashSet/*<URI>*/();
final Set/* <URI> */ visited = new HashSet/* <URI> */();
// use list to preserve the order of visited resources
final List/*<IResource>*/ toVisit = new ArrayList/*<IResource>*/();
final List/* <IResource> */ toVisit = new ArrayList/* <IResource> */();
visited.add(resource.getLocationURI());
resource.accept(proxy -> {
IResource childResource = proxy.requestResource();
Expand All @@ -1067,7 +1086,7 @@ public void performChange(IResource resource) {
return toVisit;
}

private boolean shouldPerformRecursiveChanges(List/*<IResourceChange>*/ changes) {
private boolean shouldPerformRecursiveChanges(List/* <IResourceChange> */ changes) {
if (!changes.isEmpty()) {
StringBuilder message = new StringBuilder(IDEWorkbenchMessages.ResourceInfo_recursiveChangesSummary)
.append('\n');
Expand All @@ -1087,23 +1106,23 @@ private boolean shouldPerformRecursiveChanges(List/*<IResourceChange>*/ changes)
return false;
}

private void scheduleRecursiveChangesJob(final IResource resource, final List/*<IResourceChange>*/ changes) {
private void scheduleRecursiveChangesJob(final IResource resource, final List/* <IResourceChange> */ changes) {
Job.create(IDEWorkbenchMessages.ResourceInfo_recursiveChangesJobName, monitor -> {
try {
List/*<IResource>*/ toVisit = getResourcesToVisit(resource);
List/* <IResource> */ toVisit = getResourcesToVisit(resource);

// Prepare the monitor for the given amount of work
SubMonitor subMonitor = SubMonitor.convert(monitor,
IDEWorkbenchMessages.ResourceInfo_recursiveChangesJobName,
toVisit.size());

// Apply changes recursively
for (Iterator/*<IResource>*/ it = toVisit.iterator(); it.hasNext();) {
for (Iterator /* <IResource> */ it = toVisit.iterator(); it.hasNext();) {
SubMonitor iterationMonitor = subMonitor.split(1).setWorkRemaining(changes.size());
IResource childResource = (IResource) it.next();
iterationMonitor.subTask(NLS
.bind(IDEWorkbenchMessages.ResourceInfo_recursiveChangesSubTaskName,
childResource.getFullPath()));
childResource.getFullPath()));
for (Object change : changes) {
iterationMonitor.split(1);
((IResourceChange) change)
Expand Down Expand Up @@ -1147,7 +1166,7 @@ public boolean performOk() {
new NullProgressMonitor());
}

List/*<IResourceChange>*/ changes = new ArrayList/*<IResourceChange>*/();
List/* <IResourceChange> */ changes = new ArrayList/* <IResourceChange> */();

ResourceAttributes attrs = resource.getResourceAttributes();
if (attrs != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ ResourceInfo_derivedHasDerivedAncestor = Deri&ved (has derived ancestor)
ResourceInfo_type = T&ype:
ResourceInfo_location = &Location:
ResourceInfo_location_button_tooltip = Show In System Explorer
ResourceInfo_path_button_tooltip = Copy full path
ResourceInfo_resolvedLocation = Resolved locatio&n:
ResourceInfo_size = &Size:
ResourceInfo_bytes = {0} bytes
Expand Down
Loading

0 comments on commit a2113d4

Please sign in to comment.