Re: TODO list item: menu selection
- From: David Santiago <mrcooger cyberverse com>
- To: gtk-devel-list redhat com
- cc: jrb redhat com
- Subject: Re: TODO list item: menu selection
- Date: Fri, 7 Apr 2000 11:34:40 -0700 (PDT)
On 7 Apr 2000, Owen Taylor wrote:
>
> David Santiago <mrcooger@cyberverse.com> writes:
>
> > Hello folks. I saw on the GTK+ todo list that one of the items was making
> > menus not select the first item when you click on them. It said to inquire
> > here.
> >
> > Someone posted a patch to the list to do this, but it was pointed out that
> > it didn't handle the case when the user opened the menu with a keyboard
> > shortcut, in which case you'd want the first item to be selected. When I
> > checked (a few minutes ago), this patch had not been applied.
> >
> > .
> > .
> > .
> >
> > Thanks,
> > David Santiago :)
>
> Jonathan Blandford <jrb@redhat.com> has been handling some of the
> other TODO items about menus so this change should be coordinated with
> him.
>
> 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...
> The way I would look at it, what we want to do is select the first
> child _only_ if the selection was done from a keyboard accelerator.
>
> Ideally, this should apply:
>
> - If the user pops up a menu as "Alt-F"
> - If the user selects a submenu by shortcut accelerator
>
> Windows adds one more situation to this, and selects the first item
> when the user hits return when sitting on a the parent menu item of a
> submenu. But since GTK+ automatically pops up the submenu immediately
> when you cursor into the parent menu item, this probably doesn't
> matter for us.
>
> So, considering this, it is a very close approximation if the first
> menu item is selected only when the popup occurs as a result of
> gtk_real_menu_item_activate_item() and not otherwise.
>
> Now the problem, right now, with making this do something different is
> popping up the submenu is routed through the ->select signal, and
> someone could, in theory override that in a subclass. My feeling is
> that the menu code is hairy and convoluted enough that anybody that
> does that is just asking for trouble anyways.
>
> So, I think the right thing to do is to rename
> gtk_menu_item_select_timeout_unlocked() to gtk_menu_item_popup_submenu(),
> call that from gtk_menu_item_select_timeout (), and _directly_
> from gtk_real_menu_item_activate_item(), and then move the
> code to select the first child from that function into
> gtk_real_menu_item_activate_item(), where it can be
> unconditional - you don't need the existing check either.
>
> I think that should simplify the code and get the desired behavior.
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?
Thanks very much,
David Santiago :)
> Regards,
> Owen
>
>
> > @@ -658,13 +660,19 @@
> >
> > /* This is a bit of a hack - we want to select the first item
> > * of menus hanging of a menu bar, but not for cascading submenus
> > + * and not when we are told otherwise (ie, the menu was selected
> > + * with the mouse)
> > */
> > - if (GTK_IS_MENU_BAR (GTK_WIDGET (menu_item)->parent))
> > + if ((GTK_IS_MENU_BAR (GTK_WIDGET (menu_item)->parent))
> > + && (menu_item->select_first_submenu_item))
> > {
> > - GtkMenuShell *submenu = GTK_MENU_SHELL (menu_item->submenu);
> > + GtkMenuShell *submenu = GTK_MENU_SHELL (menu_item->submenu);
> > if (submenu->children)
> > gtk_menu_shell_select_item (submenu, submenu->children->data);
> > }
> > + /* Here we reset this flag to true, so we must be told again
> > + explicitly to select the first menu item. */
> > + menu_item->select_first_submenu_item = TRUE;
> > }
> > }
> >
> > Index: gtk/gtkmenuitem.h
> > ===================================================================
> > RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.h,v
> > retrieving revision 1.10
> > diff -u -r1.10 gtkmenuitem.h
> > --- gtk/gtkmenuitem.h 2000/02/13 08:16:47 1.10
> > +++ gtk/gtkmenuitem.h 2000/04/07 09:50:52
> > @@ -64,6 +64,10 @@
> > guint submenu_direction : 1;
> > guint right_justify: 1;
> > guint timer;
> > + /* If the following flag is true and the menuitem is in a
> > + menubar, the first menu item in the submenu will be
> > + selected when this menu item is selected. */
> > + guint select_first_submenu_item: 1;
> > };
>
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]