Search in sources :

Example 11 with AutoCompletion

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

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 12 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project fql by CategoricalData.

the class XCodeEditor method doTemplates.

@Override
protected void doTemplates() {
    CompletionProvider provider = createCompletionProvider();
    AutoCompletion ac = new AutoCompletion(provider);
    KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.META_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
    ac.setTriggerKey(key);
    ac.install(topArea);
}
Also used : CompletionProvider(org.fife.ui.autocomplete.CompletionProvider) DefaultCompletionProvider(org.fife.ui.autocomplete.DefaultCompletionProvider) AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) KeyStroke(javax.swing.KeyStroke)

Example 13 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project nuclei-burp-plugin by projectdiscovery.

the class TemplateGeneratorTab method setupAutoCompletion.

private void setupAutoCompletion(RSyntaxTextArea textEditor) {
    if (this.yamlFieldDescriptionMap != null) {
        final DefaultCompletionProvider defaultCompletionProvider = new DefaultCompletionProvider();
        defaultCompletionProvider.setAutoActivationRules(true, null);
        this.yamlFieldDescriptionMap.forEach((key, value) -> defaultCompletionProvider.addCompletion(new BasicCompletion(defaultCompletionProvider, key, value)));
        final AutoCompletion autoCompletion = new AutoCompletion(defaultCompletionProvider);
        // autoCompletion.setShowDescWindow(true); TODO point to or open remote documentation
        autoCompletion.setAutoCompleteEnabled(true);
        autoCompletion.setAutoActivationEnabled(true);
        autoCompletion.setAutoCompleteSingleChoices(false);
        autoCompletion.setAutoActivationDelay(500);
        autoCompletion.install(textEditor);
    }
}
Also used : DefaultCompletionProvider(org.fife.ui.autocomplete.DefaultCompletionProvider) AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) BasicCompletion(org.fife.ui.autocomplete.BasicCompletion)

Example 14 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project RSTAUI by bobbylight.

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 15 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project openosrs-dev by blurite.

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)

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