Re: Adding a callback to a GtkAction
- From: "John Cupitt" <jcupitt gmail com>
- To: beckenba sfu ca
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Adding a callback to a GtkAction
- Date: Mon, 20 Mar 2006 07:22:10 +0000
On 3/20/06, beckenba sfu ca <beckenba sfu ca> wrote:
toolbar item. Obviously I'm missing something. How do you add a callback
to a GtkAction item?
For a regular pushbutton item, make a table of GtkActionEntry:
static GtkActionEntry mainw_actions[] = {
{ "NewColumn",
GTK_STOCK_NEW, N_( "New C_olumn" ), NULL,
N_( "Create a new column" ),
G_CALLBACK( mainw_column_new_action_cb ) },
....
};
Have some XML for your menubar:
static const char *mainw_menubar_ui_description =
"<ui>"
" <menubar name='MainwMenubar'>"
" <menu action='FileMenu'>"
" <menu action='FileNewMenu'>"
" <menuitem action='NewColumn'/>"
....
Then when you build a window, make an actiongroup:
mainw->action_group = gtk_action_group_new( "MainwActions" );
gtk_action_group_set_translation_domain( mainw->action_group,
GETTEXT_PACKAGE );
gtk_action_group_add_actions( mainw->action_group,
mainw_actions, G_N_ELEMENTS( mainw_actions ),
GTK_WINDOW( mainw ) );
Make a UI manager:
mainw->ui_manager = gtk_ui_manager_new();
gtk_ui_manager_insert_action_group( mainw->ui_manager,
mainw->action_group, 0 );
Link the accelerators to your window:
accel_group = gtk_ui_manager_get_accel_group( mainw->ui_manager );
gtk_window_add_accel_group( GTK_WINDOW( mainw ), accel_group );
Build the menubar:
error = NULL;
if( !gtk_ui_manager_add_ui_from_string( mainw->ui_manager,
mainw_menubar_ui_description, -1, &error ) ) {
g_message( "building menus failed: %s", error->message );
g_error_free( error );
exit( EXIT_FAILURE );
}
Extract the built widgets and attach to your window:
mbar = gtk_ui_manager_get_widget( mainw->ui_manager, "/MainwMenubar" );
gtk_box_pack_start( GTK_BOX( vbox ), mbar, FALSE, FALSE, 0 );
gtk_widget_show( mbar );
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]