From: Joel VanderWerf Date: 2003-03-16T07:09:26+09:00 Subject: Re: |FXRUBY] contextual menu in an Icon List Pierre Baillet wrote: > Dear rubyists, > > has any of you ever managed to Build a FXIconList with a contextual menu > over every item in the list (contextual menu which would change > depending on which item you right-clicked on) > > So far, all my attempts have given something not really usable. > > If so, a code snippet would be really welcomed... I have a file browser class based on FXFileList which has a context-sensitive popup. FXFileList is based on FXIconList, so the same technique would work. I'll try to extract a snippet, but if you want the full code it's in my foxtails package on RAA. Look at lib/foxtails/FTFileBrowser.rb and examples/file-browser.rb. When initializing, you connect the icon list with this method call: connect(SEL_RIGHTBUTTONRELEASE, method(:onPopupMenu)) and define onPopupMenu as in FXFileSelector::onPopupMenu in the fox source: def onPopupMenu sender, sel, event if event.moved then return 1 end index = getItemAt(event.win_x, event.win_y) filemenu = FXMenuPane.new(self) ### Add your menu items here ### FXMenuCommand.new(filemenu, ...) filemenu.create() filemenu.popup(nil, event.root_x, event.root_y) filemenu.grabKeyboard getApp().runModalWhileShown(filemenu) return 1 end I haven't noticed any delay whatsoever in dynamically creating panes like this. YMMV. FoxTails also has dynamically generated popup menu buttons (see examples/simple.rb and lib/foxtails/FTPopupButton.rb).