mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
2005-07-16 Alain Magloire
Fix for PR 102327: Fire deltas when contentType is changed. * model/org/eclipse/cdt/core/model/ICElementDelta.java * model/org/eclipse/cdt/internal/core/model/CElementDelta.java * model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java
This commit is contained in:
parent
54101f2441
commit
d2aff435e1
4 changed files with 66 additions and 10 deletions
|
@ -1,3 +1,9 @@
|
|||
2005-07-16 Alain Magloire
|
||||
Fix for PR 102327: Fire deltas when contentType is changed.
|
||||
* model/org/eclipse/cdt/core/model/ICElementDelta.java
|
||||
* model/org/eclipse/cdt/internal/core/model/CElementDelta.java
|
||||
* model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java
|
||||
|
||||
2005-07-14 Vladimir Hirsl
|
||||
Fix for 103024: NPE in indexerEncoderUtil.nodeInVisitedExternalEheader
|
||||
Project was not being set when creating indexer in IndexManager#getDefaultIndexer().
|
||||
|
|
|
@ -167,6 +167,11 @@ public interface ICElementDelta {
|
|||
*/
|
||||
public int F_BINARY_PARSER_CHANGED = 0x800000;
|
||||
|
||||
/**
|
||||
* Change in the binary Parser.
|
||||
*/
|
||||
public int F_CONTENT_TYPE = 0x1000000;
|
||||
|
||||
/**
|
||||
* Returns deltas for the children that have been added.
|
||||
*/
|
||||
|
|
|
@ -698,6 +698,12 @@ public class CElementDelta implements ICElementDelta {
|
|||
buffer.append("PATHENTRY REORDER"); //$NON-NLS-1$
|
||||
prev = true;
|
||||
}
|
||||
if ((changeFlags & ICElementDelta.F_CONTENT_TYPE) != 0) {
|
||||
if (prev)
|
||||
buffer.append(" | "); //$NON-NLS-1$
|
||||
buffer.append("CONTENT_TYPE"); //$NON-NLS-1$
|
||||
prev = true;
|
||||
}
|
||||
|
||||
//if ((changeFlags & ICElementDelta.F_SUPER_TYPES) != 0) {
|
||||
// if (prev)
|
||||
|
|
|
@ -85,6 +85,10 @@ public class ContentTypeProcessor extends CModelOperation {
|
|||
}
|
||||
|
||||
private boolean isRegisteredContentTypeId(String id) {
|
||||
// bailout early
|
||||
if (id == null || id.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
String[] ids = CoreModel.getRegistedContentTypeIds();
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
if (ids[i].equals(id)) {
|
||||
|
@ -95,6 +99,35 @@ public class ContentTypeProcessor extends CModelOperation {
|
|||
}
|
||||
|
||||
protected void processContentType(ICElement celement, IContentType contentType, IScopeContext context) {
|
||||
/*
|
||||
* We only know that an association was added/removed from the contentType.
|
||||
* we need to go to all the members that are in the cache(known ICElement) and recheck there
|
||||
* state to see if there were affected. That also include children that were non-celement
|
||||
* the new assiociation may have turn them to new ICElement.
|
||||
* algo:
|
||||
* if ICContainer check if we have a CElementinfo(children)
|
||||
* if yes,
|
||||
* look at the members(IResource) and get there contentType
|
||||
* if the type is the same as the event
|
||||
* check if element was already a celement
|
||||
* if yes,
|
||||
* check if the element as the same contentType
|
||||
* if yes,
|
||||
* do nothing
|
||||
* else
|
||||
* if the content ID is registered ID
|
||||
* fired changed event
|
||||
* else
|
||||
* fire remove event
|
||||
* check for the CElement
|
||||
* get the new oldID and the newID
|
||||
* if not equal
|
||||
* check if the newID is registered
|
||||
* if yes
|
||||
* fire changed event
|
||||
* else
|
||||
* fire remove event
|
||||
*/
|
||||
if (celement instanceof IOpenable) {
|
||||
int type = celement.getElementType();
|
||||
// if the type is not a TranslationUnit
|
||||
|
@ -128,11 +161,14 @@ public class ContentTypeProcessor extends CModelOperation {
|
|||
if (cType != null && cType.equals(contentType)) {
|
||||
boolean found = false;
|
||||
for (int j = 0; j < celements.length; ++j) {
|
||||
if (celements[j].getElementName().equals(name)
|
||||
&& celements[j].getElementType() == ICElement.C_UNIT) {
|
||||
ITranslationUnit unit = (ITranslationUnit)celements[j];
|
||||
if (!cType.getId().equals(unit.getContentTypeId())) {
|
||||
elementChanged(celements[j]);
|
||||
if (celements[j].getElementName().equals(name)) {
|
||||
if (celements[j].getElementType() == ICElement.C_UNIT) {
|
||||
ITranslationUnit unit = (ITranslationUnit)celements[j];
|
||||
if (!cType.getId().equals(unit.getContentTypeId())) {
|
||||
if (isRegisteredContentTypeId(cType.getId())) {
|
||||
elementChanged(celements[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
found = true;
|
||||
break;
|
||||
|
@ -158,12 +194,15 @@ public class ContentTypeProcessor extends CModelOperation {
|
|||
}
|
||||
break;
|
||||
case ICElement.C_UNIT: {
|
||||
String id = ((ITranslationUnit)celement).getContentTypeId();
|
||||
if (contentType.getId().equals(id)) {
|
||||
String oldId = ((ITranslationUnit)celement).getContentTypeId();
|
||||
if (contentType.getId().equals(oldId)) {
|
||||
try {
|
||||
IContentType cType = CCorePlugin.getContentType(celement.getCProject().getProject(), celement.getElementName());
|
||||
if (cType != null && isRegisteredContentTypeId(cType.getId())) {
|
||||
elementChanged(celement);
|
||||
String newId = (cType != null) ? cType.getId() : ""; //$NON-NLS-1$
|
||||
if (isRegisteredContentTypeId(newId)) {
|
||||
if (!oldId.equals(newId)) {
|
||||
elementChanged(celement);
|
||||
}
|
||||
} else {
|
||||
elementRemoved(celement, celement.getParent());
|
||||
}
|
||||
|
@ -257,7 +296,7 @@ public class ContentTypeProcessor extends CModelOperation {
|
|||
if (element instanceof IOpenable) {
|
||||
((IOpenable)element).close();
|
||||
}
|
||||
fCurrentDelta.changed(element, ICElementDelta.F_CONTENT);
|
||||
fCurrentDelta.changed(element, ICElementDelta.F_CONTENT |ICElementDelta.F_CONTENT_TYPE);
|
||||
}
|
||||
/**
|
||||
* Removes the given element from its parents cache of children. If the
|
||||
|
|
Loading…
Add table
Reference in a new issue