Game Development Community

Adding custom tab completion to a GuiTextEditCtrl ?

by Orion Elenzil · in Torque Game Engine · 01/24/2008 (7:43 pm) · 3 replies

Howdy folks -

i'd like to add tab completion to a GuiTextEditCtrl,
but naturally want it to use my own dictionary, not the Console's namespace bizniss.

i see a few pieces, but haven't quite determined how/if they wire together:

script:

* on the control in question, set tabComplete = "1"

* this means the control will now receive callbacks like:
function myTextEditCtrl::onTabComplete(%this, %boolForward)
{
   // ie, %boolForward is true iff shift was not engaged when tab was pressed
}


engine:

* we see const char* Dictionary::tabComplete()

* we see Dictionary::add(StringTableEntry)


.. this all looks great,
where i'm getting a little muddled is that Dictionary doesn't seem to be exposed to script.

any pointers ?

tia!

#1
02/05/2008 (8:57 pm)
Bump!
#2
02/05/2008 (9:13 pm)
Hey Orion,
There are a few ways you could approach doing this, I suppose it really depends on your requirements for implementation. That is, do you want to have multiple dictionaries to tabComplete from? Or do you just want to tabComplete from a single dictionary instead of from the console's namespace craziness?

If you just want a single dictionary lookup you could rig this up pretty easily by creating a script function that passed on whatever string you have and returned the result...

ConsoleFunction( customTabComplete, const char*, ...)
{
    return sgMySpecialDict->tabComplete(theArgs);
}

then call that from your onTabComplete callback.

If you want to use multiple dynamically assigned dictionaries based on the context of use, you'd want to do something slightly more involved. One way would be to keep another dictionary of dictionaries that were looked up by name, and have those found using the same method as above. With the 'name' of the dictionary as an argument.

ConsoleFunction( customTabComplete, const char*, ...)
{

    Dictionary *theDictionary = sgDictionaryDictionary.lookup(argDictionaryName);
    return theDictionary->tabComplete(theArgs);
}

Let me know if this helps, I'm mostly theorizing here so it may not be what you're looking for.

Cheers,
-Justin
#3
02/05/2008 (9:41 pm)
Hey Justin, thanks for getting back!

i see.
so you're saying don't bother exposing the Dictionary class to script,
but handle it in C.

yeah.

i could see a few functions:

addToDict(dictionaryName, entry)
removeFromDict(dictionaryName, entry)
tabComplete(dictionaryName, theArgs)
deleteDict(dictionaryName)

.. i think those would let script manage the dictionaries fairly well.

cool,
thanks for the idea!