StyledTextControl autocompletion sort requirement

The STC documentation for AutoCompShow says:

"Note that the itemList must be in sorted order."

Is there a way around this requirement? I'm displaying a list of database column names and would like to display them in a particular order. I'd also like to eliminate options as letters are typed and add options as letters are removed (backspace).

Under GTK, when using an unsorted list, the list displays, but disappears when a letter is typed. I was thinking of using an event like EVT_KEY_DOWN to intercept typing and redisplay the autocompletion list on every keystroke. That way (I think) I could add and remove items from the list during typing and use an unsorted list.

How does that sound. Is there a better way to do this?

Randall

I'm replying to myself to share a solution I found that seems to meet all of the requirements I listed. One disclaimer though. I've only tested this on one platform.

The key to the solution is UserListShow. I'm using that instead of AutoCompShow and catching three events:

1. EVT_STC_CHARADDED. I use this to narrow down the list I'm showing. For example, if the list is ['shoe', 'sun', 'rain'] and the user types 's' while AutoCompActive(), I draw a new list (calling UserListShow again) ['show', 'sun'].

2. EVT_KEY_DOWN. I'm using this to look for a backspace b/c EVT_STC_CHARADDED doesn't catch it. If AutoCompActive() and keycode == 8, redraw the list.

3. EVT_STC_USERLISTSELECTION. When the user makes a selection, this sends an event so you can see what they selected and show it. This is great because you can include extra information in your list that's not shown after being selected.

I'm still working on it so I'll probably find some improvements to this method, but it's overall not to bad.

One thing I haven't figured out is when a backspace command is intercepted, performing the list update and calling evt.Skip() makes the list disappear. Also when I call evt.Skip() then do the list update. What's so weird is that I'm explicitly calling UserListShow after evt.Skip() and the list doesn't show. To work around this, I'm calling CmdKeyExecute(stc.STC_CMD_DELETEBACK) before UserListShow and not calling evt.Skip(). Still AutoCompleteActive() == False right before UserListShow is called (which concerns me), but to the user, everything seems OK.

Randall

Randall Smith wrote:

ยทยทยท

The STC documentation for AutoCompShow says:

"Note that the itemList must be in sorted order."

Is there a way around this requirement? I'm displaying a list of database column names and would like to display them in a particular order. I'd also like to eliminate options as letters are typed and add options as letters are removed (backspace).

Under GTK, when using an unsorted list, the list displays, but disappears when a letter is typed. I was thinking of using an event like EVT_KEY_DOWN to intercept typing and redisplay the autocompletion list on every keystroke. That way (I think) I could add and remove items from the list during typing and use an unsorted list.

How does that sound. Is there a better way to do this?

Randall