From: Joel VanderWerf Date: 2003-03-17T07:01:10+09:00 Subject: Re: |FXRUBY] contextual menu in an Icon List Lyle Johnson wrote: > Joel VanderWerf wrote: > >> Thien Vuong wrote: >> >>> If the menu is complex and shows some delay, I'd split the menu pane >>> instantiation part out, and only bind the create/popup/run to the >>> right click event. >> >> >> How would you handle dynamic menu content then? > > > You should be able to use FXWindow#removeChild to remove menu commands > that are no longer needed, e.g. > > menuPane.removeChild(aMenuCommand) > > and add new menu commands to an existing menu pane as usual, e.g. > > FXMenuCommand.new(menuPane, ...) But then you have to add them back when the context changes back to an item that requires them. The logic is clearer if you just build up the menus from scratch, isn't it? I suppose if you only had 2 or 3 kinds of items, you could precreate menus for each... > Don't forget about the FXWindow#linkBefore and FXWindow#linkAfter > methods, if you need to rearrange the order of child windows. Also don't > forget to call create on newly-added child windows if they're being > added to an already-created menu pane, i.e. > > newItem = FXMenuCommand.new(menuPane, ...) > newItem.create > > Having said all of that... unless the menu is really, *really* complex, > it ought to be fast enough to just create these popup menus on-the-fly, > as needed. That's been my experience too. Even with 3 cascades, checked items, icon items, etc. ... > Also important to note that FXIconList#getItemAt will return -1 if they > don't right-click on an item (i.e. they perhaps right-click in the > whitespace *outside* of any items). Your code should presumably handle > this possibility ;) In that case I go ahead and add "Delete...", for example, but I disable it to show it only applies when you actually manage to hit an item.