diff --git a/edit/editmenu.c b/edit/editmenu.c index 2ed7594cc..36718f6b3 100644 --- a/edit/editmenu.c +++ b/edit/editmenu.c @@ -440,7 +440,7 @@ void edit_done_menu (void) static void -edit_drop_menu_cmd (WEdit * e, int which) +edit_drop_menu_cmd (WEdit *e, int which) { if (edit_menubar->active) return; @@ -448,12 +448,9 @@ edit_drop_menu_cmd (WEdit * e, int which) edit_menubar->dropped = drop_menus; if (which >= 0) { edit_menubar->selected = which; - edit_menubar->previous_selection = which; - } else { - edit_menubar->previous_selection = - dlg_item_number (e->widget.parent); } + edit_menubar->previous_widget = e->widget.parent->current->widget; dlg_select_widget (e->widget.parent, edit_menubar); } diff --git a/src/ChangeLog b/src/ChangeLog index d2289d43e..b429c0040 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2003-09-12 Pavel Roskin + * menu.h (WMenu): Save pointer to the previous widget, not its + number. Adjust all dependencies. + * menu.c (menubar_finish): Restore focus on the saved widget. + * dlg.c (dlg_item_number): Remove, it's unused now. + (dlg_select_nth_widget): Likewise. + * help.c (interactive_display): User straight widget order. * complete.c (complete_engine): Don't need DLG_REVERSE. diff --git a/src/dlg.c b/src/dlg.c index 45d31bee0..20786cd94 100644 --- a/src/dlg.c +++ b/src/dlg.c @@ -837,34 +837,3 @@ void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new) p = p->next; } while (p != h->current); } - -/* Returns the index of h->current from h->first */ -int dlg_item_number (Dlg_head *h) -{ - Widget_Item *p; - int i = 0; - - p = h->first; - - do { - if (p == h->current) - return i; - i++; - p = p->next; - } while (p != h->first); - fprintf (stderr, "Internal error: current not in dialog list\n\r"); - exit (1); -} - -int dlg_select_nth_widget (Dlg_head *h, int n) -{ - Widget_Item *w; - int i; - - w = h->first; - for (i = 0; i < n; i++) - w = w->next; - - return dlg_select_widget (h, w->widget); -} - diff --git a/src/dlg.h b/src/dlg.h index 2bea342bf..acdf5f0e1 100644 --- a/src/dlg.h +++ b/src/dlg.h @@ -199,8 +199,6 @@ int dlg_select_widget (Dlg_head *h, void *widget); void dlg_one_up (Dlg_head *h); void dlg_one_down (Dlg_head *h); int dlg_focus (Dlg_head *h); -int dlg_select_nth_widget (Dlg_head *h, int n); -int dlg_item_number (Dlg_head *h); Widget *find_widget_type (Dlg_head *h, void *callback); /* Sets/clear the specified flag in the options field */ diff --git a/src/main.c b/src/main.c index 01652cd17..3498c65c1 100644 --- a/src/main.c +++ b/src/main.c @@ -980,7 +980,7 @@ menu_last_selected_cmd (void) { the_menubar->active = 1; the_menubar->dropped = drop_menus; - the_menubar->previous_selection = dlg_item_number (midnight_dlg); + the_menubar->previous_widget = midnight_dlg->current->widget; dlg_select_widget (midnight_dlg, the_menubar); } diff --git a/src/menu.c b/src/menu.c index 3c3552d6c..21119694c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -206,14 +206,14 @@ static void menubar_right (WMenu *menu) menubar_draw (menu); } -static void menubar_finish (WMenu *menubar) +static void +menubar_finish (WMenu *menubar) { menubar->dropped = 0; menubar->active = 0; menubar->widget.lines = 1; widget_want_hotkey (menubar->widget, 0); - dlg_select_nth_widget (menubar->widget.parent, - menubar->previous_selection); + dlg_select_widget (menubar->widget.parent, menubar->previous_widget); do_refresh (); } @@ -399,7 +399,7 @@ menubar_event (Gpm_Event *event, WMenu *menubar) return MOU_NORMAL; if (!menubar->dropped){ - menubar->previous_selection = dlg_item_number(menubar->widget.parent); + menubar->previous_widget = menubar->widget.parent->current->widget; menubar->active = 1; menubar->dropped = 1; was_active = 0; diff --git a/src/menu.h b/src/menu.h index f63426ffc..cd5b9733a 100644 --- a/src/menu.h +++ b/src/menu.h @@ -37,7 +37,7 @@ typedef struct WMenu { int selected; /* Selected menu on the top bar */ int subsel; /* Selected entry on the submenu */ int max_entry_len; /* Cache value for the columns in a box */ - int previous_selection; /* Selected widget before activating menu */ + Widget *previous_widget; /* Selected widget before activating menu */ } WMenu; Menu *create_menu (char *name, menu_entry *entries, int count,