Dynamically populating a stack menu bar

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Dynamically populating a stack menu bar

Post by massung » Sat Jan 16, 2010 9:55 pm

Sorry, I've been searching the forums here and trying everything I can think of, but I just can't get this to work.

Basically, at runtime something will happen, and I'd like to populate one of my stack's menus with a list of options. As a close example to what I want to do, let's say I'm making a text editor. And one of my menus is the "Font" menu to change the font of the selected text. I use the menu builder to create my basic menu, and on preOpenStack I get all the fontNames that are "ANSI" and want to add them to that menu. Right now I basically do...

Code: Select all

on preOpenStack
   get the fontNames

   ## process it to get just the ones that are "ANSI"

   set the text of button "Font" to it
end preOpenStack
However, the menu doesn't populate with the list of fonts.

If I open up the message box and type put the text of button "Font" it will correctly show the list of fonts. If I open up the inspector, though, the menu items of the button are what they were originally. And - obviously - the actual menu items haven't changed in the menubar. I'm not sure if there's a command I need to call to update the menu or if I'm setting the wrong property.

If it matters, I'm developing on OS X (in case OS X and Windows are different in this regard).

Thanks!

Jeff M.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Dynamically populating a stack menu bar

Post by BvG » Sat Jan 16, 2010 11:05 pm

I can't replicate your problem. I did this:
  • made a new stack
  • created a option menu
  • set it's name to "font"
  • script of stack:

    Code: Select all

    on openstack
       set the text of button "Font" to the fontnames
    end openstack
  • save stack in a place where i can find it
  • close Rev IDE
  • opwn IDE again
  • open test stack from recent files list
result: the menu contains the fonts
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: Dynamically populating a stack menu bar

Post by massung » Sat Jan 16, 2010 11:41 pm

It's important to know that I'm not populating an option button. I'm populating a menu - like the one at the top of the window (a menu I've made with the menu builder).

For your test, make a new stack, open the menu builder and create a menu named "font" and then do the same thing from there.

I understand that a menu is just a button as well, and if I just make a simple option button it works for me too. But it doesn't for a button created by the menu builder.

Jeff M

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: Dynamically populating a stack menu bar

Post by massung » Sat Jan 16, 2010 11:49 pm

Ugh. I'm not sure what's different, but I just went through it all again and this time it works.

I suppose I should be happy, but I dislike it when something doesn't work... then does... and I don't know why. It's an indication that I'm going to have to fight this battle again sometime in the future.

Oh well.

Thanks for checking it!

Jeff M.

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Dynamically populating a stack menu bar

Post by Klaus » Sun Jan 17, 2010 12:34 pm

Hi Jeff,

the script looks OK! I always use it this way and never had problems!

Try to add a "descriptor" and avoid using IT, IT may change when you least exspect it :)
...
put the fontnames into tFonts
## do your font stuff
set the text of button "Font" of grp "MyMenubar" of cd 1 of stack "Stack with the menu group" to tFonts
...

Hope that helps.


Best

Klaus

Post Reply