uppercase completion

Questions on using RSyntaxTextArea should go here.

Moderator: robert

uppercase completion

Postby marcio jr » Wed Sep 26, 2012 3:47 pm

Hi! I would like to know if is possible to convert the completion expressions to upper case. For example:
1. Caps Lock is activaded
2. There is a basic completion like:
Code: Select all
        provider.addCompletion(new BasicCompletion(provider, "transaction flush", null, "The transaction flush statement enables or disables the transaction flush mechanism."));

3. I type TRANS and press <ctrl> + <space>
4. Instead of "transaction flush", I want to get "TRANSACTION FLUSH"

ps.: Im working with JEditorPane

Thanks!
marcio jr
 

Re: uppercase completion

Postby robert » Thu Sep 27, 2012 1:18 pm

It's always great to hear about someone using the AutoComplete library in a text component other than RSyntaxTextArea!

The easiest way is to create your own subclass of AutoCompletion and override the getReplacementText() method to upper-case the result. This method is basically a hook for folks to modify the completion text right before it gets inserted.

java code:

@Override
protected String getReplacementText(Completion c, Document doc, int start, int len) {
String text = super.getReplacementText(c, doc, start, len);
return text==null ? null : text.toUpperCase();
}
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: uppercase completion

Postby marcio jr » Fri Sep 28, 2012 5:12 pm

first of all, thank you very much for this great tool! I would like to use the autocompletion + rsta but rsta does not support my syntax (pick d3 basic programs), so Im using an DefaultStyledDocument to highlight the keywords. I see your TokenMakerMaker but had problems with $ character and other particularities..also I cant get the new flex files work with rsta.

About upper case, your code works very well in BasicCompletions and FunctionCompletions, but in TemplateCompletions nothing happens.

I implemented this way:

java code:

AutoCompletion ac = new AutoCompletion(provider) {

@Override
protected String getReplacementText(Completion c, Document doc, int start, int len) {
String text = super.getReplacementText(c, doc, start, len);
if (Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK) == true) {
return text == null ? null : text.toUpperCase();
} else {
return text == null ? null : text;
}

}
};
marcio jr
 

Re: uppercase completion

Postby robert » Sat Sep 29, 2012 2:41 pm

Looks like parameterized completions, such as templates, take a different code path than regular completions. As this may not be fixed for awhile since it's not straightforward, can you not simply upper-case all your completion information before it is loaded?
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: uppercase completion

Postby marcio jr » Mon Oct 01, 2012 7:19 pm

yes, could do it, but how can I verify case and load completions at runtime? Some event before to call the choices box?
marcio jr
 

Re: uppercase completion

Postby robert » Tue Oct 02, 2012 12:29 pm

How are you currently loading your completions? If you use DefaultCompletionProvider (or a subclass) and an XML input file matching the specification in CompletionXml.dtd, you can ensure your data is capitalized in the XML itself.
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron