1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Implementat for CView.selectReveal()

The element was not shown since we did not have
a comparater.
This commit is contained in:
Alain Magloire 2004-02-29 04:40:29 +00:00
parent a6553e61d1
commit 17436b16d0
4 changed files with 82 additions and 10 deletions

View file

@ -1,3 +1,12 @@
2004-02-28 Alain Magloire
Provide an implementation of CView.selectReveal().
The problem was that ITranslationUnit != IWorkingCopy
* src/org/eclipse/cdt/internal/ui/cview/CView.java
* src/org/eclipse/cdt/internal/ui/cview/CViewElementComparer.java
* src/org/eclipse/cdt/ui/actions/ShowInCViewAction.java
2004-02-28 Alain Magloire
Fixing a NPE.

View file

@ -523,6 +523,7 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
viewer = createViewer(parent);
viewer.setUseHashlookup(true);
viewer.setComparer(new CViewElementComparer());
initContentProvider(viewer);
initLabelProvider(viewer);
CUIPlugin.getDefault().getProblemMarkerManager().addListener(viewer);

View file

@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
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;
public class CViewElementComparer implements IElementComparer {
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;
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);
}
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();
}
}

View file

@ -11,18 +11,16 @@
package org.eclipse.cdt.ui.actions;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.cview.SelectionConverter;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchSite;
@ -90,15 +88,12 @@ public class ShowInCViewAction extends SelectionProviderAction {
public void run(ITextEditor editor) {
if (editor != null) {
IEditorInput input = editor.getEditorInput();
if (input instanceof IFileEditorInput) {
IFileEditorInput fileInput = (IFileEditorInput) input;
IFile file = fileInput.getFile();
CoreModel factory = CoreModel.getDefault();
ICElement celement = factory.create(file);
try {
ICElement celement = SelectionConverter.getElementAtOffset(editor);
if (celement != null) {
run(new StructuredSelection(celement));
}
} catch (CModelException e) {
}
}
}