[PATCH] Auto complete

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

[PATCH] Auto complete

#1 Post by fixIt »

Here is what I have for the ChatWnd autocomplete. I have a few questions though, for now I have it ignore trying to auto complete words unless they are at least 2 characters...does that sound about right? I also added the ability to save user typed words for auto complete but I made it only if they are at least 5 characters long. Dunno if you think that will be useful or if its not necessary just let me know. Also I am not well versed on all the different objects in the game does it look like I covered all of the important game words? Game words are stored with an upper case first letter I made it find it whether the first letter is upper or lower. However should I make it so the first letter is always capitalized of game words when auto completed? Or maybe game words should be in all caps or another color? And if there is anything that you think I should change stylistically or whatever just let me know.




I release my submissions under the GPL 2.0 license.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [PATCH] Auto complete

#2 Post by Geoff the Medio »

Off the top of my head, the only additional content things you might add are ship hulls and parts.

I have a few issues with the use-typed autocomplete stuff:
* Rather than strtok, having to deal with passing strings by value or copy them, and dealing with casting, you might use boost tokenizer.
* Avoid c-style (casts) and use static_cast or dynamic_cast as appropriate.
* Avoid referencing NULL; I think there are some issues with it, though don't know / remember the details. This shouldn't be an issue if the previous points are followed. For checking if pointers are null, use if (pointer) or if (!pointer), or use if (container.empty()) or similar.
* I'm a bit worried about using std::toupper if non-latin characters get mixed into text; I'm not sure how that will work. Is converting to uppercase really necessary anyway?
* That said, I don't think there's really much need for user-typed words autocomplete anyway...

fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] Auto complete

#3 Post by fixIt »

Geoff the Medio wrote:Off the top of my head, the only additional content things you might add are ship hulls and parts.

I have a few issues with the use-typed autocomplete stuff:
* Rather than strtok, having to deal with passing strings by value or copy them, and dealing with casting, you might use boost tokenizer.
* Avoid c-style (casts) and use static_cast or dynamic_cast as appropriate.
* Avoid referencing NULL; I think there are some issues with it, though don't know / remember the details. This shouldn't be an issue if the previous points are followed. For checking if pointers are null, use if (pointer) or if (!pointer), or use if (container.empty()) or similar.
* I'm a bit worried about using std::toupper if non-latin characters get mixed into text; I'm not sure how that will work. Is converting to uppercase really necessary anyway?
* That said, I don't think there's really much need for user-typed words autocomplete anyway...
Okay thanks. I'll add ship hull and parts once I get the chance. I figured there was probably a better way to do it thanks, in the future i'll use boost tokenizer. I will get rid of user typed words than, that should simplify my changes.

the reason I use toupper is because all game words are stored with the first letter in upper case. And the set comparison/matching does not recognize something if you don't match the case. So with my code if you type g or G you'd get grotto or Grotto. Are you saying you want me to find some boost equivalent? Or are you saying to just get rid of it totally? That way game words will only be completed if the user types the first letter in upper case? meaing they would have to type G to get grotto if they typed g nothing would be found?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [PATCH] Auto complete

#4 Post by Geoff the Medio »

fixIt wrote:Are you saying you want me to find some boost equivalent [for toupper]? Or are you saying to just get rid of it totally?
The boost equivalent idea sounds good. I think there are also case-insensitive string matching functions available... The ValueRef code probably uses them, for example, to recognize Target.Owner or TARGET.owner or whatever variation thereof the scripter uses.

fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] Auto complete

#5 Post by fixIt »

Geoff the Medio wrote:
fixIt wrote:Are you saying you want me to find some boost equivalent [for toupper]? Or are you saying to just get rid of it totally?
The boost equivalent idea sounds good. I think there are also case-insensitive string matching functions available... The ValueRef code probably uses them, for example, to recognize Target.Owner or TARGET.owner or whatever variation thereof the scripter uses.
Thanks, boost surely simplified it a lot. I was using the toupper to get things working case insensitive in hopes of keeping what was already in place.

Anyways now things are case insensitive, I added hulls and parts and got rid of the user typed words.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Last edited by fixIt on Thu Jan 12, 2012 1:23 am, edited 1 time in total.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [PATCH] Auto complete

#6 Post by Geoff the Medio »

I am slightly concerned that the auto keyword might cause some problems as you're using it... It seems to compile with MSVC 2010, but I can't test the OSX or Linux GCC builds. The internet says GCC 4.4 or later should support auto as well, at least with a compiler switch. I'm not sure if anyone is still trying to build FO on GCC 4.3, though...

"a lot" is two words.

When I type "imp" into the chat box and press tab, the autocomplete gives me BLD_IMPERIAL_PALACE. You probably need to look things up in the stringtable before adding to the autocomplete list (except not ShipDesigns, which look their own names up when predefined, or return their user-entered name if user-created).

When I type "bl" and press tab, I get BLD_ART_BLACK_HOLE. I would expect it to only match the start of a word, not find any partial matches in the middle.

It would also be nice if pressing tab repeatedly would cycle through alternative matches.

fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] Auto complete

#7 Post by fixIt »

Ah okay noted, replaced the autos with iterators. Alright I'll look into the rest.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: [PATCH] Auto complete

#8 Post by Vezzra »

fixIt wrote:Ah okay noted, replaced the autos with iterators...
I've been able to build FO successfully with this new version of your patch on OS X.

fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] Auto complete

#9 Post by fixIt »

Vezzra wrote:
fixIt wrote:Ah okay noted, replaced the autos with iterators...
I've been able to build FO successfully with this new version of your patch on OS X.
Thanks for checking. I'll just write everything out in the future though just to be safe.


Heres my updated patch:

-Looks up game words in string table that needed to be
-Repeated tabs allows you to cycle through alternative matches
-It only matches words from the start of a word
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


Post Reply