1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Use ${ProjName} for workspace includes when possible

Use ${ProjName} for workspace includes referencing folders from
the project to better support project renames 

Inspired by the implementation for selecting includes in build
settings located in FileListControl.java 

Fixes #402

---------

Co-authored-by: jantje <eclipse@baeyens.it>
Co-authored-by: Jonah Graham <jonah@kichwacoders.com>
This commit is contained in:
jantje 2023-06-08 01:24:31 +02:00 committed by GitHub
parent 9dcaf509fa
commit 501e7db9a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 9 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: %pluginName Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.ui; singleton:=true Bundle-SymbolicName: org.eclipse.cdt.ui; singleton:=true
Bundle-Version: 8.0.200.qualifier Bundle-Version: 8.1.0.qualifier
Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin
Bundle-Vendor: %providerName Bundle-Vendor: %providerName
Bundle-Localization: plugin Bundle-Localization: plugin

View file

@ -496,28 +496,43 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab {
} }
public static String getWorkspaceDirDialog(Shell shell, String text) { public static String getWorkspaceDirDialog(Shell shell, String text) {
return getWorkspaceDialog(shell, text, true, null); return getWorkspaceDialog(shell, text, true, true, null);
} }
public static String getWorkspaceFileDialog(Shell shell, String text) { public static String getWorkspaceFileDialog(Shell shell, String text) {
return getWorkspaceDialog(shell, text, false, null); return getWorkspaceDialog(shell, text, false, true, null);
}
/**
* @since 8.1
*/
public static String getWorkspaceDirDialog(Shell shell, String text, IProject prj) {
return getWorkspaceDialog(shell, text, true, true, prj);
}
/**
* @since 8.1
*/
public static String getWorkspaceFileDialog(Shell shell, String text, IProject prj) {
return getWorkspaceDialog(shell, text, false, true, prj);
} }
/** /**
* @since 5.4 * @since 5.4
*/ */
public static String getProjectDirDialog(Shell shell, String text, IProject prj) { public static String getProjectDirDialog(Shell shell, String text, IProject prj) {
return getWorkspaceDialog(shell, text, true, prj); return getWorkspaceDialog(shell, text, true, false, prj);
} }
/** /**
* @since 5.4 * @since 5.4
*/ */
public static String getProjectFileDialog(Shell shell, String text, IProject prj) { public static String getProjectFileDialog(Shell shell, String text, IProject prj) {
return getWorkspaceDialog(shell, text, false, prj); return getWorkspaceDialog(shell, text, false, false, prj);
} }
private static String getWorkspaceDialog(Shell shell, String text, boolean dir, IProject prj) { private static String getWorkspaceDialog(Shell shell, String text, boolean dir, boolean selectFromRoot,
IProject prj) {
String currentPathText; String currentPathText;
IPath path; IPath path;
currentPathText = text; currentPathText = text;
@ -528,7 +543,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(),
new WorkbenchContentProvider()); new WorkbenchContentProvider());
if (prj == null) if (prj == null || selectFromRoot)
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
else else
dialog.setInput(prj); dialog.setInput(prj);
@ -576,8 +591,14 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab {
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
IResource resource = (IResource) dialog.getFirstResult(); IResource resource = (IResource) dialog.getFirstResult();
if (resource != null) { if (resource != null) {
if (resource.getProject().equals(prj)) {
String projectPath = new Path("${ProjName}").append(resource.getProjectRelativePath()) //$NON-NLS-1$
.makeAbsolute().toString();
return "${workspace_loc:" + projectPath + "}"; //$NON-NLS-1$ //$NON-NLS-2$
}
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
return buf.append("${").append("workspace_loc:").append(resource.getFullPath()).append("}").toString(); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ return buf.append("${").append("workspace_loc:").append(resource.getFullPath()).append("}").toString(); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
} }
} }
return null; return null;

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription;
import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.Messages;
import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CDTSharedImages;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyEvent;
@ -205,10 +206,11 @@ public class IncludeDialog extends AbstractPropertyDialog {
} else if (e.widget.equals(b_ko)) { } else if (e.widget.equals(b_ko)) {
shell.dispose(); shell.dispose();
} else if (e.widget.equals(b_work)) { } else if (e.widget.equals(b_work)) {
IProject project = cfgd.getProjectDescription().getProject();
if ((mode & DIR_MASK) == DIR_MASK) if ((mode & DIR_MASK) == DIR_MASK)
s = AbstractCPropertyTab.getWorkspaceDirDialog(shell, text.getText()); s = AbstractCPropertyTab.getWorkspaceDirDialog(shell, text.getText(), project);
else else
s = AbstractCPropertyTab.getWorkspaceFileDialog(shell, text.getText()); s = AbstractCPropertyTab.getWorkspaceFileDialog(shell, text.getText(), project);
if (s != null) { if (s != null) {
s = strip_wsp(s); s = strip_wsp(s);
text.setText(s); text.setText(s);