[Gambas-user] Adding keyboard shortcuts to listbox_keyrelease event

Doriano Blengino doriano.blengino at ...1909...
Thu Oct 9 08:17:15 CEST 2008


M0E Lnx ha scritto:
> is there a way to code it in my key_release event?
>
> On Tue, Oct 7, 2008 at 4:53 PM, Benoit Minisini
> <gambas at ...1...> wrote:
>   
>> On mardi 07 octobre 2008, M0E Lnx wrote:
>>     
>>> I have a really long list in a lisbox. I'd like to make it so when I
>>> press "s" on the keyboard, it jumps to the first item whose text
>>> starts with an "s" or any other letter for that matter.
>>>
>>> Can someone suggest a way to do this?
>>>
>>>       
>> Yes, Qt does that by default, but not GTK+. Again, I need to implement that
>> feature in the gb.gtk component.
>>
>>     
I don't know if the KeyRelease event is the right one to use (it seems 
strange to me: why wait for a key release to do something? Normally 
things happen as soon as a key is pressed...), but surely KeyPress can work.

In the KeyPress event of the listbox, start to search for the next item 
beginning with the letter, with wrap; then move the index.
In pseudocode:

    sub xxx_keypress()
      dim scan as integer

      if key.text > "z" or key.text < " " then return      ' this key is 
not "searchable"
     
      scan = last.index
      do
        inc scan
        if scan >= last.count then scan=0  ' wrap to the top again
        if scan=last.index then return     ' went where we started off: 
didn't find another item
        if last[scan].text like key.text & "*" then
          ' found another
          last.index = scan
          return
      loop
    end sub

I did not test this snippet but the general idea should work. May be 
some adjustment is needed...
May be this is slow...

Regards,
Doriano





More information about the User mailing list