diff --git a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
index f754e44147d..aa9828031a8 100644
--- a/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.ui/META-INF/MANIFEST.MF
@@ -12,7 +12,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.cdt.codan.core,
org.eclipse.jface.text,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ org.eclipse.cdt.ui,
+ org.eclipse.cdt.core
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.codan.internal.ui;x-friends:="org.eclipse.cdt.codan.ui.cxx",
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java
index a55f098eaec..51ddcb6fcd3 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java
@@ -12,9 +12,18 @@ package org.eclipse.cdt.codan.internal.ui.views;
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.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;
@@ -24,10 +33,13 @@ 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.
@@ -49,6 +61,7 @@ public class ProblemDetails extends ViewPart {
*/
private Link description;
private GenericCodanProblemDetailsProvider genProvider = new GenericCodanProblemDetailsProvider();
+ private AbstractCodanProblemDetailsProvider curProvider = genProvider;
/**
* The constructor.
@@ -68,13 +81,15 @@ public class ProblemDetails extends ViewPart {
@Override
public void widgetSelected(SelectionEvent e) {
String link = e.text;
- if (link==null) return;
+ if (link == null)
+ return;
if (link.startsWith("http")) { //$NON-NLS-1$
org.eclipse.swt.program.Program.launch(e.text);
return;
}
- if (link.startsWith("source:")) { //$NON-NLS-1$
- // open in eclipse editor TODO
+ // link file format example "file:/tmp/file.c#42", 42 is the line number
+ if (link.startsWith("file:")) { //$NON-NLS-1$
+ openFile(link);
return;
}
if (link.startsWith("help:")) { //$NON-NLS-1$
@@ -136,6 +151,7 @@ public class ProblemDetails extends ViewPart {
}
private void applyProvider(AbstractCodanProblemDetailsProvider provider) {
+ curProvider = provider;
setTextSafe(message, provider, provider.getStyledProblemMessage());
setTextSafe(description, provider, provider.getStyledProblemDescription());
}
@@ -155,4 +171,37 @@ 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);
+ }
+ }
}
\ No newline at end of file
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java
index 654dd0b9d06..0b20bea7f64 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstarctCodanCMarkerResolution.java
@@ -10,20 +10,14 @@
*******************************************************************************/
package org.eclipse.cdt.codan.ui;
-import org.eclipse.core.resources.IFile;
+import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolution2;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
/**
@@ -32,8 +26,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
* description client class should additionally implement
* {@link IMarkerResolution2}
*/
-public abstract class AbstarctCodanCMarkerResolution implements
- IMarkerResolution {
+public abstract class AbstarctCodanCMarkerResolution implements IMarkerResolution {
/**
* Get position offset from marker. If CHAR_START attribute is not set for
* marker, line and document would be used.
@@ -65,35 +58,16 @@ public abstract class AbstarctCodanCMarkerResolution implements
* the marker to resolve
*/
public void run(IMarker marker) {
- // See if there is an open editor on the file containing the marker
- IWorkbenchWindow w = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- if (w == null) {
- return;
- }
- IWorkbenchPage page = w.getActivePage();
- if (page == null) {
- return;
- }
- IFileEditorInput input = new FileEditorInput((IFile) marker
- .getResource());
- IEditorPart editorPart = page.findEditor(input);
- if (editorPart == null) {
- // open an editor
- try {
- editorPart = IDE.openEditor(page, (IFile) marker.getResource(),
- true);
- } catch (PartInitException e) {
- e.printStackTrace();
- }
- }
- if (editorPart == null) {
- return;
- }
+ IEditorPart editorPart;
+ try {
+ editorPart = CodanEditorUtility.openInEditor(marker);
+ } catch (PartInitException e) {
+ CodanUIActivator.log(e);
+ return;
+ }
if (editorPart instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) editorPart;
- IDocument doc = editor.getDocumentProvider().getDocument(
- editor.getEditorInput());
+ IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
apply(marker, doc);
}
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java
index 3623fd3d385..c8e3cb04821 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanProblemDetailsProvider.java
@@ -56,7 +56,7 @@ public abstract class AbstractCodanProblemDetailsProvider {
* @return
*/
protected String getProblemId() {
- String id = marker.getAttribute(IMarker.PROBLEM, (String) null);
+ String id = marker.getAttribute(IMarker.PROBLEM, (String) null);
return id;
}
@@ -77,14 +77,14 @@ public abstract class AbstractCodanProblemDetailsProvider {
*/
public String getStyledProblemMessage() {
String message = escapeForLink(getProblemMessage());
- String loc = marker.getResource().getFullPath().toOSString();
- String loc2 = marker.getAttribute(IMarker.LOCATION, ""); //$NON-NLS-1$
- if (loc2.length()>0)
- loc=loc2;
- int line = marker.getAttribute(IMarker.LINE_NUMBER, 0);
- return message + "\n" + loc + ":" + line; //$NON-NLS-1$//$NON-NLS-2$
+ String href = getLocationHRef();
+ String link = href.replaceFirst("^file:", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ link = link.replaceFirst("#(\\d+)$", ":$1"); //$NON-NLS-1$//$NON-NLS-2$
+ return "" + link + "\n" + message; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+ protected String getLocationHRef() {
+ return CodanEditorUtility.getLocationHRef(marker);
}
-
/**
* Return styled problem description. This text would be used in Link widget.
* String can include tags to which would be
@@ -109,6 +109,6 @@ public abstract class AbstractCodanProblemDetailsProvider {
* such as & (mnemonic)
*/
protected String escapeForLink(String text) {
- return text.replaceAll("&", "&&"); //$NON-NLS-1$//$NON-NLS-2$
+ return text.replaceAll("&", "&&"); //$NON-NLS-1$//$NON-NLS-2$
}
}