1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

fixed problem with applying path entry after switching between include & symbols and project path properies page.

needed to correctly merge and changes made by project path page with entries in include path page
This commit is contained in:
David Inglis 2004-09-08 14:58:12 +00:00
parent a617f1ba4d
commit 0ad9d83903
5 changed files with 78 additions and 71 deletions

View file

@ -37,7 +37,6 @@ import org.eclipse.core.runtime.SubProgressMonitor;
abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock implements ICOptionContainer { abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock implements ICOptionContainer {
private List fFilteredOut = new ArrayList();
private StatusInfo fCPathStatus; private StatusInfo fCPathStatus;
private StatusInfo fBuildPathStatus; private StatusInfo fBuildPathStatus;
@ -69,17 +68,40 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
* @return Returns the current class path (raw). Note that the entries * @return Returns the current class path (raw). Note that the entries
* returned must not be valid. * returned must not be valid.
*/ */
public IPathEntry[] getRawCPath() { public IPathEntry[] getRawCPath() throws CModelException{
List elements = getCPaths(); List elements = getCPaths();
int nElements = elements.size();
List entries = new ArrayList();
for (int i = 0; i < nElements; i++) { IPathEntry[] entries = fCurrCProject.getRawPathEntries();
CPElement currElement = (CPElement) elements.get(i); List cpath = new ArrayList(elements.size() + entries.length);
entries.add(currElement.getPathEntry());
int[] applyTypes = getAppliedFilteredTypes();
// create and set the paths
for (int i = 0; i < elements.size(); i++) {
CPElement entry = ((CPElement) elements.get(i));
for(int j = 0; j < applyTypes.length; j++) {
if (entry.getEntryKind() == applyTypes[j]) {
cpath.add(entry.getPathEntry());
break;
} }
entries.addAll(fFilteredOut); }
return (IPathEntry[]) entries.toArray(new IPathEntry[entries.size()]); }
// add entries which do not match type being applyed by the ui block
for(int i = 0; i < entries.length; i++) {
int pathType = entries[i].getEntryKind();
boolean found = false;
for(int j = 0; j < applyTypes.length; j++) {
if (pathType == applyTypes[j]) {
found = true;
break;
}
}
if (!found) {
cpath.add(entries[i]);
}
}
return (IPathEntry[]) cpath.toArray(new IPathEntry[cpath.size()]);
} }
/** /**
@ -117,19 +139,17 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
initialize(element, newCPath); initialize(element, newCPath);
} }
abstract protected int[] getFilteredTypes(); abstract protected int[] getFilteredTypes(); // path type which block would like access to
abstract protected int[] getAppliedFilteredTypes(); // path type which block modifies
abstract protected void initialize(ICElement element, List cPaths); abstract protected void initialize(ICElement element, List cPaths);
protected ArrayList getFilteredElements(IPathEntry[] cPathEntries, int[] types) { protected ArrayList getFilteredElements(IPathEntry[] cPathEntries, int[] types) {
ArrayList newCPath = new ArrayList(); ArrayList newCPath = new ArrayList();
fFilteredOut.clear();
for (int i = 0; i < cPathEntries.length; i++) { for (int i = 0; i < cPathEntries.length; i++) {
IPathEntry curr = cPathEntries[i]; IPathEntry curr = cPathEntries[i];
if (contains(types, curr.getEntryKind())) { if (contains(types, curr.getEntryKind())) {
newCPath.add(CPElement.createFromExisting(curr, fCurrCProject)); newCPath.add(CPElement.createFromExisting(curr, fCurrCProject));
} else {
fFilteredOut.add(curr);
} }
} }
return newCPath; return newCPath;
@ -268,19 +288,40 @@ abstract public class AbstractPathOptionBlock extends TabFolderOptionBlock imple
monitor.worked(2); monitor.worked(2);
List cpath = new ArrayList(cPathEntries.size() + fFilteredOut.size()); IPathEntry[] entries = fCurrCProject.getRawPathEntries();
List cpath = new ArrayList(cPathEntries.size() + entries.length);
int[] applyTypes = getAppliedFilteredTypes();
// create and set the paths // create and set the paths
for (int i = 0; i < cPathEntries.size(); i++) { for (int i = 0; i < cPathEntries.size(); i++) {
CPElement entry = ((CPElement) cPathEntries.get(i)); CPElement entry = ((CPElement) cPathEntries.get(i));
for(int j = 0; j < applyTypes.length; j++) {
if (entry.getEntryKind() == applyTypes[j]) {
IResource res = entry.getResource(); IResource res = entry.getResource();
if ((res instanceof IFolder) && !res.exists()) { if ((res instanceof IFolder) && !res.exists()) {
CoreUtility.createFolder((IFolder) res, true, true, null); CoreUtility.createFolder((IFolder) res, true, true, null);
} }
cpath.add(entry.getPathEntry()); cpath.add(entry.getPathEntry());
break;
}
}
} }
cpath.addAll(fFilteredOut);
// add entries which do not match type being applyed by the ui block
for(int i = 0; i < entries.length; i++) {
int pathType = entries[i].getEntryKind();
boolean found = false;
for(int j = 0; j < applyTypes.length; j++) {
if (pathType == applyTypes[j]) {
found = true;
break;
}
}
if (!found) {
cpath.add(entries[i]);
}
}
monitor.worked(1); monitor.worked(1);
getCProject().setRawPathEntries((IPathEntry[]) cpath.toArray(new IPathEntry[cpath.size()]), getCProject().setRawPathEntries((IPathEntry[]) cpath.toArray(new IPathEntry[cpath.size()]),

View file

@ -15,8 +15,6 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.resources.IPathEntryStore; import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener;
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler; import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
@ -42,7 +40,7 @@ import org.eclipse.ui.dialogs.PropertyPage;
/** /**
* @see PropertyPage * @see PropertyPage
*/ */
public class CPathPropertyPage extends PropertyPage implements IStatusChangeListener, IPathEntryStoreListener { public class CPathPropertyPage extends PropertyPage implements IStatusChangeListener{
private static final String PAGE_SETTINGS = "CPathsPropertyPage"; //$NON-NLS-1$ private static final String PAGE_SETTINGS = "CPathsPropertyPage"; //$NON-NLS-1$
private static final String INDEX = "pageIndex"; //$NON-NLS-1$ private static final String INDEX = "pageIndex"; //$NON-NLS-1$
@ -64,12 +62,6 @@ public class CPathPropertyPage extends PropertyPage implements IStatusChangeList
} else if (!project.isOpen()) { } else if (!project.isOpen()) {
result = createForClosedProject(parent); result = createForClosedProject(parent);
} else { } else {
try {
fStore = CoreModel.getPathEntryStore(getProject());
fStore.addPathEntryStoreListener(this);
} catch (CoreException e) {
}
result = createWithCProject(parent, project); result = createWithCProject(parent, project);
} }
Dialog.applyDialogFont(result); Dialog.applyDialogFont(result);
@ -201,16 +193,6 @@ public class CPathPropertyPage extends PropertyPage implements IStatusChangeList
return true; return true;
} }
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#dispose()
*/
public void dispose() {
if (fStore != null) {
fStore.removePathEntryStoreListener(this);
}
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -230,32 +212,6 @@ public class CPathPropertyPage extends PropertyPage implements IStatusChangeList
if (fCPathsBlock != null) { if (fCPathsBlock != null) {
getSettings().put(INDEX, fCPathsBlock.getPageIndex()); getSettings().put(INDEX, fCPathsBlock.getPageIndex());
} }
if (fStore != null) {
fStore.removePathEntryStoreListener(this);
}
return super.performCancel(); return super.performCancel();
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent)
*/
public void pathEntryStoreChanged(PathEntryStoreChangedEvent event) {
if (event.hasContentChanged()) {
Control control = getControl();
if (control != null && !control.isDisposed()) {
control.getDisplay().asyncExec(new Runnable() {
public void run() {
Control control = getControl();
if (control != null && !control.isDisposed()) {
fCPathsBlock.init(CoreModel.getDefault().create(getProject()), null);
}
}
});
}
}
}
} }

