New topic: 

Dynamic Menu That Works in Menu Bar - Is It Possible?

<http://forums.realsoftware.com/viewtopic.php?t=29223>

       Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic         Author  
Message       capaho           Post subject: Dynamic Menu That Works in Menu 
Bar - Is It Possible?Posted: Sat Jul 25, 2009 10:49 am                        
Joined: Fri Jul 21, 2006 12:28 am
Posts: 190              I have tried to create a dynamic font menu in the menu 
bar but can't get it to work.  I can populate it and enable it, create a class 
to compensate for the dysfunctional MenuHandler, but that's as far as it goes.  
MenuItem.Index is always -2147483648 and MenuItem.Checked is never true for the 
selected item.  If I create a font menu in OS X, the menu lists 233 fonts, but 
I haven't found a way to detect the font selection.  Advice, suggestions 
greatly appreciated.

And, yes, I've done numerous searches in these forums but have yet to find a 
solution that works.     
_________________
Regards, 
Carl 
Capaho Web Hosting 
http://www.capaho.com  
                            Top               Karen           Post subject: Re: 
Dynamic Menu That Works in Menu Bar - Is It Possible?Posted: Sat Jul 25, 2009 
11:09 am                        
Joined: Fri Sep 30, 2005 8:53 am
Posts: 588              Adding a font menu that gets defined in code at run 
time is certainly possible, as is adding or removing  menus from the menubar.

But by dynamic do you mean recreate the font list every time the menu is shown? 
If so why do you want to do that?

And what to mean by dysfunctional MenuHandlers? They work as expected. Maybe 
you don't fully understand how to work with RB menus? Again tells us how you 
are trying to do this in more detail and then we can steer you in the right 
direction.

- Karen   
                            Top               jefftullin           Post 
subject: Re: Dynamic Menu That Works in Menu Bar - Is It Possible?Posted: Sat 
Jul 25, 2009 11:42 am                        
Joined: Wed Nov 15, 2006 3:50 pm
Posts: 647              Add one menu item called thefont under a menu item 
called allfonts
Give thefont an index of 0

Add a menuhandler for this menu item to your window.

Add a method to the window  populatefonts

In that:
Code:
while allfonts.count >0
  allfonts.Remove(0)
wend

for x= 1 to fonts.count
  
  m = new menuitem
  m.Text = //font name
  m.Name = thefont
  m.Index = allfonts.count
  allfonts.Append m
  m.AutoEnable =false
  m.enabled = true
  
next
   
                            Top               capaho           Post subject: 
Re: Dynamic Menu That Works in Menu Bar - Is It Possible?Posted: Sat Jul 25, 
2009 10:46 pm                        
Joined: Fri Jul 21, 2006 12:28 am
Posts: 190              Thanks for the suggestions, jefftullin.  I tried your 
code snippet and it did get the MenuHandler working, but it's still returning 
an index of -2147483648.  The LR shows that MenuItem.Index is read-only, so it 
doesn't look like it works in trying to set an index number when creating the 
menu.  Also, the following code was not effective in enabling the menu items:
Code:m.AutoEnable =false
m.enabled = true


The only thing I've tried that works is looping through the menu items in 
EnableMenuItems, like this:
Code:For i = 0 to allfonts.Count - 1
  allfonts.Item(i).Enable
Next


If I loop through the menu items like this:
Code:For i = 0 to allfonts.Count - 1
  MsgBox allfonts.Item(i).Text
Next


I get the font names from the menu, but if I do this:
Code:For i = 0 to allfonts.Count - 1
  If allfonts.Item(i).Checked = True then
  MsgBox allfonts.Item(i).Text
  End if
Next

The selected item fails to produce a message box with its name.

If I do this:
Code:MsgBox Str(allfonts.Index)

I always get an index of -2147483648 for the selected item.  I have tried every 
way I can think of to populate the menu, but I have not been able to find a way 
to return a valid index number.  Without that, the menu is obviously useless.   
  
_________________
Regards, 
Carl 
Capaho Web Hosting 
http://www.capaho.com  
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to