Problems with ST/X and Solutions

problem with enable/disable menuItem

Postby duetto » 17. Dec 2009, 20:52

hi all,

i'm building a small app with a tree control (SGTObjectList) and a standard file menu. the New menuItem has a key of newKey.

desired behaviour is to have the tree and File|New menuItem to be disabled at application start and then enabled when File|Open is selected. inspector shows that both items are disabled at time of postBuildWith:. they were set to enabled => false in menu editor.

the first line below does enable the tree control but the second does not enable the menu item. inspector shows the menuItem enabled attribute has a value of enabled. inspector also shows it is the correct menuItem.

anybody have an idea why menuItem is not being enabled? am i missing a step?

((builder componentAt:#SGTObjectList)scrolledView) enable.

menuItem := ((builder componentAt: #ToolBar1) menuHolder) atNameKey: #newKey.
menuItem enable.

i'm working with stx 542 on windows xp.

john cummings
Posts: 22
Joined: 28. Sep 2009, 02:43

Re: problem with enable/disable menuItem

Postby cgittinger » 17. Dec 2009, 21:28

personally, I would not use explicit enable/diabled for menuItems and especially not follow the container hierarchy (i.e. componentAt: - scrolledView) it does work, but is pretty fragile, whenever you change the layout or containments or names. I useually use a postBuild-callback and remember the created widget in an instvar. That makes me (at least) independent of the widget's name.
But: why don't you use a valueHolder for enabling/disabling ?
An especially elegant solution are BlockValues, which can track the value of another valueHolder. For example, if you want to enable a MenuItem whenever a selection is present, use something similar to:

for the selection:

Code: Select all
    selectionHolder notNil ifTrue:[
       selectionHolder := ValueHolder new.
    ^ selectionHolder

(that's the standard way as generated by "generate aspect methods).
Then, for the enable-holder, use the following:

Code: Select all
    ^ BlockValue
                with:[:m | m notNil ]
                argument:self selectionHolder

this creates a "pseudo holder" which, watches selectionHolder's contents and computes its own value as "m notNIl" whenever it does change. Use this valueHolder as an enable-holder of the menuItem in question.

Actually, enabling/disabling menu items as you described should also work, but I had to setup some code and run it to see what is actually goin in. Could you attach some more code - best would be a complete mini.example ?
Posts: 61
Joined: 12. Nov 2008, 17:05

Re: problem with enable/disable menuItem

Postby duetto » 17. Dec 2009, 23:18


as usual, thanks for the quick reply. i will build a test app using your suggestions. if i still have the problem, i will send the mini app. i'm not a pro coder, so this will take awhile :)

thanks again,

Posts: 22
Joined: 28. Sep 2009, 02:43

Return to Troubleshooting

Users browsing this forum: No registered users and 1 guest

Design by GB