Search in sources :

Example 1 with IErlangConsolePage

use of org.erlide.ui.console.IErlangConsolePage 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

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 IErlangConsole (org.erlide.ui.console.IErlangConsole)1 IErlangConsolePage (org.erlide.ui.console.IErlangConsolePage)1