Autocompleting Popup Box

Share your advanced PureBasic knowledge/code with the community.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Autocompleting Popup Box

Post by Xombie »

This code is sufficiently different from the original autocompleting stuff that I thought it needed it's own category. The code contains the original completing routines as well as the enhanced popup box code. You can use this code as an update to the non-popup box if you like since I cleaned up the routines.

Basically this code will take an array and an editgadget and will popup a little window with any matching items. You can control the number of characters it will match on and you can update the array at any time if the items change.

It's simply used like ...

Code: Select all

ac_SetAutocomplete(#EditTest, @Array03(), 3)
... where Array03 is an array of strings and the number 3 means we're only matching on 3 or more characters. This will be 0 if you don't want the popup box.

The code needs to be bug tested badly so I'm putting it out there for anyone that's interested :) I expect full reports back ~_~

Let me know when you find any bugs or if I need to change some behavior.

http://www.seijin.net/Storage/Code/Autocomplete.zip

Take it easy! :)
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

that's pretty cool xombie.


as you ask us, here is a little bug :

in main.pb
in the editorgadget '#EditTest' / Array03()

when i type [Return] [Return] char,
selecting CHARFORMAT2 in the popup,
and finally [Tab] it displays 'chCHARFORMAT2 '
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

I'm on it. Didn't check different lines :oops:

Thanks for trying it for me ^_^
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Very good idea to create a new windows which contains the listview !!!!

Bug :
- If you create two lines in the array with the same word, two are in the array

- the case recognition are not used ?

- if i use the bottom arrow, that goes down in the listview but if you use the enter key, that create a linebreak on the editorgadget

- I use this array

Code: Select all

   ;/ Create Items for the editor 
   Array03(0) = "Openw"
   Array03(1) = "Openw"
   Array03(2) = "Openwin"
   Array03(3) = "Openwa"
   Array03(4) = "Openwindow"
   Array03(5) = "Word"
   Array03(6) = "Orgasme"
with

Code: Select all

ac_SetAutocomplete(#EditTest, @Array03(), 1)
And i write w in th editorgadget, i have no listview

Good job, when you (and me f you want) have resolved bugs, could i add this functionnality to LibEditorPlus ?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

@progi
Array03(6) = "Orgasme"
oh yes, fred, i want this feature. :lol:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Nice work (as always) Xombie.

Using your example, in the first string type "jackoo" and then try and delete with the baskspace key. It stops on jack (which is of course one of the searched for words).

Is this right?
I may look like a mule, but I'm not a complete ass.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

Thanks ^_^

No, that's a bug. It happened before and I fixed it but I guess I put it right back :) I'll add it to my list and have a fix out in a few hours. I think :D
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

Alright, I believe I have those bugs fixed. Take a look and let me know what I missed.

I'm going to pretty much totally redo the code as it's horribly messy and chaotic. Bad coding habits for projects like these. I just start with an idea and keep building on it. Makes for quicker results in small projects but not great code >_>

http://www.seijin.net/Storage/Code/Autocomplete.zip

..: Edit :.. By the way, what did you mean about 'case', progi?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

i meant CaseSensitive :

openwindow() <> OpenWindow()
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

Progi1984 mentioned it... I thought <_<

I suppose I'm looking at this from a programming stand point. Should I allow both "TEST" and "Test" in the list and allow the user to select either one? I'm going for a case insensitive approach and not displaying any duplicate items.

Also, I'm going to break off this popup list code on it's own and make it only for editor gadgets (rich edit controls) - any complaints on that? Should it also be allowed for string gadgets (edit controls) ?
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

If i set

Code: Select all

ac_SetAutocomplete(#EditTest, @Array03(), 1)
,
when i have three characters in word, the autocompletion list isn't launched.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

That's weird. I just tested it and it worked over here. I checked with both ...

Code: Select all

ac_SetAutocomplete(#EditTest, @Array03(), 1)
... and ...

Code: Select all

ac_UpdateArray(#EditTest, @Array03(), 1)
... and both worked fine for completing with or without 3 letters already in place. Maybe give me a very specific example? I might be misunderstanding what you're meaning.

Also, I'm reworking the whole code for the popup list so I may have some new stuff to replace this.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

A very specific example

Code: Select all

1. Write a beginning of word
2. The autocompleting is launched
3. Choose your word
4. By example, the length of your word is 5.
5. Now, you delete the last character
6. and the autocompleting is not launched but in the PB ide, YES !
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

Well, here's the reworked code. It only works for rich edit gadgets and only provides for the popup list functionality. Otherwise, it should be similar to the older code. The public functions are ...

Code: Select all

SetGadgetPopList(#EditTest, @Array01(), 3)
UpdatePopList(#EditTest, @Array01(), 1)
RemoveGadgetPopList(-1)
... those. See if it reacts a little better than before. Hopefully it does :)

Also, Progi1984, I still couldn't recreate the error you had. See if this code has the same problem and let me know, please.

http://www.seijin.net/Storage/Code/PopList.zip
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

I haven't no problems now.

Very good work !!!!! Very good work !!!!!
Post Reply