A problem with Font Menu in LC Resource Center

Peter M. Brigham, MD pmbrig at gmail.com
Sat Apr 7 08:32:53 EDT 2012


On Apr 6, 2012, at 10:44 PM, Charles Szasz wrote:

> on menuPick theMenuItem
>   set the itemDelimiter to "|"
>   switch item 1 of theMenuItem ---the submenu name
>      case "Font"
>         set the textFont of field "Example Text"\
>                to item 2 of theMenuItem
>         break
>      case "Size"
>         set the textSize of field "example Text"\ 
>                to item 2 of theMenuItem 
>         break
>      case "Plain"
>         ---Plain removes all styles:
>         set the textStyle of field "example text" to empty
>         break
>      case "Bold"  ---These two remaining menu items
>         break
>      case" Italic"  ---are handled with the same piece of code!
>         break
>         put the textStyle of field "example text" into currentStyle
>         set the itemDelimiter to comma
>         if theMenuItem is among the items of currentStyle then
>            ---already has that style, so remove it
>            delete item (itemOffset(theMenuItem,currentStyle))\
>            of currentStyle
>         else
>            ---add the style to any existing styles
>            if currentStyle is "Plain"
>            then put theMenuItem into currentStyle
>            else put comma & theMenuItem after currentStyle
>         end if
>         set the textStyle of field "Example Text" to currentStyle
>   end switch
> end menuPick

Well, one problem is that you have breaks at the top of 2 sections, which will exit you without any action.

It looks as if you want this instead:

on menuPick theMenuItem
  set the itemDelimiter to "|"
  switch item 1 of theMenuItem ---the submenu name
     case "Font"
        set the textFont of field "Example Text"\
               to item 2 of theMenuItem
        break
     case "Size"
        set the textSize of field "example Text"\ 
               to item 2 of theMenuItem 
        break
     case "Plain"
        ---Plain removes all styles:
        set the textStyle of field "example text" to empty
        break
     case "Bold"  ---These two remaining menu items    **** no break
     case" Italic"  ---are handled with the same piece of code!    **** no break
        put the textStyle of field "example text" into currentStyle
        set the itemDelimiter to comma
        if theMenuItem is among the items of currentStyle then
           ---already has that style, so remove it
           delete item (itemOffset(theMenuItem,currentStyle))\
           of currentStyle
        else
           ---add the style to any existing styles
           if currentStyle is "Plain"
           then put theMenuItem into currentStyle
           else put comma & theMenuItem after currentStyle
        end if
        set the textStyle of field "Example Text" to currentStyle
        break
  end switch
end menuPick

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig





More information about the use-livecode mailing list