Re: GtkUIManager help



On 11/24/05, Adam <adam ajtee plus com> wrote:
In my application I want to be able to dynamically add items to a menu after a
configuration file has loaded and after a file has been opened.   The menu's
use gtk_ui_manager to initialise but I am unsure how to go about implementing
to dynamic addition of menu items.

I do this by having a "stub" menuitem which I find and replace at runtime.

My UI XML looks like this:

"    <menu action='ToolkitsMenu'>"
"      <menuitem action='EditToolkits'/>"
"      <separator/>"
"      <menuitem action='Stub'/>"       /* Toolkits pasted here at runtime */
"    </menu>"

Stub is defined like this:

static GtkActionEntry mainw_actions[] = {
        ....

        /* Dummy action ... replaced at runtime.
         */
        { "Stub",
                NULL, "", NULL, "", NULL },

I find and delete stub like this, making a note of the menu it's in:

        /* Fetch the menu we add toolkit menus to.
         */
        item = gtk_ui_manager_get_widget( mainw->ui_manager,
                "/MainwMenubar/ToolkitsMenu/Stub" );
        kitgview->menu = gtk_widget_get_parent( GTK_WIDGET( item ) );

        /* Remove the stub item.
         */
        gtk_widget_destroy( item );

Then add items like this:

                kview->item = gtk_menu_item_new_with_label(
                        IOBJECT( kit )->name );

                gtk_menu_shell_insert( GTK_MENU_SHELL( menu ),
                        kview->item,
                        ICONTAINER( kit )->pos + TOOLKITVIEW_MENU_OFFSET );
                gtk_widget_show( kview->item );

Probably not the best way :-( but it seems to work.

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]