mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-09 19:43:27 +02:00
Fix for browsing workspace functionality in the FileListControl: more smart linked resource and non-default project location handling
This commit is contained in:
parent
20a2976398
commit
918b130a5b
1 changed files with 24 additions and 19 deletions
|
@ -135,7 +135,6 @@ public class FileListControl {
|
||||||
|
|
||||||
String currentPathText;
|
String currentPathText;
|
||||||
IPath path;
|
IPath path;
|
||||||
IResource resource = null;
|
|
||||||
|
|
||||||
currentPathText = getText().getText();
|
currentPathText = getText().getText();
|
||||||
if(contextInfo != null){
|
if(contextInfo != null){
|
||||||
|
@ -158,39 +157,45 @@ public class FileListControl {
|
||||||
|
|
||||||
/* Remove workspace location prefix (if any) */
|
/* Remove workspace location prefix (if any) */
|
||||||
path = new Path(currentPathText);
|
path = new Path(currentPathText);
|
||||||
IPath workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
|
|
||||||
|
|
||||||
if (workspacePath.isPrefixOf(path)) {
|
|
||||||
path = path.removeFirstSegments(workspacePath.segmentCount());
|
|
||||||
path = path.setDevice(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get resource for path. We use fProject if path is invalid.*/
|
|
||||||
if (!path.toString().trim().equals("")) { //$NON-NLS-1$
|
|
||||||
resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
|
|
||||||
}
|
|
||||||
if (resource == null)
|
|
||||||
resource = rc;
|
|
||||||
|
|
||||||
/* Create workspace folder/file selection dialog and
|
/* Create workspace folder/file selection dialog and
|
||||||
* set initial selection */
|
* set initial selection */
|
||||||
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(),
|
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(),
|
||||||
new WorkbenchLabelProvider(), new WorkbenchContentProvider());
|
new WorkbenchLabelProvider(), new WorkbenchContentProvider());
|
||||||
|
|
||||||
dialog.setInitialSelection(resource);
|
|
||||||
|
|
||||||
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
|
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
|
||||||
dialog.setSorter(new ResourceSorter(ResourceSorter.NAME));
|
dialog.setSorter(new ResourceSorter(ResourceSorter.NAME));
|
||||||
|
|
||||||
if (type == IOption.BROWSE_DIR) {
|
if (type == IOption.BROWSE_DIR) {
|
||||||
if (!(resource instanceof IContainer))
|
IResource container = null;
|
||||||
resource = null;
|
if(path.isAbsolute()){
|
||||||
|
IContainer cs[] = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(path);
|
||||||
|
if(cs != null && cs.length > 0)
|
||||||
|
container = cs[0];
|
||||||
|
}
|
||||||
|
if(container == null && rc instanceof IContainer)
|
||||||
|
container = rc;
|
||||||
|
|
||||||
|
|
||||||
|
dialog.setInitialSelection(container);
|
||||||
|
|
||||||
Class[] filteredResources = {IContainer.class, IProject.class};
|
Class[] filteredResources = {IContainer.class, IProject.class};
|
||||||
dialog.addFilter(new TypedViewerFilter(filteredResources));
|
dialog.addFilter(new TypedViewerFilter(filteredResources));
|
||||||
dialog.setTitle(WORKSPACE_DIR_DIALOG_TITLE);
|
dialog.setTitle(WORKSPACE_DIR_DIALOG_TITLE);
|
||||||
dialog.setMessage(WORKSPACE_DIR_DIALOG_MSG);
|
dialog.setMessage(WORKSPACE_DIR_DIALOG_MSG);
|
||||||
} else {
|
} else {
|
||||||
|
IResource resource = null;
|
||||||
|
if(path.isAbsolute()){
|
||||||
|
IFile fs[] = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||||
|
if(fs != null && fs.length > 0)
|
||||||
|
resource = fs[0];
|
||||||
|
}
|
||||||
|
if(resource == null)
|
||||||
|
resource = rc;
|
||||||
|
|
||||||
|
|
||||||
|
dialog.setInitialSelection(resource);
|
||||||
|
|
||||||
dialog.setValidator(new ISelectionStatusValidator() {
|
dialog.setValidator(new ISelectionStatusValidator() {
|
||||||
public IStatus validate(Object[] selection) {
|
public IStatus validate(Object[] selection) {
|
||||||
if (selection != null)
|
if (selection != null)
|
||||||
|
@ -212,7 +217,7 @@ public class FileListControl {
|
||||||
if (dialog.open() == Window.OK) {
|
if (dialog.open() == Window.OK) {
|
||||||
fSetByBrowseDialog = true;
|
fSetByBrowseDialog = true;
|
||||||
|
|
||||||
resource = (IResource) dialog.getFirstResult();
|
IResource resource = (IResource) dialog.getFirstResult();
|
||||||
|
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
getText().setText(variableManager.generateVariableExpression(WORKSPACELOC_VAR,
|
getText().setText(variableManager.generateVariableExpression(WORKSPACELOC_VAR,
|
||||||
|
|
Loading…
Add table
Reference in a new issue