use of org.erlide.ui.editors.erl.AbstractErlangEditor in project erlide_eclipse by erlang.
the class ErlangHyperlinkDetector method detectHyperlinks.
private IHyperlink[] detectHyperlinks(final IDocument doc, final int offset) {
final AbstractErlangEditor editor = getAdapter(AbstractErlangEditor.class);
if (editor == null) {
return null;
}
final ErlToken token = editor.getScanner().getTokenAt(offset);
if (token == null) {
return null;
}
final int tokenKind = token.getKind();
if (tokenKind != ErlToken.KIND_ATOM && tokenKind != ErlToken.KIND_STRING && tokenKind != ErlToken.KIND_MACRO && tokenKind != ErlToken.KIND_VAR) {
return null;
}
try {
final ITypedRegion partition = doc.getPartition(offset);
final ErlRegion region = new ErlRegion(token.getOffset(), token.getLength(), partition.getType());
if (!IDocument.DEFAULT_CONTENT_TYPE.equals(region.getType())) {
return null;
}
return new IHyperlink[] { new ErlangHyperlink(editor, region) };
} catch (final BadLocationException e) {
return null;
}
}
use of org.erlide.ui.editors.erl.AbstractErlangEditor in project erlide_eclipse by erlang.
the class ErlangAbstractHandler method getTextSelection.
/**
* Provide the text selection that is needed to execute the command. Default
* implementation, extend to Erlang elements selected.
*
* @param document
* text {@link IDocument}
* @param selection
* selection affected by command (extended by extendSelection)
* @return new {@link ITextSelection} with all text up to selection
*/
protected ITextSelection getTextSelection(final IDocument document, final ITextSelection selection, final ITextEditor editor) {
if (editor instanceof ErlangEditor) {
final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
final IErlModule module = erlangEditor.getModule();
if (module != null) {
final int offset1 = selection.getOffset();
final int offset2 = offset1 + selection.getLength();
try {
final IErlElement e1 = module.getElementAt(offset1);
final IErlElement e2 = module.getElementAt(offset2);
if (e1 instanceof ISourceReference) {
final ISourceReference ref1 = (ISourceReference) e1;
final ISourceRange r1 = ref1.getSourceRange();
final int offset = r1.getOffset();
int length = r1.getLength();
if (e1 == e2) {
final int docLength = document.getLength();
if (offset + length > docLength) {
length = docLength - offset;
}
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, length));
} else if (e2 == null) {
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, selection.getLength() + selection.getOffset() - offset));
} else if (e2 instanceof ISourceReference) {
final ISourceReference ref2 = (ISourceReference) e2;
final ISourceRange r2 = ref2.getSourceRange();
return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, r2.getOffset() - offset + r2.getLength()));
}
}
} catch (final ErlModelException e) {
}
}
}
return ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
}
use of org.erlide.ui.editors.erl.AbstractErlangEditor in project erlide_eclipse by erlang.
the class HandleEdocLinksLocationListener method changing.
@Override
public void changing(final LocationEvent event) {
ErlangBrowserInformationControlInput input = null;
if (control != null) {
input = control.getInput();
} else if (edocView != null) {
input = edocView.getInput();
}
if (input != null) {
final AbstractErlangEditor editor = input.getEditor();
String moduleName = "";
final Object inputElement = input.getInputElement();
if (inputElement instanceof OpenResult) {
final OpenResult or = (OpenResult) inputElement;
moduleName = or.getName();
}
final ErlangFunctionCall functionCall = HoverUtil.eventToErlangFunctionCall(moduleName, event);
if (functionCall != null) {
final IErlProject project = ErlangEngine.getInstance().getModelUtilService().getProject(editor.getModule());
if (project == null) {
return;
}
final IOtpRpc backend = BackendCore.getBuildBackend(project);
final OtpErlangTuple otpDoc = (OtpErlangTuple) ErlangEngine.getInstance().getOtpDocService().getOtpDoc(backend, functionCall);
if (Util.isOk(otpDoc)) {
final String docStr = Util.stringValue(otpDoc.elementAt(1));
final StringBuffer result = new StringBuffer(docStr);
String docPath = "";
String anchor = "";
if (otpDoc.arity() > 4) {
docPath = Util.stringValue(otpDoc.elementAt(3));
anchor = Util.stringValue(otpDoc.elementAt(4));
}
if (result.length() > 0) {
final String html = HoverUtil.getHTML(result);
final Object element = new OpenResult(otpDoc.elementAt(2));
input = new ErlangBrowserInformationControlInput(input, editor, element, html, 20, HoverUtil.getDocumentationURL(docPath, anchor));
}
}
}
}
if (input != null) {
if (control != null) {
if (control.hasDelayedInputChangeListener()) {
control.notifyDelayedInputChange(input);
} else {
control.setInput(input);
}
} else if (edocView != null) {
edocView.setInfo(input);
}
}
}
use of org.erlide.ui.editors.erl.AbstractErlangEditor in project erlide_eclipse by erlang.
the class EditorUtility method isOpenInEditor.
/**
* Tests if a CU is currently shown in an editor
*
* @return the IEditorPart if shown, null if element is not open in an
* editor
*/
public static IEditorPart isOpenInEditor(final Object inputElement) {
final Collection<IEditorPart> allErlangEditors = EditorUtility.getAllErlangEditors();
for (final IEditorPart editorPart : allErlangEditors) {
if (inputElement instanceof IErlElement) {
final IErlElement element = (IErlElement) inputElement;
final IErlModule module = ErlangEngine.getInstance().getModelUtilService().getModule(element);
final AbstractErlangEditor editor = (AbstractErlangEditor) editorPart;
if (module.equals(editor.getModule())) {
return editorPart;
}
}
}
final IEditorInput input = EditorUtility.getEditorInput(inputElement);
if (input != null) {
for (final IEditorPart editorPart : allErlangEditors) {
if (editorPart.getEditorInput().equals(input)) {
return editorPart;
}
}
}
return null;
}
use of org.erlide.ui.editors.erl.AbstractErlangEditor in project erlide_eclipse by erlang.
the class ErlModelUtils method openFunctionInEditor.
/**
* Activate editor and select erlang function
*/
public static boolean openFunctionInEditor(final ErlangFunction erlangFunction, final IEditorPart editor) throws CoreException {
final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
final IErlModule module = erlangEditor.getModule();
if (module == null) {
return false;
}
module.open(null);
final IErlFunction function = module.findFunction(erlangFunction);
if (function == null) {
return false;
}
EditorUtility.revealInEditor(editor, function);
return true;
}
Aggregations