Search in sources :

Example 16 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project unethicalite by unethicalite.

the class ShellPanel method switchContext.

public void switchContext(Injector injector) {
    freeContext();
    this.injector = injector;
    exec = new RLShellExecutionControl() {

        @Override
        protected String invoke(Method doitMethod) throws Exception {
            var result = new AtomicReference<>();
            var sema = new Semaphore(0);
            invokeOnClientThread(() -> {
                try {
                    result.set(super.invoke(doitMethod));
                } catch (Exception e) {
                    result.set(e);
                } finally {
                    sema.release();
                }
            });
            sema.acquire();
            if (result.get() instanceof String) {
                return (String) result.get();
            }
            throw (Exception) result.get();
        }
    };
    shell = JShell.builder().executionEngine(exec, null).build();
    String preludeStr;
    try (var is = ShellPanel.class.getResourceAsStream("prelude.jsh")) {
        preludeStr = new String(is.readAllBytes(), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    prelude = ImmutableSet.copyOf(eval(preludeStr, false));
    var cp = new JShellAutocompleteProvider(shell);
    autoCompletion = new AutoCompletion(cp);
    autoCompletion.setAutoActivationDelay(200);
    autoCompletion.setAutoActivationEnabled(true);
    autoCompletion.setAutoCompleteSingleChoices(false);
    autoCompletion.install(this.textArea);
}
Also used : AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) Method(java.lang.reflect.Method) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException)

Example 17 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project omegaide by omegaui.

the class RegexAwareComboBox method setAutoCompleteEnabled.

/**
 * Toggles whether regex auto-complete is enabled.  This method will fire
 * a property change event of type
 * {@link ContentAssistable#ASSISTANCE_IMAGE}.
 *
 * @param enabled Whether regex auto complete should be enabled.
 * @see #isAutoCompleteEnabled()
 */
public void setAutoCompleteEnabled(boolean enabled) {
    if (this.enabled != enabled) {
        this.enabled = enabled;
        if (enabled) {
            AutoCompletion ac = getAutoCompletion();
            JTextComponent tc = (JTextComponent) getEditor().getEditorComponent();
            ac.install(tc);
        } else {
            ac.uninstall();
        }
        String prop = ContentAssistable.ASSISTANCE_IMAGE;
        // both non-null and old.equals(new).
        if (enabled) {
            firePropertyChange(prop, null, getContentAssistImage());
        } else {
            firePropertyChange(prop, null, null);
        }
    }
}
Also used : AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) JTextComponent(javax.swing.text.JTextComponent)

Example 18 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project runelite by open-osrs.

the class ShellPanel method switchContext.

public void switchContext(Injector injector) {
    freeContext();
    this.injector = injector;
    exec = new RLShellExecutionControl() {

        @Override
        protected String invoke(Method doitMethod) throws Exception {
            var result = new AtomicReference<>();
            var sema = new Semaphore(0);
            invokeOnClientThread(() -> {
                try {
                    result.set(super.invoke(doitMethod));
                } catch (Exception e) {
                    result.set(e);
                } finally {
                    sema.release();
                }
            });
            sema.acquire();
            if (result.get() instanceof String) {
                return (String) result.get();
            }
            throw (Exception) result.get();
        }
    };
    shell = JShell.builder().executionEngine(exec, null).build();
    String preludeStr;
    try (var is = ShellPanel.class.getResourceAsStream("prelude.jsh")) {
        preludeStr = new String(is.readAllBytes(), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    prelude = ImmutableSet.copyOf(eval(preludeStr, false));
    var cp = new JShellAutocompleteProvider(shell);
    autoCompletion = new AutoCompletion(cp);
    autoCompletion.setAutoActivationDelay(200);
    autoCompletion.setAutoActivationEnabled(true);
    autoCompletion.setAutoCompleteSingleChoices(false);
    autoCompletion.install(this.textArea);
}
Also used : AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) Method(java.lang.reflect.Method) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException)

Example 19 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project MeteoInfo by meteoinfo.

the class JythonLanguageSupport method install.

/**
 * {@inheritDoc}
 */
@Override
public void install(RSyntaxTextArea textArea) {
    JythonCompletionProvider prov = getProvider();
    AutoCompletion ac = new JythonAutoCompletion(prov);
    ac.setAutoCompleteEnabled(true);
    ac.setAutoActivationEnabled(true);
    ac.setParameterAssistanceEnabled(isParameterAssistanceEnabled());
    ac.install(textArea);
    installImpl(textArea, ac);
    textArea.setToolTipSupplier(prov);
}
Also used : AutoCompletion(org.fife.ui.autocomplete.AutoCompletion)

Example 20 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project MeteoInfo by meteoinfo.

the class AbstractLanguageSupport method uninstallImpl.

/**
 * Unregisters an textArea.  This should be called by subclasses in their
 * {@link #uninstall(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea)} methods.
 * This method will also call the <code>uninstall</code> method on the
 * <code>AutoCompletion</code>.
 *
 * @param textArea The text area.
 * @see #installImpl(RSyntaxTextArea, AutoCompletion)
 */
protected void uninstallImpl(RSyntaxTextArea textArea) {
    AutoCompletion ac = getAutoCompletionFor(textArea);
    if (ac != null) {
        ac.uninstall();
    }
    textAreaToAutoCompletion.remove(textArea);
}
Also used : AutoCompletion(org.fife.ui.autocomplete.AutoCompletion)

Aggregations

AutoCompletion (org.fife.ui.autocomplete.AutoCompletion)23 CompletionProvider (org.fife.ui.autocomplete.CompletionProvider)9 DefaultCompletionProvider (org.fife.ui.autocomplete.DefaultCompletionProvider)9 IOException (java.io.IOException)6 KeyStroke (javax.swing.KeyStroke)6 BadLocationException (javax.swing.text.BadLocationException)5 Method (java.lang.reflect.Method)4 Semaphore (java.util.concurrent.Semaphore)4 RSyntaxTextArea (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea)4 RTextScrollPane (org.fife.ui.rtextarea.RTextScrollPane)3 JTextComponent (javax.swing.text.JTextComponent)2 CollapsibleSectionPanel (org.fife.rsta.ui.CollapsibleSectionPanel)2 FlatSVGIcon (com.formdev.flatlaf.extras.FlatSVGIcon)1 BashCompletionProvider (com.g3g4x5x6.editor.provider.BashCompletionProvider)1 JavaCompletionProvider (com.g3g4x5x6.editor.provider.JavaCompletionProvider)1 NucleiYamlCompletionProvider (com.g3g4x5x6.nuclei.NucleiYamlCompletionProvider)1 GridView (com.jeta.forms.gui.form.GridView)1 Font (java.awt.Font)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1