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

Ported index-view actions to the new api

This commit is contained in:
Markus Schorn 2006-10-13 09:51:12 +00:00
parent 6d85d8d0b9
commit ce35f1444b
3 changed files with 71 additions and 61 deletions

View file

@ -11,16 +11,17 @@
package org.eclipse.cdt.internal.ui.indexview; package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.search.ui.NewSearchUI; import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
@ -31,17 +32,17 @@ public class FindDeclarationsAction extends IndexAction {
super(viewer, CUIPlugin.getResourceString("IndexView.findDeclarations.name")); //$NON-NLS-1$ super(viewer, CUIPlugin.getResourceString("IndexView.findDeclarations.name")); //$NON-NLS-1$
} }
private PDOMBinding getBinding() { private IIndexBinding getBinding() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection)) if (!(selection instanceof IStructuredSelection))
return null; return null;
Object[] objs = ((IStructuredSelection)selection).toArray(); Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof PDOMBinding) return (objs.length == 1 && objs[0] instanceof IIndexBinding)
? (PDOMBinding)objs[0] : null; ? (IIndexBinding)objs[0] : null;
} }
public void run() { public void run() {
PDOMBinding binding = getBinding(); IIndexBinding binding = getBinding();
PDOMSearchBindingQuery query = new PDOMSearchBindingQuery( PDOMSearchBindingQuery query = new PDOMSearchBindingQuery(
null, null,
binding, binding,

View file

@ -11,10 +11,10 @@
package org.eclipse.cdt.internal.ui.indexview; package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery; import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery; import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
@ -31,13 +31,13 @@ public class FindReferencesAction extends IndexAction {
super(viewer, CUIPlugin.getResourceString("IndexView.findReferences.name")); //$NON-NLS-1$ super(viewer, CUIPlugin.getResourceString("IndexView.findReferences.name")); //$NON-NLS-1$
} }
private PDOMBinding getBinding() { private IIndexBinding getBinding() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection)) if (!(selection instanceof IStructuredSelection))
return null; return null;
Object[] objs = ((IStructuredSelection)selection).toArray(); Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof PDOMBinding) return (objs.length == 1 && objs[0] instanceof IIndexBinding)
? (PDOMBinding)objs[0] : null; ? (IIndexBinding)objs[0] : null;
} }
public void run() { public void run() {

View file

@ -11,12 +11,6 @@
package org.eclipse.cdt.internal.ui.indexview; package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -27,8 +21,20 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
* *
@ -44,50 +50,53 @@ public class OpenDefinitionAction extends IndexAction {
if (!(selection instanceof IStructuredSelection)) if (!(selection instanceof IStructuredSelection))
return; return;
Object[] objs = ((IStructuredSelection)selection).toArray(); try {
for (int i = 0; i < objs.length; ++i) { IIndex index= CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects());
if (!(objs[i] instanceof PDOMBinding)) Object[] objs = ((IStructuredSelection)selection).toArray();
continue; for (int i = 0; i < objs.length; ++i) {
if (!(objs[i] instanceof IIndexBinding))
try {
PDOMBinding binding = (PDOMBinding)objs[i];
PDOMName name = binding.getFirstDefinition();
if (name == null)
name = binding.getFirstDeclaration();
if (name == null)
continue; continue;
IASTFileLocation location = name.getFileLocation(); index.acquireReadLock();
IPath path = new Path(location.getFileName()); try {
Object input = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); IIndexBinding binding = (IIndexBinding)objs[i];
if (input == null) IIndexName[] defs= index.findDefinitions(binding);
input = new FileStorage(path); for (int j = 0; j < defs.length; j++) {
IIndexName name = defs[j];
IEditorPart editor = EditorUtility.openInEditor(input); showInEditor(name);
if (editor != null && editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor;
int nodeOffset = location.getNodeOffset();
int nodeLength = location.getNodeLength();
int offset;
int length;
if (nodeLength == -1) {
// This means the offset is actually a line number
try {
IDocument document = textEditor.getDocumentProvider().getDocument(editor.getEditorInput());
offset = document.getLineOffset(nodeOffset);
length = document.getLineLength(nodeOffset);
} catch (BadLocationException e) {
CUIPlugin.getDefault().log(e);
return;
}
} else {
offset = nodeOffset;
length = nodeLength;
} }
} finally {
textEditor.selectAndReveal(offset, length); index.releaseReadLock();
} }
} catch (CoreException e) { }
}
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
catch (InterruptedException e) {
}
}
private void showInEditor(IIndexName name) throws CModelException, PartInitException {
IPath path = new Path(name.getFileName());
Object input = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if (input == null)
input = new FileStorage(path);
IEditorPart editor = EditorUtility.openInEditor(input);
if (editor != null && editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor;
int nodeOffset = name.getNodeOffset();
int nodeLength = name.getNodeLength();
try {
if (nodeLength == -1) {
// This means the offset is actually a line number
IDocument document = textEditor.getDocumentProvider().getDocument(editor.getEditorInput());
nodeOffset = document.getLineOffset(nodeOffset);
nodeLength = document.getLineLength(nodeOffset);
}
textEditor.selectAndReveal(nodeOffset, nodeLength);
} catch (BadLocationException e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
} }
} }
@ -99,7 +108,7 @@ public class OpenDefinitionAction extends IndexAction {
return false; return false;
Object[] objs = ((IStructuredSelection)selection).toArray(); Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i) for (int i = 0; i < objs.length; ++i)
if (objs[i] instanceof PDOMBinding) if (objs[i] instanceof IIndexBinding)
return true; return true;
return false; return false;
} }