Search in sources :

Example 6 with OpenResult

use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.

the class ErlangSearchPage method tryErlangTextSelection.

public SearchPatternData tryErlangTextSelection(final SearchPatternData initData0, final IEditorPart activePart) throws ErlModelException {
    final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) activePart;
    final IErlModule module = erlangEditor.getModule();
    SearchPatternData initData = initData0;
    if (module != null) {
        final ISelection ssel = erlangEditor.getSite().getSelectionProvider().getSelection();
        final ITextSelection textSel = (ITextSelection) ssel;
        final int offset = textSel.getOffset();
        OpenResult res;
        try {
            res = ErlangEngine.getInstance().getOpenService().open(module.getScannerName(), offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), "", ErlangEngine.getInstance().getModel().getPathVars());
        } catch (final RpcException e) {
            res = null;
        }
        ErlLogger.debug("searchPage(open) " + res);
        initData = determineInitValuesFrom(module, offset, res);
    }
    return initData;
}
Also used : OpenResult(org.erlide.engine.services.search.OpenResult) RpcException(org.erlide.runtime.rpc.RpcException) IErlModule(org.erlide.engine.model.root.IErlModule) ISelection(org.eclipse.jface.viewers.ISelection) ITextSelection(org.eclipse.jface.text.ITextSelection) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Example 7 with OpenResult

use of org.erlide.engine.services.search.OpenResult in project erlide_eclipse by erlang.

the class OpenAction method run.

@Override
public void run(final ITextSelection selection) {
    try {
        final IEditorPart activeEditor = getSite().getPage().getActiveEditor();
        final int offset = selection.getOffset();
        ITextEditor textEditor = null;
        OpenResult openResult = null;
        IErlElement element = null;
        IErlProject project = null;
        IErlModule module = null;
        final IErlModel model = ErlangEngine.getInstance().getModel();
        if (activeEditor instanceof AbstractErlangEditor) {
            final AbstractErlangEditor editor = (AbstractErlangEditor) activeEditor;
            textEditor = editor;
            editor.reconcileNow();
            final String scannerName = editor.getScannerName();
            module = editor.getModule();
            project = editor.getProject();
            openResult = ErlangEngine.getInstance().getOpenService().open(scannerName, offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), project.getProperties().getExternalModules(), model.getPathVars());
            ErlLogger.debug("open " + openResult);
            element = editor.getElementAt(offset, true);
        } else if (activeEditor instanceof ITextEditor) {
            textEditor = (ITextEditor) activeEditor;
            final String text = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()).get();
            openResult = ErlangEngine.getInstance().getOpenService().openText(text, offset);
            final IFile file = textEditor.getEditorInput().getAdapter(IFile.class);
            if (file != null) {
                final IProject p = file.getProject();
                if (p != null) {
                    project = model.findProject(p);
                }
            }
        }
        if (openResult != null) {
            helper.openOpenResult(textEditor, module, offset, project, openResult, element);
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) IErlElement(org.erlide.engine.model.IErlElement) OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule)

Aggregations

OpenResult (org.erlide.engine.services.search.OpenResult)7 IErlModule (org.erlide.engine.model.root.IErlModule)4 IErlProject (org.erlide.engine.model.root.IErlProject)4 IErlModel (org.erlide.engine.model.root.IErlModel)3 AbstractErlangEditor (org.erlide.ui.editors.erl.AbstractErlangEditor)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 CoreException (org.eclipse.core.runtime.CoreException)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IErlElement (org.erlide.engine.model.IErlElement)2 IOtpRpc (org.erlide.runtime.rpc.IOtpRpc)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 DebugException (org.eclipse.debug.core.DebugException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Point (org.eclipse.swt.graphics.Point)1 IEditorPart (org.eclipse.ui.IEditorPart)1