Re: [gtk-list] Menu and shortcuts questions.



Rok Papez wrote:
> 
> Hello!
> 
> I have already posted this question on app-devel-list but there was no reply.
> I don't use the item factory to create the menus (I'm manipulating them
> manualy).
> Now I need to add the shortcuts to my manualy made menus and make the
> "sensitive keys" underlined. (I'm trying to make the "F" in "File" menu
> underlined and I want the "File" menu to open when I press alt+F, all this
> without the item factory).
> How does one use the accelerator group?? Is it possible to make the insert and
> delete keys shortcuts to some actions?
> 
> I've already tried reading the source code to figure out how the item factory
> does it but I didn't get very far :(.

Glade 0.5.1 will output code to do this (http://glade.pn.org). Here's some example
code (with the extra Glade-specific stuff taken out):

  GtkAccelGroup *accel_group;
  GtkAccelGroup *file1_menu_accels;
  guint tmp_key;

  accel_group = gtk_accel_group_new ();

  ...

  menubar1 = gtk_menu_bar_new ();
  gtk_widget_show (menubar1);
  gtk_box_pack_start (GTK_BOX (vbox1), menubar1, FALSE, FALSE, 0);

  file1 = gtk_menu_item_new_with_label ("");
  tmp_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (file1)->child),
                                   _("_File"));
  gtk_widget_add_accelerator (file1, "activate_item", accel_group,
                              tmp_key, GDK_MOD1_MASK, 0);
  gtk_widget_show (file1);
  gtk_container_add (GTK_CONTAINER (menubar1), file1);

  file1_menu = gtk_menu_new ();
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (file1), file1_menu);
  file1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (file1_menu));

  new1 = gtk_menu_item_new_with_label ("");
  tmp_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (new1)->child),
                                   _("_New"));
  gtk_widget_add_accelerator (new1, "activate_item", file1_menu_accels,
                              tmp_key, 0, 0);
  gtk_widget_show (new1);
  gtk_container_add (GTK_CONTAINER (file1_menu), new1);



  gtk_window_add_accel_group (GTK_WINDOW (window1), accel_group);


Damon




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