From: Lyle Johnson Date: 2003-03-17T07:00:07+09:00 Subject: Re: |FXRUBY] contextual menu in an Icon List 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, ...) 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. >> You may also have to manage the selection a bit to give some feedbackk >> on which items this is going to run on. >> >> if !isItemSelected(index) >> killSelection >> setCurrentItem(index) >> selectItem(index) >> end >> > > That's a good idea. I was thinking it would be better if right-click > didn't change the selection and instead operated only on the clicked-on > object, but that's probably bad GUI design. Also, I notice that at least > one file browser (konqueror) does change the selection as you suggest, > and it agrees with you even in the case of multiple selection. 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 ;)