1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

- making usage of CodanEditorUtility

This commit is contained in:
Alena Laskavaia 2010-05-05 20:48:28 +00:00
parent b168348b96
commit b3e3a91fd6

View file

@ -14,16 +14,9 @@ import java.util.Collection;
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.codan.ui.CodanEditorUtility;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
@ -33,13 +26,11 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* Problems Details view show details for selected problem marker.
@ -89,7 +80,11 @@ public class ProblemDetails extends ViewPart {
}
// link file format example "file:/tmp/file.c#42", 42 is the line number
if (link.startsWith("file:")) { //$NON-NLS-1$
openFile(link);
try {
CodanEditorUtility.openInEditor(link, curProvider.getMarker().getResource());
} catch (PartInitException e1) {
CodanUIActivator.log(e1);
}
return;
}
if (link.startsWith("help:")) { //$NON-NLS-1$
@ -171,37 +166,4 @@ public class ProblemDetails extends ViewPart {
public void setFocus() {
message.setFocus();
}
@SuppressWarnings("restriction")
public void openFile(String link) {
String file = link.replaceFirst("^file:", ""); //$NON-NLS-1$ //$NON-NLS-2$
file = file.replaceAll("#\\d+$", ""); //$NON-NLS-1$ //$NON-NLS-2$
String sline = link.replaceAll(".*#(\\d+)$", "$1"); //$NON-NLS-1$ //$NON-NLS-2$
try {
IPath pfile = new Path(file);
IResource markerResource = curProvider.getMarker().getResource();
ICElement element = CoreModel.getDefault().create(markerResource);
IEditorPart part = EditorUtility.openInEditor(pfile, element);
int line = 0;
try {
line = Integer.parseInt(sline);
} catch (NumberFormatException e2) {
// no line
}
if (line > 0) {
if (part instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) part;
IDocument document = textEditor.getDocumentProvider().getDocument(
part.getEditorInput());
try {
textEditor.selectAndReveal(document.getLineOffset(line-1), 0);
} catch (BadLocationException e1) {
return;
}
}
}
} catch (PartInitException e1) {
CodanUIActivator.log(e1);
}
}
}