Re: Trapping menu clicks in GTK2

new topic     » goto parent     » topic index » view thread      » older message » newer message

Michael J. Sabal wrote:
> 
> 
> Irv, or anyone else with GTK2 experience:
> 
>   How do you trap menu selections?  I tried applying the code for the quit
> button from button.exu to a File-->Quit menu choice, but it didn't work.  Any
> help is as always appreciated.

Here's a clip from a working program.
bar and filemenu are defined as atoms, fileitem is an object, since 
it grows as the menu items are added.
the db: items are, of course, from "include db_file.e as db" , ,
where db_file.e has handlers to connect to database.e functions.
For example: db:create references a global constant 'create' in db_file.e ...

function Create()
-- call db_create()
return NULL
end function
global constant create = call_back(routine_id("Create"))


So, then you can hook that call into the menu item as shown below:

bar = menubar()
pack(panel,bar,0,0,0)

filemenu = menuitem("_File")
 fileitem  = choice("gtk-new",db:create,0)
 fileitem &= choice("gtk-open",db:open,0)
 fileitem &= choice("gtk-close",db:close,0)
 separator()
 fileitem &= choice("gtk-quit",quit,win)
 set_submenu(filemenu)
 setMenuItems(fileitem,{1,1,0})


The zero passed as the last parameter is usually unused, but whatever is 
there will be passed to the function being called, so you could pass 
a value if it would help.

Perhaps if you had a 'help' function, you could declare several menu 
items which all called the same routine, but passed a different number, 
to show different bits of information. 

Hope that helps, 
Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu