New topic: 

no menu attached to format toolbutton, why not? what'smissng

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

         Page 1 of 1
   [ 7 posts ]                 Previous topic | Next topic          Author  
Message        brianheibert          Post subject: no menu attached to format 
toolbutton, why not? what'smissngPosted: Sat Mar 20, 2010 6:06 pm               
          
Joined: Sat Jan 23, 2010 3:03 pm
Posts: 105                I have this in my toolbar's open event

Code:  Dim FormatToolBtn as new ToolButton
  FormatToolBtn.name = "Format"
  FormatToolBtn.caption = "Format"
  FormatToolBtn.icon = FormatBtn
  Dim FormatMenu as new menuItem
  
  if app.fontavailable("Times New Roman") then
  Dim FontTimesNewRoman as New MenuItem
  FontTimesNewRoman.text = "Times New Roman"
  FontTimesNewRoman.append FontTimesNewRoman
  end if
  
  if app.fontavailable("Comic Sans MS") then
  Dim FontComicSansMS as New MenuItem
  FontComicSansMS.text = "Comic Sans MS"
  FontComicSansMS.append FontComicSansMS
  end if
  
  if app.fontavailable("Monaco") then 
  Dim FontMonaco as New MenuItem
  FontMonaco.text = "Monaco"
  FontMonaco.append FontMonaco
  end if
  
  if app.fontavailable("Andale Mono") then
  Dim FontAndaleMono as New MenuItem
  FontAndaleMono.text = "Andale Mono"
  FontAndaleMono.append FontAndaleMono
  end if
  
  if app.fontavailable("System") then
  Dim SystemFont as New MenuItem
  SystemFont.text = "System"
  SystemFont.append SystemFont
  end if
  
  if app.fontavailable("Lucida Grande") then
  Dim LucidaGrande as New MenuItem
  LucidaGrande.text = "Lucida Grande"
  LucidaGrande.append LucidaGrande
  end if
  
  FormatToolBtn.DropdownMenu=FormatMenu
  
  FormatToolBtn.Style=ToolButton.ToolStyleDropDown
  FormatToolBtn.DropdownMenu=FormatMenu
  me.append FormatToolBtn


and this in action event of the toolbar
Code:  if item.name = "Format" then
  Dim FMenu as new menuitem
  dim x as integer
  
  for x = 0 to fontcount - 1
  dim m as new menuitem
  dim m1 as new menuitem
  m1.text = "-"
  m.text = font(x)
  fmenu.append m
  fmenu.append m1
  next
  
  dim m as menuitem
  m=fmenu.popup
  if m <> nil then
  msgbox m.text 
  end if
  
  end if


it displays a format toolbutton but it still doesn't display a menu when the 
format toolbutton is clicked.  What's missing?  What do I need to change?      
_________________
Brian Heibert
brianheibert.net
insanemonkeysoftware.com
[email protected]  
                             Top                 jefftullin          Post 
subject: Re: no menu attached to format toolbutton, why not? what'smiPosted: 
Sat Mar 20, 2010 6:31 pm                                 
Joined: Wed Nov 15, 2006 3:50 pm
Posts: 1408                Remove all this code

Code:if app.fontavailable("Times New Roman") then
  Dim FontTimesNewRoman as New MenuItem
  FontTimesNewRoman.text = "Times New Roman"
  FontTimesNewRoman.append FontTimesNewRoman
  end if
  
  if app.fontavailable("Comic Sans MS") then
  Dim FontComicSansMS as New MenuItem
  FontComicSansMS.text = "Comic Sans MS"
  FontComicSansMS.append FontComicSansMS
  end if
  
  if app.fontavailable("Monaco") then 
  Dim FontMonaco as New MenuItem
  FontMonaco.text = "Monaco"
  FontMonaco.append FontMonaco
  end if
  
  if app.fontavailable("Andale Mono") then
  Dim FontAndaleMono as New MenuItem
  FontAndaleMono.text = "Andale Mono"
  FontAndaleMono.append FontAndaleMono
  end if
  
  if app.fontavailable("System") then
  Dim SystemFont as New MenuItem
  SystemFont.text = "System"
  SystemFont.append SystemFont
  end if
  
  if app.fontavailable("Lucida Grande") then
  Dim LucidaGrande as New MenuItem
  LucidaGrande.text = "Lucida Grande"
  LucidaGrande.append LucidaGrande
  end if
  
  FormatToolBtn.DropdownMenu=FormatMenu
  
  FormatToolBtn.Style=ToolButton.ToolStyleDropDown
  FormatToolBtn.DropdownMenu=FormatMenu
  me.append FormatToolBtn   
                             Top                brianheibert          Post 
subject: Re: no menu attached to format toolbutton, why not? what'smiPosted: 
Sat Mar 20, 2010 6:46 pm                         
Joined: Sat Jan 23, 2010 3:03 pm
Posts: 105                why? fontavailable checks to make sure the fonts my 
app uses are on the users system      
_________________
Brian Heibert
brianheibert.net
insanemonkeysoftware.com
[email protected]  
                             Top                 jefftullin          Post 
subject: Re: no menu attached to format toolbutton, why not? what'smiPosted: 
Sat Mar 20, 2010 7:03 pm                                 
Joined: Wed Nov 15, 2006 3:50 pm
Posts: 1408                Quote:why? fontavailable checks to make sure the 
fonts my app uses are on the users system

Because if you do, it will work.
Whereas right now, it doesn't.  

Secondly because the fonts are added in the toolbar action event. 
In the code I gave you, I said that you could use a select..case to cherry pick 
the fonts that get added to the menu.
The sample code I gave you (and which you changed to add separators between 
every font name) currently adds all fonts .
Working through the font()  array in this way kinda makes  fontavailable  
superfluous.
If a font is in that list, it is available.

So if you want to limit the fonts that show up, you could add something like

Code:if font(x) = "Courier" or font(x) = "Monaco" or font(x) = "Times" then
//add to the font menu
end if   
                             Top                brianheibert          Post 
subject: Re: no menu attached to format toolbutton, why not? what'smiPosted: 
Sat Mar 20, 2010 7:20 pm                         
Joined: Sat Jan 23, 2010 3:03 pm
Posts: 105                I don't want to limit fonts that show up
I want to make sure there on the user's system 
before using them      
_________________
Brian Heibert
brianheibert.net
insanemonkeysoftware.com
[email protected]  
                             Top                 brianheibert          Post 
subject: Re: no menu attached to format toolbutton, why not? what'smiPosted: 
Sat Mar 20, 2010 7:25 pm                         
Joined: Sat Jan 23, 2010 3:03 pm
Posts: 105                okay I took out the font checker to experiment

  Dim FormatToolBtn as new ToolButton
  FormatToolBtn.name = "Format"
  FormatToolBtn.caption = "Format"
  FormatToolBtn.icon = FormatBtn
  Dim FormatMenu as new menuItem
  
  
  Dim FontTimesNewRoman as New MenuItem
  FontTimesNewRoman.text = "Times New Roman"
  FontTimesNewRoman.append FontTimesNewRoman
  
  
  
  Dim FontComicSansMS as New MenuItem
  FontComicSansMS.text = "Comic Sans MS"
  FontComicSansMS.append FontComicSansMS
  
 This is in open 
Code:  Dim FontMonaco as New MenuItem
  FontMonaco.text = "Monaco"
  FontMonaco.append FontMonaco
  
  
  
  Dim FontAndaleMono as New MenuItem
  FontAndaleMono.text = "Andale Mono"
  FontAndaleMono.append FontAndaleMono
  
  
  
  Dim SystemFont as New MenuItem
  SystemFont.text = "System"
  SystemFont.append SystemFont
  
  
  
  Dim LucidaGrande as New MenuItem
  LucidaGrande.text = "Lucida Grande"
  LucidaGrande.append LucidaGrande
  
  FormatToolBtn.DropdownMenu=FormatMenu
  
  FormatToolBtn.Style=ToolButton.ToolStyleDropDown
  FormatToolBtn.DropdownMenu=FormatMenu
  me.append FormatToolBtn


This is in Action...

  if item.name = "Format" then
  Dim FMenu as new menuitem
  dim x as integer
  
  for x = 0 to fontcount - 1
  dim m as new menuitem
  dim m1 as new menuitem
  m1.text = "-"
  m.text = font(x)
  fmenu.append m
  fmenu.append m1
  next
  
  dim m as menuitem
  m=fmenu.popup
  if m <> nil then
  msgbox m.text 
  end if
  
  end if
  
Why is my menu still not showing up?      
_________________
Brian Heibert
brianheibert.net
insanemonkeysoftware.com
[email protected]  
                             Top                 timhare          Post subject: 
Re: no menu attached to format toolbutton, why not? what'smiPosted: Sat Mar 20, 
2010 7:31 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 7452
Location: Portland, OR  USA                Jeff gave you a better solution in 
your other thread.  Why aren't you using it?
jefftullin wrote:To save you asking this question again, here is the complete 
solution, Brian.
(I know you've had all this many times before)

Assuming you have a toolbar already in place, and it is empty, put this code in 
the OPEN event of the window:
(In my hastily prepared test app, the toolbar has been called Toolbar11)

Code:  Dim FormatToolBtn as new Toolbutton
  formattoolbtn.Name = "FontMenu"
  FormatToolBtn.Caption = "Fonts"
  me.Toolbar11.Append formattoolbtn

If you test run your app now, the toolbar will have one button, showing the 
word 'Fonts'
Stop the app, and add this code to the Toolbar11  ACTION event

Code: 
//has the font menu toolbutton been clicked?
 if item.name = "Fontmenu" then

//create a parent menu item
  Dim FMenu as new menuItem
  dim x as integer
  
  for x = 0 to fontcount -1 //loop through all installed fonts
  dim m as new MenuItem
  m.Text = font(x)
  fmenu.append m  //add the names to the menu
   //if you only want a subset, add a select case here and only add the menu 
item if you like the font
  next
  
  dim m as menuitem //this object will get the result of the user's choice
  m= fmenu.PopUp  //show the list of fonts
  if m <> nil then  //as long as something was selected
  msgbox m.Text  //show us what the user chose

   //add your own code to handle the choice

  end if
  
  end if
   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 7 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