1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +02:00

2004-09-02 Chris Wiebe

fix editor/view selection problems
	* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingElementComparer.java
	* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java
	* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersView.java
	* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/NamespacesView.java
	* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypesView.java
This commit is contained in:
Chris Wiebe 2004-09-02 22:00:11 +00:00
parent 4fc3c3b548
commit 7d383dd0ce
6 changed files with 122 additions and 133 deletions

View file

@ -1,3 +1,12 @@
2004-09-02 Chris Wiebe
fix editor/view selection problems
* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingElementComparer.java
* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/CBrowsingPart.java
* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/MembersView.java
* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/NamespacesView.java
* browser/org/eclipse/cdt/internal/ui/browser/cbrowsing/TypesView.java
2004-09-01 Chris Wiebe
Fix for 68883

View file

@ -10,67 +10,17 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.browser.cbrowsing;
import org.eclipse.cdt.core.browser.TypeUtil;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.cdt.internal.ui.cview.CViewElementComparer;
public class CBrowsingElementComparer implements IElementComparer {
public class CBrowsingElementComparer extends CViewElementComparer {
public boolean equals(Object o1, Object o2) {
if (o1 == o2) // this handles also the case that both are null
return true;
if (o1 == null)
return false; // o2 != null if we reach this point
if (o1.equals(o2))
return true;
// Assume they are CElements
ICElement c1= (o1 instanceof ICElement) ? (ICElement)o1 : null;
ICElement c2= (o2 instanceof ICElement) ? (ICElement)o2 : null;
if (c1 == null || c2 == null)
return false;
// compare identical elements across working copies
if (c1.getElementType() == c2.getElementType()
&& c1.getElementName().equals(c2.getElementName())) {
if (TypeUtil.getFullyQualifiedName(c1).equals(TypeUtil.getFullyQualifiedName(c2))) {
return c1.getUnderlyingResource().equals(c2.getUnderlyingResource());
}
}
if (c1 instanceof ITranslationUnit) {
ITranslationUnit t1 = (ITranslationUnit)o1;
if (t1.isWorkingCopy()) {
c1 = ((IWorkingCopy)t1).getOriginalElement();
}
}
if (c2 instanceof ITranslationUnit) {
ITranslationUnit t2 = (ITranslationUnit)o2;
if (t2.isWorkingCopy()) {
c2 = ((IWorkingCopy)t2).getOriginalElement();
}
}
if (c1 == null || c2 == null) {
return false;
}
return c1.equals(c2);
//TODO compare ITypeInfos
return super.equals(o1, o2);
}
public int hashCode(Object o1) {
ICElement c1= (o1 instanceof ICElement) ? (ICElement)o1 : null;
if (c1 == null)
return o1.hashCode();
if (c1 instanceof ITranslationUnit) {
ITranslationUnit t1= (ITranslationUnit)c1;
if (t1.isWorkingCopy()) {
c1= ((IWorkingCopy)t1).getOriginalElement();
}
}
if (c1 == null) {
return o1.hashCode();
}
return c1.hashCode();
//TODO compare ITypeInfos
return super.hashCode(o1);
}
}

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -660,24 +661,6 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
return (resource instanceof IProject);
}
protected boolean isValidNamespace(Object element) {
if (element instanceof ITypeInfo) {
ITypeInfo info = (ITypeInfo)element;
if (info.exists() && info.getCElementType() == ICElement.C_NAMESPACE) {
// make sure it has types other than namespaces
ITypeInfo[] types = info.getEnclosedTypes();
if (types != null) {
for (int i = 0; i < types.length; ++i) {
if (types[i].getCElementType() != ICElement.C_NAMESPACE) {
return true;
}
}
}
}
}
return false;
}
/**
* Answers if the given <code>element</code> is a valid
* element for this part.
@ -686,20 +669,6 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
* @return <true> if the given element is a valid element
*/
abstract protected boolean isValidElement(Object element);
// if (element == null)
// return false;
//// element= getSuitableCElement(element);
//// if (element == null)
//// return false;
// Object input= getViewer().getInput();
// if (input == null)
// return false;
// if (input instanceof Collection)
// return ((Collection)input).contains(element);
// else
// return input.equals(element);
//
// }
private boolean isInputResetBy(Object newInput, Object input, IWorkbenchPart part) {
if (newInput == null)
@ -1183,19 +1152,20 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
}
void adjustInputAndSetSelection(Object o) {
if (!(o instanceof ICElement) && !(o instanceof ITypeInfo)) {
Object element = getOriginalElement(o);
if (!(element instanceof ICElement) && !(element instanceof ITypeInfo)) {
setSelection(StructuredSelection.EMPTY, true);
return;
}
Object elementToSelect= getSuitableElement(findElementToSelect(o));
Object newInput= findInputForElement(o);
Object elementToSelect= getSuitableElement(findElementToSelect(element));
Object newInput= findInputForElement(element);
Object oldInput= null;
Object viewerInput = getInput();
if (viewerInput instanceof ICElement || viewerInput instanceof ITypeInfo)
oldInput = viewerInput;
if (elementToSelect == null && !isValidInput(newInput) && (newInput == null && !isAncestorOf(o, oldInput)))
if (elementToSelect == null && !isValidInput(newInput) && (newInput == null && !isAncestorOf(element, oldInput)))
// Clear input
setInput(null);
else if (mustSetNewInput(elementToSelect, oldInput, newInput)) {
@ -1210,6 +1180,23 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
else
setSelection(StructuredSelection.EMPTY, true);
}
protected Object getOriginalElement(Object obj) {
if (obj instanceof ICElement) {
ICElement element = (ICElement)obj;
// Below is for children of TranslationUnits but we have to make sure
// we handle the case that the child comes from the a workingCopy in that
// case it should be equal as the original element.
ITranslationUnit t = (ITranslationUnit)element.getAncestor(ICElement.C_UNIT);
if (t != null && t.isWorkingCopy()) {
ICElement original = ((IWorkingCopy)t).getOriginal(element);
if (original != null)
return original;
}
}
return obj;
}
/**
* Compute if a new input must be set.
@ -1218,9 +1205,18 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
* @since 3.0
*/
private boolean mustSetNewInput(Object elementToSelect, Object oldInput, Object newInput) {
return (newInput == null || !newInput.equals(oldInput))
&& (elementToSelect == null
|| oldInput == null);
if (newInput == null || oldInput == null || !newInput.equals(oldInput)) {
return true;
}
if (elementToSelect == null) {
return false;
}
// return !findInputForElement(elementToSelect).equals(newInput);
return false;
// return !(inputContainsElement(newInput, elementToSelect));
// return (newInput == null || !newInput.equals(oldInput))
// && (elementToSelect == null
// || oldInput == null);
// return (newInput == null || !newInput.equals(oldInput))
// && (elementToSelect == null
// || oldInput == null
@ -1246,10 +1242,10 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
abstract protected Object findElementToSelect(Object element);
/**
* Converts the given Java element to one which is suitable for this
* Converts the given C element to one which is suitable for this
* view. It takes into account wether the view shows working copies or not.
*
* @param element the Java element to be converted
* @param element the C element to be converted
* @return an element suitable for this view
*/
Object getSuitableElement(Object obj) {
@ -1381,17 +1377,17 @@ public abstract class CBrowsingPart extends ViewPart implements IMenuListener, I
}
if (ei instanceof IFileEditorInput) {
IFile file= ((IFileEditorInput)ei).getFile();
ICElement je= (ICElement)file.getAdapter(ICElement.class);
if (je == null) {
ICElement ce= (ICElement)file.getAdapter(ICElement.class);
if (ce == null) {
IContainer container= ((IFileEditorInput)ei).getFile().getParent();
if (container != null)
je= (ICElement)container.getAdapter(ICElement.class);
ce= (ICElement)container.getAdapter(ICElement.class);
}
if (je == null) {
if (ce == null) {
setSelection(null, false);
return;
}
adjustInputAndSetSelection(je);
adjustInputAndSetSelection(ce);
// } else if (ei instanceof IClassFileEditorInput) {
// IClassFile cf= ((IClassFileEditorInput)ei).getClassFile();
// adjustInputAndSetSelection(cf);

View file

@ -117,7 +117,7 @@ public class MembersView extends CBrowsingPart implements IPropertyChangeListene
protected boolean isValidInput(Object element) {
if (element instanceof ITypeInfo) {
ITypeInfo type= (ITypeInfo)element;
if (type.getCElementType() != ICElement.C_NAMESPACE && exists(type))
if (type.getCElementType() != ICElement.C_NAMESPACE && type.exists())
return true;
}
return false;
@ -131,8 +131,11 @@ public class MembersView extends CBrowsingPart implements IPropertyChangeListene
* @return <true> if the given element is a valid element
*/
protected boolean isValidElement(Object element) {
if (element instanceof ICElement) {
if (element instanceof ICModel || element instanceof ICProject || element instanceof ISourceRoot)
if (element instanceof ICElement) {
if (element instanceof ICModel
|| element instanceof ICProject
|| element instanceof ISourceRoot
|| element instanceof ITranslationUnit)
return false;
return true;
}
@ -240,14 +243,9 @@ public class MembersView extends CBrowsingPart implements IPropertyChangeListene
* @see org.eclipse.cdt.internal.ui.browser.cbrowsing.CBrowsingPart#findElementToSelect(java.lang.Object)
*/
protected Object findElementToSelect(Object element) {
if (element instanceof ICElement && !(element instanceof ITranslationUnit)
&& TypeUtil.isDeclaredType((ICElement)element)) {
ICElement parent = TypeUtil.getDeclaringContainerType((ICElement)element);
if (parent != null) {
return element;
}
}
if (isValidElement(element)) {
return element;
}
return null;
}
}

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredViewer;
@ -119,7 +120,21 @@ public class NamespacesView extends CBrowsingPart {
* @return <true> if the given element is a valid element
*/
protected boolean isValidElement(Object element) {
return isValidNamespace(element);
if (element instanceof ITypeInfo) {
ITypeInfo info = (ITypeInfo)element;
if (info.exists() && info.getCElementType() == ICElement.C_NAMESPACE) {
// make sure it has types other than namespaces
ITypeInfo[] types = info.getEnclosedTypes();
if (types != null) {
for (int i = 0; i < types.length; ++i) {
if (types[i].getCElementType() != ICElement.C_NAMESPACE) {
return true;
}
}
}
}
}
return false;
}
/**
@ -170,7 +185,7 @@ public class NamespacesView extends CBrowsingPart {
return cProject;
}
if (element instanceof ICElement && !(element instanceof ITranslationUnit)) {
if (element instanceof ICElement) {
ICElement cElem = (ICElement)element;
ISourceRoot root = findSourceRoot(cElem);
if (exists(root) && !isProjectSourceRoot(root))
@ -191,19 +206,27 @@ public class NamespacesView extends CBrowsingPart {
return null;
}
if (element instanceof ICElement && !(element instanceof ITranslationUnit)) {
ICElement parent = (ICElement)element;
while (parent != null) {
if ((parent instanceof IStructure
if (element instanceof ICElement) {
ICElement celem = (ICElement)element;
if (celem instanceof ITranslationUnit) {
IProject project = celem.getCProject().getProject();
return AllTypesCache.getGlobalNamespace(project);
} else if (celem.getElementType() == ICElement.C_NAMESPACE) {
return AllTypesCache.getTypeForElement(celem, true, true, null);
} else {
ICElement parent = (ICElement)element;
while (parent != null) {
if ((parent instanceof IStructure
|| parent instanceof IEnumeration
|| parent instanceof ITypeDef)
&& parent.exists()) {
ITypeInfo info = AllTypesCache.getTypeForElement(parent, true, true, null);
if (info != null) {
return info.getEnclosingNamespace(true);
}
}
parent = parent.getParent();
ITypeInfo info = AllTypesCache.getTypeForElement(parent, true, true, null);
if (info != null) {
return info.getEnclosingNamespace(true);
}
}
parent = parent.getParent();
}
}
return null;
}

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredViewer;
@ -109,7 +110,11 @@ public class TypesView extends CBrowsingPart {
* @return <true> if the given element is a valid input
*/
protected boolean isValidInput(Object element) {
return isValidNamespace(element);
if (element instanceof ITypeInfo) {
ITypeInfo info = (ITypeInfo)element;
return (info.exists() && info.getCElementType() == ICElement.C_NAMESPACE);
}
return false;
}
/**
@ -166,12 +171,20 @@ public class TypesView extends CBrowsingPart {
return null;
}
if (element instanceof ICElement && !(element instanceof ITranslationUnit)) {
ICElement parent = TypeUtil.getDeclaringContainerType((ICElement)element);
if (parent != null) {
ITypeInfo info = AllTypesCache.getTypeForElement(parent, true, true, null);
if (info != null)
return info.getEnclosingNamespace(true);
if (element instanceof ICElement) {
ICElement celem = (ICElement) element;
if (celem instanceof ITranslationUnit) {
IProject project = celem.getCProject().getProject();
return AllTypesCache.getGlobalNamespace(project);
} else if (celem.getElementType() == ICElement.C_NAMESPACE) {
return AllTypesCache.getTypeForElement(celem, true, true, null);
} else {
ICElement parent = TypeUtil.getDeclaringContainerType(celem);
if (parent != null) {
ITypeInfo info = AllTypesCache.getTypeForElement(parent, true, true, null);
if (info != null)
return info.getEnclosingNamespace(true);
}
}
return null;
}