Search in sources :

Example 1 with IErlangConsole

use of org.erlide.ui.console.IErlangConsole in project erlide_eclipse by erlang.

the class SendToConsoleAction method getConsole.

private IErlangConsole getConsole(@NonNull final IProject aproject) {
    final IBackendManager backendManager = BackendCore.getBackendManager();
    final Set<IBackend> executionBackends = backendManager.getExecutionBackends(aproject);
    final ErlConsoleManager erlConsoleManager = ErlideUIPlugin.getDefault().getErlConsoleManager();
    IErlangConsole result = null;
    for (final IBackend backend : executionBackends) {
        result = erlConsoleManager.getConsole(backend);
        if (result != null) {
            break;
        }
    }
    return result;
}
Also used : IBackendManager(org.erlide.backend.api.IBackendManager) IBackend(org.erlide.backend.api.IBackend) IErlangConsole(org.erlide.ui.console.IErlangConsole) ErlConsoleManager(org.erlide.ui.console.ErlConsoleManager)

Example 2 with IErlangConsole

use of org.erlide.ui.console.IErlangConsole in project erlide_eclipse by erlang.

the class SendToConsoleAction method run.

@Override
public void run(final ITextSelection selection0) {
    ITextSelection selection = selection0;
    IErlangConsole console = null;
    if (project != null) {
        console = getConsole(project);
        if (console == null) {
            final String message = "There is no runtime launched for this backend. Please start a runtime to send commands to.";
            final Exception x = new Exception("No runtime started");
            ErrorDialog.openError(getShell(), "No runtime", message, new Status(IStatus.ERROR, ErlideUIPlugin.PLUGIN_ID, 0, x.getMessage(), x));
            return;
        }
        console.getShell().removeListener(consoleBackendShellListener);
        // if selection is empty, grab the whole line
        selection = getLineSelection(selection, false);
        // try to make the text a full erlang expression, ending with dot
        String text = selection.getText().trim();
        if (text.endsWith(",") || text.endsWith(";")) {
            // $NON-NLS-1$ //$NON-NLS-2$
            text = text.substring(0, text.length() - 1);
        }
        if (!text.endsWith(".")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            text += ".";
        }
        // $NON-NLS-1$
        text += "\n";
        // send it off to the console
        if (getOutput) {
            consoleBackendShellListener = new ConsoleBackendShellListener(console.getShell(), getLineSelection(selection, true).getOffset());
            console.getShell().addListener(consoleBackendShellListener);
        }
        final IErlangConsolePage consolePage = ErlideUIPlugin.getDefault().getErlConsoleManager().getPage(console);
        consolePage.input(text);
        super.run(selection);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IErlangConsole(org.erlide.ui.console.IErlangConsole) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException) MissingResourceException(java.util.MissingResourceException) IErlangConsolePage(org.erlide.ui.console.IErlangConsolePage)

Aggregations

IErlangConsole (org.erlide.ui.console.IErlangConsole)2 MissingResourceException (java.util.MissingResourceException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 IBackend (org.erlide.backend.api.IBackend)1 IBackendManager (org.erlide.backend.api.IBackendManager)1 ErlConsoleManager (org.erlide.ui.console.ErlConsoleManager)1 IErlangConsolePage (org.erlide.ui.console.IErlangConsolePage)1