mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
222728: [editor] Register C/C++ editor with common hyperlinking preferences
This commit is contained in:
parent
7b37526690
commit
872058b5e5
4 changed files with 90 additions and 92 deletions
|
@ -475,3 +475,7 @@ DocCommentOwner.name = DocCommentOwner
|
||||||
Doxygen.name = Doxygen
|
Doxygen.name = Doxygen
|
||||||
|
|
||||||
indexedFilesDecorator.label = C/C++ Indexed Files
|
indexedFilesDecorator.label = C/C++ Indexed Files
|
||||||
|
|
||||||
|
# Hyperlinking
|
||||||
|
cEditorHyperlinkTarget= C/C++ Editor
|
||||||
|
cElementHyperlinkDetector= C/C++ Elements
|
||||||
|
|
|
@ -2677,4 +2677,24 @@
|
||||||
</enablement>
|
</enablement>
|
||||||
</decorator>
|
</decorator>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
|
<!-- Hyperlinking support -->
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
|
||||||
|
<target
|
||||||
|
id="org.eclipse.cdt.ui.cCode"
|
||||||
|
name="%cEditorHyperlinkTarget">
|
||||||
|
<context type="org.eclipse.ui.texteditor.ITextEditor"/>
|
||||||
|
</target>
|
||||||
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
|
||||||
|
<hyperlinkDetector
|
||||||
|
class="org.eclipse.cdt.internal.ui.editor.CElementHyperlinkDetector"
|
||||||
|
id="org.eclipse.cdt.ui.editor.CElementHyperlinkDetector"
|
||||||
|
name="%cElementHyperlinkDetector"
|
||||||
|
targetId="org.eclipse.cdt.ui.cCode">
|
||||||
|
</hyperlinkDetector>
|
||||||
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -12,70 +12,62 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.ITextViewer;
|
import org.eclipse.jface.text.ITextViewer;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
|
import org.eclipse.jface.text.TextUtilities;
|
||||||
|
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
|
||||||
import org.eclipse.jface.text.hyperlink.IHyperlink;
|
import org.eclipse.jface.text.hyperlink.IHyperlink;
|
||||||
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
|
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||||
|
|
||||||
public class CElementHyperlinkDetector implements IHyperlinkDetector {
|
public class CElementHyperlinkDetector extends AbstractHyperlinkDetector {
|
||||||
|
|
||||||
private ITextEditor fTextEditor;
|
public CElementHyperlinkDetector() {
|
||||||
|
|
||||||
public CElementHyperlinkDetector(ITextEditor editor) {
|
|
||||||
fTextEditor= editor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, final IRegion region, boolean canShowMultipleHyperlinks) {
|
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, final IRegion region, boolean canShowMultipleHyperlinks) {
|
||||||
if (region == null || canShowMultipleHyperlinks || fTextEditor == null)
|
ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
|
||||||
|
if (region == null || canShowMultipleHyperlinks || !(textEditor instanceof CEditor))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
final IAction openAction= fTextEditor.getAction("OpenDeclarations"); //$NON-NLS-1$
|
final IAction openAction= textEditor.getAction("OpenDeclarations"); //$NON-NLS-1$
|
||||||
if (openAction == null)
|
if (openAction == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
final IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fTextEditor.getEditorInput());
|
// check partition type
|
||||||
|
try {
|
||||||
|
String partitionType= TextUtilities.getContentType(textViewer.getDocument(), ICPartitions.C_PARTITIONING, region.getOffset(), false);
|
||||||
|
if (!IDocument.DEFAULT_CONTENT_TYPE.equals(partitionType) && !ICPartitions.C_PREPROCESSOR.equals(partitionType)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (BadLocationException exc) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(textEditor.getEditorInput());
|
||||||
if (workingCopy == null) {
|
if (workingCopy == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
IIndex index;
|
|
||||||
try {
|
|
||||||
index = CCorePlugin.getIndexManager().getIndex(workingCopy.getCProject(),
|
|
||||||
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
|
|
||||||
} catch(CoreException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
index.acquireReadLock();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final IHyperlink[] result= {null};
|
final IHyperlink[] result= {null};
|
||||||
try {
|
|
||||||
IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
|
@ -109,10 +101,7 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!status.isOK()) {
|
if (!status.isOK()) {
|
||||||
CUIPlugin.getDefault().log(status);
|
CUIPlugin.log(status);
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
index.releaseReadLock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result[0] == null ? null : result;
|
return result[0] == null ? null : result;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package org.eclipse.cdt.internal.ui.text;
|
package org.eclipse.cdt.internal.ui.text;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -40,7 +41,6 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
|
||||||
import org.eclipse.jface.text.contentassist.IContentAssistant;
|
import org.eclipse.jface.text.contentassist.IContentAssistant;
|
||||||
import org.eclipse.jface.text.formatter.IContentFormatter;
|
import org.eclipse.jface.text.formatter.IContentFormatter;
|
||||||
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
|
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
|
||||||
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
|
|
||||||
import org.eclipse.jface.text.information.IInformationPresenter;
|
import org.eclipse.jface.text.information.IInformationPresenter;
|
||||||
import org.eclipse.jface.text.information.IInformationProvider;
|
import org.eclipse.jface.text.information.IInformationProvider;
|
||||||
import org.eclipse.jface.text.information.InformationPresenter;
|
import org.eclipse.jface.text.information.InformationPresenter;
|
||||||
|
@ -62,7 +62,6 @@ import org.eclipse.ui.IPathEditorInput;
|
||||||
import org.eclipse.ui.editors.text.ILocationProvider;
|
import org.eclipse.ui.editors.text.ILocationProvider;
|
||||||
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
|
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
|
||||||
import org.eclipse.ui.ide.ResourceUtil;
|
import org.eclipse.ui.ide.ResourceUtil;
|
||||||
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
|
|
||||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
|
@ -89,7 +88,6 @@ import org.eclipse.cdt.ui.text.doctools.IDocCommentViewerConfiguration;
|
||||||
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
|
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
|
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CElementHyperlinkDetector;
|
|
||||||
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
|
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
|
||||||
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverProxy;
|
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverProxy;
|
||||||
import org.eclipse.cdt.internal.ui.text.c.hover.CInformationProvider;
|
import org.eclipse.cdt.internal.ui.text.c.hover.CInformationProvider;
|
||||||
|
@ -810,29 +808,6 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
fPreprocessorScanner.adaptToPreferenceChange(event);
|
fPreprocessorScanner.adaptToPreferenceChange(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
|
|
||||||
* @since 3.1
|
|
||||||
*/
|
|
||||||
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
|
|
||||||
if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
IHyperlinkDetector[] inheritedDetectors= super.getHyperlinkDetectors(sourceViewer);
|
|
||||||
|
|
||||||
if (fTextEditor == null)
|
|
||||||
return inheritedDetectors;
|
|
||||||
|
|
||||||
int inheritedDetectorsLength= inheritedDetectors != null ? inheritedDetectors.length : 0;
|
|
||||||
IHyperlinkDetector[] detectors= new IHyperlinkDetector[inheritedDetectorsLength + 1];
|
|
||||||
detectors[0]= new CElementHyperlinkDetector(fTextEditor);
|
|
||||||
for (int i= 0; i < inheritedDetectorsLength; i++) {
|
|
||||||
detectors[i+1]= inheritedDetectors[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return detectors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
|
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
|
||||||
*/
|
*/
|
||||||
|
@ -887,7 +862,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
try {
|
try {
|
||||||
return ((ITranslationUnit)element).getLanguage();
|
return ((ITranslationUnit)element).getLanguage();
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CUIPlugin.getDefault().log(e);
|
CUIPlugin.log(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// compute the language from the plain editor input
|
// compute the language from the plain editor input
|
||||||
|
@ -978,4 +953,14 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectorTargets(org.eclipse.jface.text.source.ISourceViewer)
|
||||||
|
*/
|
||||||
|
protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
|
||||||
|
Map targets= super.getHyperlinkDetectorTargets(sourceViewer);
|
||||||
|
targets.put("org.eclipse.cdt.ui.cCode", fTextEditor); //$NON-NLS-1$
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue