1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-09 19:43:27 +02:00

Allow the setting/getting of IPathEntryStore on a Project

This commit is contained in:
Alain Magloire 2004-05-14 21:01:08 +00:00
parent 7037b5ada3
commit 08ca38925b
2 changed files with 56 additions and 28 deletions

View file

@ -11,6 +11,7 @@ import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.filetype.ICFileType; import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.filetype.ICFileTypeAssociation; import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
import org.eclipse.cdt.core.filetype.ICFileTypeResolver; import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.internal.core.model.BatchOperation; import org.eclipse.cdt.internal.core.model.BatchOperation;
import org.eclipse.cdt.internal.core.model.CModel; import org.eclipse.cdt.internal.core.model.CModel;
import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.CModelManager;
@ -825,6 +826,14 @@ public class CoreModel {
// return null; // return null;
//} //}
public static IPathEntryStore getPathEntryStore(IProject project) throws CoreException {
return CCorePlugin.getDefault().getPathEntryStore(project);
}
public static void setPathEntryStore(IProject project, IPathEntryStore store) {
pathEntryManager.setPathEntryStore(project, store);
}
/** /**
* Return the singleton. * Return the singleton.
*/ */

View file

@ -40,6 +40,7 @@ import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
@ -375,27 +376,37 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return; return;
} }
// trigger model refresh // trigger model refresh
boolean shouldFire = false; try {
CModelManager mgr = CModelManager.getDefault(); //final boolean canChangeResources = !ResourcesPlugin.getWorkspace().isTreeLocked();
for (int i = 0; i < projectLength; i++) { CoreModel.run(new IWorkspaceRunnable() {
if (monitor != null && monitor.isCanceled()) { public void run(IProgressMonitor progressMonitor) throws CoreException {
return;
} boolean shouldFire = false;
ICProject affectedProject = modifiedProjects[i]; CModelManager mgr = CModelManager.getDefault();
if (affectedProject == null) { for (int i = 0; i < projectLength; i++) {
continue; // was filtered out if (progressMonitor != null && progressMonitor.isCanceled()) {
} return;
IPathEntry[] newEntries = getResolvedPathEntries(affectedProject); }
ICElementDelta[] deltas = generatePathEntryDeltas(affectedProject, oldResolvedEntries[i], newEntries); ICProject affectedProject = modifiedProjects[i];
if (deltas.length > 0) { if (affectedProject == null) {
shouldFire = true; continue; // was filtered out
for (int j = 0; j < deltas.length; j++) { }
mgr.registerCModelDelta(deltas[j]); IPathEntry[] newEntries = getResolvedPathEntries(affectedProject);
ICElementDelta[] deltas = generatePathEntryDeltas(affectedProject, oldResolvedEntries[i], newEntries);
if (deltas.length > 0) {
shouldFire = true;
for (int j = 0; j < deltas.length; j++) {
mgr.registerCModelDelta(deltas[j]);
}
}
}
if (shouldFire) {
mgr.fire(ElementChangedEvent.POST_CHANGE);
}
} }
} }, monitor);
} } catch (CoreException e ) {
if (shouldFire) { //
mgr.fire(ElementChangedEvent.POST_CHANGE);
} }
} }
@ -681,6 +692,21 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return containerIDs; return containerIDs;
} }
public void setPathEntryStore(IProject project, IPathEntryStore newStore) {
IPathEntryStore oldStore = null;
synchronized(this) {
oldStore = (IPathEntryStore)storeMap.remove(project);
if (newStore != null) {
storeMap.put(project, newStore);
}
}
if (oldStore != null) {
// remove are self before closing
oldStore.removePathEntryStoreListener(this);
oldStore.close();
}
}
private synchronized IPathEntryStore getPathEntryStore(IProject project, boolean create) throws CoreException { private synchronized IPathEntryStore getPathEntryStore(IProject project, boolean create) throws CoreException {
IPathEntryStore store = (IPathEntryStore)storeMap.get(project); IPathEntryStore store = (IPathEntryStore)storeMap.get(project);
if (store == null && create == true) { if (store == null && create == true) {
@ -691,13 +717,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return store; return store;
} }
private synchronized void removePathEntryStore(IProject project) {
IPathEntryStore store = (IPathEntryStore)storeMap.remove(project);
if (store!= null) {
store.removePathEntryStoreListener(this);
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent) * @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent)
*/ */
@ -712,7 +731,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
CModelManager manager = CModelManager.getDefault(); CModelManager manager = CModelManager.getDefault();
ICProject cproject = manager.create(project); ICProject cproject = manager.create(project);
if (event.hasClosed()) { if (event.hasClosed()) {
removePathEntryStore(project); setPathEntryStore(project, null);
containerRemove(cproject); containerRemove(cproject);
} }
if (project.isAccessible()) { if (project.isAccessible()) {