View file

@ -23,8 +23,8 @@ import org.eclipse.swt.widgets.Control;
public class CPathTabBlock extends AbstractPathOptionBlock { public class CPathTabBlock extends AbstractPathOptionBlock {
private int[] pathTypes = {IPathEntry.CDT_SOURCE, IPathEntry.CDT_PROJECT, IPathEntry.CDT_OUTPUT, IPathEntry.CDT_LIBRARY, private final int[] pathTypes = {IPathEntry.CDT_SOURCE, IPathEntry.CDT_PROJECT, IPathEntry.CDT_OUTPUT, IPathEntry.CDT_LIBRARY,IPathEntry.CDT_CONTAINER};
IPathEntry.CDT_CONTAINER};
private ListDialogField fCPathList; private ListDialogField fCPathList;
private CPathSourceEntryPage fSourcePage; private CPathSourceEntryPage fSourcePage;
@ -118,6 +118,9 @@ public class CPathTabBlock extends AbstractPathOptionBlock {
return pathTypes; return pathTypes;
} }
protected int[] getAppliedFilteredTypes() {
return pathTypes;
}
/** /**
* Validates the build path. * Validates the build path.
*/ */

View file

@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.resources.IPathEntryStore; import org.eclipse.cdt.core.resources.IPathEntryStore;
@ -249,7 +250,11 @@ public class IncludesSymbolsPropertyPage extends PropertyPage implements IStatus
public void run() { public void run() {
Control control = getControl(); Control control = getControl();
if (control != null && !control.isDisposed()) { if (control != null && !control.isDisposed()) {
fIncludesSymbolsBlock.init(getCElement(), null); try {
fIncludesSymbolsBlock.init(getCElement(), fIncludesSymbolsBlock.getRawCPath());
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
}
} }
} }
}); });

View file

@ -23,8 +23,6 @@ import org.eclipse.swt.widgets.Control;
public class NewIncludesSymbolsTabBlock extends AbstractPathOptionBlock implements IStatusChangeListener { public class NewIncludesSymbolsTabBlock extends AbstractPathOptionBlock implements IStatusChangeListener {
private int[] pathTypes = {IPathEntry.CDT_INCLUDE, IPathEntry.CDT_MACRO, IPathEntry.CDT_CONTAINER};
private CPathIncludeSymbolEntryPage fIncludeSymbols; private CPathIncludeSymbolEntryPage fIncludeSymbols;
private List fCPaths; private List fCPaths;
@ -68,7 +66,11 @@ public class NewIncludesSymbolsTabBlock extends AbstractPathOptionBlock implemen
} }
protected int[] getFilteredTypes() { protected int[] getFilteredTypes() {
return pathTypes; return new int[] {IPathEntry.CDT_INCLUDE, IPathEntry.CDT_MACRO, IPathEntry.CDT_CONTAINER};
}
protected int[] getAppliedFilteredTypes() {
return new int[] {IPathEntry.CDT_INCLUDE, IPathEntry.CDT_MACRO};
} }
protected void initialize(ICElement element, List cPaths) { protected void initialize(ICElement element, List cPaths) {