tab buttons and localisation

Bob Hutchison hutch at recursive.ca
Sun Dec 11 10:56:14 EST 2005


Hi,

I use tabbed buttons in my user interface. They work easily enough,  
but every reference to how this is done uses the "on menuPick  
pNew,pOld" handler. And every reference seems to use a switch or  
something to recognise the tab that was clicked based on the  
*visible* text. Sometimes a cardname = tabname trick is used.

This means that the visible text on the tab is used in two places and  
the RR user has to remember to change these values so that they match.

This is generally a Bad Thing, just out of principle. It means that  
when the text of a tab is changed the script has to be changed. This  
is a Really Bad Thing when trying to localise the application: each  
tab will have multiple text values, where, as you'd know if you've  
ever been involved in such a thing, the localised text is pretty much  
guaranteed to change a number of times. (And the cardname = tabname  
obviously won't work in this situation).

Way too error prone.

So, it turns out that there is a property that lists the tab labels,  
so I can write something along the lines of:

on menuPick pNew,pOld
   get the properties of me
   put it["text"] into labels
   put 1 into tabNumber
   repeat for each line aLabel in labels
     if pNew = aLabel then exit repeat
     add 1 to tabNumber
   end repeat

   switch tabNumber
   case 1
     go card "card_one"
     break
   case 2
     go card "card_two"
     break
   case 3
     go card "card_three"
     break
   default
      go card "card_one"
      break
   end switch
end menuPick

I checked this and it does localise correctly.

Any better ways of doing this?

There is nothing particularly clever about what I'm doing, but I'm  
new to RR and this kind of thing is a) not obvious to a new user (how  
to find the name of a property is not obvious to me at least); and,  
b) a nasty trap if not addressed by the RR programmer. The event  
"menuPick" isn't something I find particularly obvious either.

It would be good if this was either fixed in RR or that this, or some  
better technique/trick, was more widely documented.

Cheers,
Bob

----
Bob Hutchison          -- blogs at <http://www.recursive.ca/hutch/>
Recursive Design Inc.  -- <http://www.recursive.ca/>
Raconteur              -- <http://www.raconteur.info/>





More information about the use-livecode mailing list