Search in sources :

Example 1 with AbstractErlangEditor

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;
    }
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) ITypedRegion(org.eclipse.jface.text.ITypedRegion) ErlToken(org.erlide.engine.services.parsing.ErlToken) BadLocationException(org.eclipse.jface.text.BadLocationException) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Example 2 with AbstractErlangEditor

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);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IErlModule(org.erlide.engine.model.root.IErlModule) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Example 3 with AbstractErlangEditor

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);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ErlangFunctionCall(org.erlide.util.ErlangFunctionCall) OpenResult(org.erlide.engine.services.search.OpenResult) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Example 4 with AbstractErlangEditor

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Example 5 with AbstractErlangEditor

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;
}
Also used : IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Aggregations

AbstractErlangEditor (org.erlide.ui.editors.erl.AbstractErlangEditor)13 IErlModule (org.erlide.engine.model.root.IErlModule)8 IErlProject (org.erlide.engine.model.root.IErlProject)4 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)4 IEditorPart (org.eclipse.ui.IEditorPart)3 IErlElement (org.erlide.engine.model.IErlElement)3 OpenResult (org.erlide.engine.services.search.OpenResult)3 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 TextSelection (org.eclipse.jface.text.TextSelection)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1