still having problems disabling a menu item



I'm still having problems disabling a menu item. Please
help me. I'm pasting my code below. I'll insert
comments where I have questions:

#include "ezftp.h"

static GtkItemFactoryEntry main_menu[] = {
{ "/_Main",                     NULL,         NULL, 0, "<Branch>" },
{ "/Main/_Connect",             "<control>C", NULL, 0, NULL },
{ "/Main/_Disconnect",          "<control>D", NULL, 0, NULL },
{ "/Main/filesep",              NULL,         NULL, 0, "<Separator>" },
{ "/Main/_Quit",                "<control>Q", quit, 0, NULL },
{ "/_Bookmarks",                NULL,         NULL, 0, "<Branch>" },
{ "/Bookmarks/_Add Bookmark",   "<control>A", NULL, 0, NULL },
{ "/Bookmarks/_Edit Bookmarks", "<control>E", NULL, 0, NULL },
{ "/Bookmarks/booksep",         NULL,         NULL, 0, "<Separator>" },
{ "/_Local",                    NULL,         NULL, 0, "<Branch>" },
{ "/_Remote",                   NULL,         NULL, 0, "<Branch>" },
{ "/L_og",                      NULL,         NULL, 0, "<Branch>" },
{ "/Log/C_lear log",            "<control>L", NULL, 0, NULL },
{ "/Log/_Save log",             "<control>S", NULL, 0, NULL },
{ "/Log/_View log",             "<control>V", NULL, 0, NULL },
{ "/Op_tions",                  NULL,         NULL, 0, "<Branch>" },
{ "/_Help",                     NULL,         NULL, 0, "<LastBranch>" },
{ "/Help/_Index",               "<control>I", NULL, 0, NULL },
{ "/Help/A_bout " PROG_NAME,    "<control>B", NULL, 0, NULL },
};

/* main - constructs our gui and sets up the program */
int main(int argc, char **argv)
{
   GtkWidget *window, *main_box, *menu, *tmp;

   gtk_init(&argc, &argv);

   /* Scan command-line arguments */
   if(argc > 1)
   {
      if(strcmp(argv[1], "--help") == 0 ||
         strcmp(argv[1], "-h") == 0)
      {
         showUsage();
      }
      else if(strcmp(argv[1], "--version") == 0 ||
              strcmp(argv[1], "-v") == 0)
      {
         showVersion();
      }
   }

   /* Construct the main gui */
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), ezftp_version);
   gtk_signal_connect(GTK_OBJECT(window), "destroy",
                      GTK_SIGNAL_FUNC(destroy), NULL);
   gtk_signal_connect(GTK_OBJECT(window), "delete_event",
                      GTK_SIGNAL_FUNC(destroy), NULL);
   gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
   gtk_widget_realize(window);

   main_box = gtk_vbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER(window), main_box);

   createMenu(window, main_box);

   gtk_widget_show(main_box);
   gtk_widget_show(window);

   menu = gtk_object_get_data(GTK_OBJECT(window), "main menu");
   /* At this point, tmp is being set to NULL, when it should not be.
      If I have it print out main_menu[2].path, it displays
      /Main/_Disconnect, which is correct.                         */
   tmp = gtk_item_factory_get_widget(GTK_ITEM_FACTORY(menu),
         main_menu[2].path);
   /* That is causing this to fail */
   gtk_widget_set_sensitive(tmp, FALSE);

   gtk_main();
   return 0;
}


/* createMenu - Generates the main menu and stores it in the *
 * given window in the box provided.                         */
void createMenu(GtkWidget *window, GtkWidget *box)
{
   GtkItemFactory *menu;
   GtkAccelGroup *accel;
   gint nitems = sizeof(main_menu)/sizeof(main_menu[0]);
   accel = gtk_accel_group_new();
   menu = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel);

   gtk_item_factory_create_items(menu, nitems, main_menu, NULL);
   gtk_window_add_accel_group(GTK_WINDOW(window), accel);
   gtk_object_set_data(GTK_OBJECT(window), "main menu", menu);
   gtk_box_pack_start(GTK_BOX(box), menu->widget, FALSE, TRUE, 0);
   gtk_widget_show(menu->widget);
}

So, why would tmp be set to NULL? I can't find anything
wrong with my code. It compiles great. I just get the following
error when running the program:

Gtk-CRITICAL **: file gtkwidget.c: line 3313 (gtk_widget_set_sensitive):
assertion `widget != NULL' failed.

I have not been able to find anybody that can help me. I've tried
making the window realize the widget with
gtk_widget_realize(GTK_ITEM_FACTORY(menu)->widget), but that
didn't help.

-- 
+-----------------------------------------------------+
| Jeff "Shippy" Shipman     E-Mail: shippy@cs.nmt.edu |
| Computer Science Major    ICQ: 1786493              |
| New Mexico Institute of Mining and Technology       |
| Homepage: http://www.nmt.edu/~shippy                |
+-----------------------------------------------------+



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