Parameter display popup?


#1

I have a simple editor which uses the CodeEditor component. When the user types a particular keyword into the editor I would like a small window to show up displaying suggested text to follow that keyword(as demonstrated in the attached picture). I’m not looking for an auto complete function, merely a popup window with some text on it. Any ideas how I would go about implementing something like this? I don’t even know if there is a way to find the xy coordinates of the caret so that I can position the widow in the right place.


#2

Just make a Label child component of the component you want to have it above and position it via Component::getMouseXYRelative().


#3

Great, I’ll look into doing it like that. Thanks.


#4

getMouseXYrelative won’t give me the coordinates of the text caret. I would like the label to appear just under the text caret?


#5

Good request - I’ll certainly add a method to return the caret pos.


#6

…no, hang on - you can already get it, using getCaretPos() and getCharacterBounds()…


#7

That’s great Jules, I now have my popup window working great. One thing however. if my popup window is visible and users move to the next line it should become invisible. This doesn’t happen because I set it’s visibility in my codeDocumentChanged() method. Would it be difficult to add a codeDocumentKeyPressed() method that would give one access to the last key that was pressed, regardless of weather a change occurred or not?


#8

You’re really asking for something like a “CodeDocumentActivityListener” that’ll hear about cursor movements, etc. I’ll probably need something like that myself for the jucer, so it’s likely to happen.


#9

adding some pluggable listeners to allow the creation of autocompletion or suggestion popups would be cool indeed.
those listeners would be notified at any changes in the code, where was the caret position at that change, what kind of identifier was around the caret and which kind of operation has done (insert / delete / replace, separator, alpha-numeric, …). this way we can inspect easily what the user was doing and suggestions would come in a breeze.