From: Peter H. <ph...@gm...> - 2008-03-19 17:14:11
|
I'm not trying to modify a menu built by glade, so I do not know whether it works. But you can build a new (popup) menu from a list like this: import qualified Graphics.UI.Gtk as Gtk submenu <- makeMenu [ ( "submenuItem1", Left action1 ), ( "submenuItem2", Left action2 ) ] menu <- makeMenu [ ( "topItem1", Left topAction1 ), ( "submenu", Right submenu ) ] Gtk.widgetShowAll menu Gtk.menuPopup menu Nothing where makeMenu :: [ ( String, Either (IO()) Gtk.Menu ) ] -> IO Gtk.Menu makeMenu menuDefinition = do menu <- Gtk.menuNew mapM_ (mkMenuItem menu) menuDefinition return menu where mkMenuItem menu (label, actionOrSubmenu) = do item <- Gtk.menuItemNewWithLabel label Gtk.menuShellAppend menu item case actionOrSubmenu of Left action -> Gtk.onActivateLeaf item action >> return () Right submenu -> Gtk.menuItemSetSubmenu item submenu I just create it anytime I need it and leave it unreferenced when used. It should destruct by itself when GC runs. Peter. 邓超 wrote: > Hi all, > I'm learning how to using gtk2hs, and here I got a problem, that is > how to add popup menu item. For I draw the GUI form by Glade3, which > only can add a empty popup menu on a form, and I haven't found anywhere > to add menu item in Glade3, so I think I may add menu item by writing > code. But how to do it? Can anybody teach me? And if can have a sample > should be better! Thank you very much! > > Best Regards, > Deng Chao |