Re: TODO list item: menu selection

David Santiago <> writes:

> > To comment on your patch; when the comment says "this is a bit of a
> > hack", then I'd generally like to avoid adding more hacks in the same
> > place. And I think that storing a "select_item" flag on a menuitem is
> > definitely a hack.
> I definitely agree. Please don't think this was my first solution! :) I
> originally had a version that worked without changing the menuitem
> structure, but the problem was that when you pop up the menuitem and then
> press the left or right arrows to go to an adjacent menu, you want the
> first menu item of that one selected as well. So my relative unfamiliarity
> with the code, and the fact that someone else had used the timer field in
> the same way led me to believe this might be the only way to really get it
> done. Your suggestion never occurred to me, though... 

Usually having done it wrong once or twice helps to figure out the 
right way to do it. (With me being the "someone" who put the current
hack in there.)
> As I said, this hadn't occurred to me, so I went ahead and redid it like
> this. The code is much simpler, indeed. I'd much prefer this. However, the
> problem is that case with the left/right arrow keys. When this method is
> used, I can't make it respond to this case correctly. How would one go
> about correcting this? 

They way I would do this is handle it in the spot where we do the 
left/right arrow keys:

static void
gtk_real_menu_shell_move_current (GtkMenuShell      *menu_shell,
				  GtkMenuDirectionType direction)
  switch (direction)
      if (parent_menu_shell)
	  if (GTK_MENU_SHELL_CLASS (GTK_OBJECT (parent_menu_shell)->klass)->submenu_placement == 
		       GTK_MENU_SHELL_CLASS (GTK_OBJECT (menu_shell)->klass)->submenu_placement)
	    gtk_menu_shell_deselect (menu_shell);
	    gtk_menu_shell_move_selected (parent_menu_shell, -1);
	  /* Try to find a menu running the opposite direction */
	  while (parent_menu_shell && 
		 (GTK_MENU_SHELL_CLASS (GTK_OBJECT (parent_menu_shell)->klass)->submenu_placement ==
		  GTK_MENU_SHELL_CLASS (GTK_OBJECT (menu_shell)->klass)->submenu_placement))
	    parent_menu_shell = GTK_MENU_SHELL (parent_menu_shell->parent_menu_shell);
	  if (parent_menu_shell)
	    gtk_menu_shell_move_selected (parent_menu_shell, 1);

So, you would change:

	    gtk_menu_shell_move_selected (parent_menu_shell, -1);

To, something like:
  gtk_menu_shell_move_selected (parent_menu_shell, -1);

  GtkMenuItem *item = GTK_MENU_ITEM (parent_menu_shell->active_menu_item);

  if (item->submenu)
       GtkMenuShell *submenu = GTK_MENU_SHELL (item->submenu);
       if (submenu->children)
         gtk_menu_shell_select_item (submenu, submenu->children->data);

The operation of selecting the first child of the active submenu
probably should be encapsulated in a separate function like
gtk_menu_shell_select_submenu_first ().


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