Page 1 of 1

Dynamically populating a stack menu bar

Posted: Sat Jan 16, 2010 9:55 pm
by massung
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.

Re: Dynamically populating a stack menu bar

Posted: Sat Jan 16, 2010 11:05 pm
by BvG
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

Re: Dynamically populating a stack menu bar

Posted: Sat Jan 16, 2010 11:41 pm
by massung
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

Re: Dynamically populating a stack menu bar

Posted: Sat Jan 16, 2010 11:49 pm
by massung
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.

Re: Dynamically populating a stack menu bar

Posted: Sun Jan 17, 2010 12:34 pm
by Klaus
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