Menu.st
changeset 584 9a4c30f7586f
parent 582 94f55f6a8bad
child 589 cc422fe7824f
equal deleted inserted replaced
583:f3b3936710c1 584:9a4c30f7586f
    52 
    52 
    53 groupSizes:something
    53 groupSizes:something
    54     "set the value of the instance variable 'groupSizes' (automatically generated)"
    54     "set the value of the instance variable 'groupSizes' (automatically generated)"
    55 
    55 
    56     groupSizes := something.!
    56     groupSizes := something.!
       
    57 
       
    58 labelAt:anIndex
       
    59     "gets the label of the menu item at the given index or nil
       
    60     "
       
    61     |item|
       
    62 
       
    63     (item := self menuItemAt:anIndex) notNil ifTrue:[
       
    64         ^ item label
       
    65     ].
       
    66   ^ nil
       
    67 
       
    68 !
       
    69 
       
    70 labelAtValue:aValue
       
    71     "gets the label of the menu item assigned to value
       
    72     "
       
    73     |item|
       
    74 
       
    75     item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue ].
       
    76 
       
    77     item notNil ifTrue:[
       
    78         ^ item label
       
    79     ].
       
    80   ^ nil
       
    81 
       
    82 !
    57 
    83 
    58 labels
    84 labels
    59     "return a collection of labels from my items"
    85     "return a collection of labels from my items"
    60 
    86 
    61     ^ items collect:[:anItem | anItem label]
    87     ^ items collect:[:anItem | anItem label]
    77 
   103 
    78 
   104 
    79 !
   105 !
    80 
   106 
    81 menuItemAt:index
   107 menuItemAt:index
    82     ^ items at:index
   108     "gets the menu item at the given index. When the index is out of bounds
       
   109      nil is returned
       
   110     "
       
   111     (index > 0 and:[index <= items size]) ifTrue:[
       
   112         ^ items at:index
       
   113     ].
       
   114   ^ nil
    83 !
   115 !
    84 
   116 
    85 menuItems
   117 menuItems
    86     ^ items
   118     ^ items
    87 !
   119 !
   137     "Created: 25.2.1997 / 19:49:29 / cg"
   169     "Created: 25.2.1997 / 19:49:29 / cg"
   138 ! !
   170 ! !
   139 
   171 
   140 !Menu methodsFor:'accessing resource'!
   172 !Menu methodsFor:'accessing resource'!
   141 
   173 
   142 findGuiResourcesIn:aResourceContainer
   174 findGuiResourcesIn:aResourceContainerOrApplication
   143     "setup a resource owner
   175     "setup a resource owner
   144     "
   176     "
   145     aResourceContainer notNil ifTrue:[
   177     aResourceContainerOrApplication notNil ifTrue:[
   146         items notNil ifTrue:[
   178         items notNil ifTrue:[
   147             items do:[:anItem| anItem findGuiResourcesIn:aResourceContainer ]
   179             items do:[:anItem| anItem findGuiResourcesIn:aResourceContainerOrApplication ]
   148         ]
   180         ]
   149     ]
   181     ]
   150 
   182 
   151 ! !
   183 ! !
   152 
   184 
   275     coll add:(groupSizes literalArrayEncoding).
   307     coll add:(groupSizes literalArrayEncoding).
   276     coll add:nil.
   308     coll add:nil.
   277   ^ coll asArray
   309   ^ coll asArray
   278 ! !
   310 ! !
   279 
   311 
       
   312 !Menu methodsFor:'enumerating'!
       
   313 
       
   314 menuAndSubmenusDetectItem:aOneArgBlock
       
   315     "evaluate the block for each item in the current menu and all
       
   316      submenus. In case that the block returns a non nil argument,
       
   317      the item will be returned
       
   318     "
       
   319     |sm item|
       
   320 
       
   321     items notNil ifTrue:[
       
   322         items do:[:anItem|
       
   323             (aOneArgBlock value:anItem) notNil ifTrue:[
       
   324                 ^ anItem
       
   325             ].
       
   326             (sm := anItem submenu) notNil ifTrue:[
       
   327                 item := anItem submenu menuAndSubmenusDetectItem:aOneArgBlock.
       
   328                 item notNil ifTrue:[
       
   329                     ^ item
       
   330                 ]
       
   331             ]
       
   332         ]
       
   333     ].
       
   334   ^ nil
       
   335 ! !
       
   336 
       
   337 !Menu methodsFor:'menu items'!
       
   338 
       
   339 someMenuItemWithValue:aValue
       
   340     "get the menu item assigned with the value; in case that the value
       
   341      is not found nil is returned
       
   342     "
       
   343     ^ self someMenuItemWithValue:aValue ifNone:nil
       
   344 !
       
   345 
       
   346 someMenuItemWithValue:aValue ifNone:exceptionBlock
       
   347     "get the menu item assigned with the value; in case that the value
       
   348      is not found, the given exceptionBlock is executed and returned
       
   349     "
       
   350     |item|
       
   351 
       
   352     item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue].
       
   353 
       
   354     item notNil ifTrue:[
       
   355         ^ item
       
   356     ].
       
   357   ^ exceptionBlock value
       
   358 ! !
       
   359 
       
   360 !Menu methodsFor:'queries'!
       
   361 
       
   362 hasSubMenuAt:anIndex
       
   363     "test whether the menu item at the given index has a submenu
       
   364     "
       
   365     ^ (self menuItemAt:anIndex) hasSubmenu
       
   366 ! !
       
   367 
   280 !Menu methodsFor:'startup'!
   368 !Menu methodsFor:'startup'!
   281 
   369 
   282 startUp
   370 startUp
   283     "display the menu as a popUp; return the value associated with the
   371     "display the menu as a popUp; return the value associated with the
   284      selected item, 0 if none was selected"
   372      selected item, 0 if none was selected"
   285 
   373 
   286     |menu|
   374     |menu result|
   287 
   375 
   288     menu := MenuPanel menu:self.
   376     menu := MenuPanel menu:self.
   289   ^ menu startUp
   377     result := menu startUp.
       
   378   ^ result ? 0
   290 
   379 
   291 "   
   380 "   
   292         |m|
   381         |m|
   293 
   382 
   294         m := #(#Menu #(
   383         m := #(#Menu #(
   310 ! !
   399 ! !
   311 
   400 
   312 !Menu class methodsFor:'documentation'!
   401 !Menu class methodsFor:'documentation'!
   313 
   402 
   314 version
   403 version
   315     ^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.10 1997-05-23 14:04:26 ca Exp $'
   404     ^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.11 1997-05-27 09:10:34 ca Exp $'
   316 ! !
   405 ! !