History

menuconfig: Add jump keys to search results

makes it possible to jump directly to the menu for a configuration entry after having searched for it with '/'. If this menu is not currently accessible we jump to the nearest accessible parent instead. After exiting this menu, the user is returned to the search results where he may jump further in or elsewhere.

Benjamin Poirier committed 14 years ago

Commit 5e609ad1 parent 1d1e2ca5 files · +94 −35Browse files

Unified · Split

5 files
  1. scripts/kconfig/expr.h +2 −0
  2. scripts/kconfig/lkc_proto.h +4 −2
  3. scripts/kconfig/mconf.c +43 −21
  4. scripts/kconfig/menu.c +44 −11
  5. scripts/kconfig/nconf.c +1 −1
scripts/kconfig/expr.h+2−0
@@ -173,6 +173,8 @@ struct menu { · 172 unmodified lines
173173 #define MENU_CHANGED 0x0001
174174 #define MENU_ROOT 0x0002
175175
176+#define JUMP_NB 9
177+
176178 extern struct file *file_list;
177179 extern struct file *current_file;
178180 struct file *lookup_file(const char *name);
scripts/kconfig/lkc_proto.h+4−2
@@ -21,8 +21,10 @@ P(menu_get_root_menu,struct menu *,(struct menu *menu)); · 20 unmodified lines
2121 P(menu_get_parent_menu,struct menu *,(struct menu *menu));
2222 P(menu_has_help,bool,(struct menu *menu));
2323 P(menu_get_help,const char *,(struct menu *menu));
24−P(get_symbol_str, void, (struct gstr *r, struct symbol *sym));
25−P(get_relations_str, struct gstr, (struct symbol **sym_arr));
24+P(get_symbol_str, int, (struct gstr *r, struct symbol *sym, struct menu
25+ **jumps, int jump_nb));
26+P(get_relations_str, struct gstr, (struct symbol **sym_arr, struct menu
27+ **jumps));
2628 P(menu_get_ext_help,void,(struct menu *menu, struct gstr *help));
2729
2830 /* symbol.c */
scripts/kconfig/mconf.c+43−21
@@ -236,16 +236,19 @@ search_help[] = N_( · 235 unmodified lines
236236 "Result:\n"
237237 "-----------------------------------------------------------------\n"
238238 "Symbol: FOO [=m]\n"
239+ "Type : tristate\n"
239240 "Prompt: Foo bus is used to drive the bar HW\n"
240− "Defined at drivers/pci/Kconfig:47\n"
241− "Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
242− "Location:\n"
243− " -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
244− " -> PCI support (PCI [=y])\n"
245− " -> PCI access mode (<choice> [=y])\n"
246− "Selects: LIBCRC32\n"
247− "Selected by: BAR\n"
241+ " Defined at drivers/pci/Kconfig:47\n"
242+ " Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
243+ " Location:\n"
244+ " -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
245+ " -> PCI support (PCI [=y])\n"
246+ "(1) -> PCI access mode (<choice> [=y])\n"
247+ " Selects: LIBCRC32\n"
248+ " Selected by: BAR\n"
248249 "-----------------------------------------------------------------\n"
250+ "o The line 'Type:' shows the type of the configuration option for\n"
251+ " this symbol (boolean, tristate, string, ...)\n"
249252 "o The line 'Prompt:' shows the text used in the menu structure for\n"
250253 " this symbol\n"
251254 "o The 'Defined at' line tell at what file / line number the symbol\n"
@@ -254,8 +257,12 @@ search_help[] = N_( · 2 unmodified lines
254257 " this symbol to be visible in the menu (selectable)\n"
255258 "o The 'Location:' lines tell where in the menu structure this symbol\n"
256259 " is located\n"
257− " A location followed by a [=y] indicate that this is a selectable\n"
258− " menu item - and current value is displayed inside brackets.\n"
260+ " A location followed by a [=y] indicates that this is a\n"
261+ " selectable menu item - and the current value is displayed inside\n"
262+ " brackets.\n"
263+ " Press the key in the (#) prefix to jump directly to that\n"
264+ " location. You will be returned to the current search results\n"
265+ " after exiting this new menu.\n"
259266 "o The 'Selects:' line tell what symbol will be automatically\n"
260267 " selected if this symbol is selected (y or m)\n"
261268 "o The 'Selected by' line tell what symbol has selected this symbol\n"
@@ -274,7 +281,7 @@ static int child_count; · 12 unmodified lines
274281 static int single_menu_mode;
275282 static int show_all_options;
276283
277−static void conf(struct menu *menu);
284+static void conf(struct menu *menu, struct menu *active_menu);
278285 static void conf_choice(struct menu *menu);
279286 static void conf_string(struct menu *menu);
280287 static void conf_load(void);
@@ -308,7 +315,9 @@ static void search_conf(void) · 27 unmodified lines
308315 struct symbol **sym_arr;
309316 struct gstr res;
310317 char *dialog_input;
311− int dres;
318+ int dres, vscroll = 0, hscroll = 0;
319+ bool again;
320+
312321 again:
313322 dialog_clear();
314323 dres = dialog_inputbox(_("Search Configuration Parameter"),
@@ -331,10 +340,24 @@ again: · 16 unmodified lines
331340 dialog_input += strlen(CONFIG_);
332341
333342 sym_arr = sym_re_search(dialog_input);
334− res = get_relations_str(sym_arr);
343+ do {
344+ struct menu *jumps[JUMP_NB] = {0};
345+ int keys[JUMP_NB + 1] = {0}, i;
346+
347+ res = get_relations_str(sym_arr, jumps);
348+ for (i = 0; i < JUMP_NB && jumps[i]; i++)
349+ keys[i] = '1' + i;
350+ dres = show_textbox_ext(_("Search Results"), str_get(&res), 0,
351+ 0, keys, &vscroll, &hscroll);
352+ again = false;
353+ for (i = 0; i < JUMP_NB && jumps[i]; i++)
354+ if (dres == keys[i]) {
355+ conf(jumps[i]->parent, jumps[i]);
356+ again = true;
357+ }
358+ str_free(&res);
359+ } while (again);
335360 free(sym_arr);
336− show_textbox(_("Search Results"), str_get(&res), 0, 0);
337− str_free(&res);
338361 }
339362
340363 static void build_conf(struct menu *menu)
@@ -515,12 +538,11 @@ conf_childs: · 174 unmodified lines
515538 indent -= doint;
516539 }
517540
518−static void conf(struct menu *menu)
541+static void conf(struct menu *menu, struct menu *active_menu)
519542 {
520543 struct menu *submenu;
521544 const char *prompt = menu_get_prompt(menu);
522545 struct symbol *sym;
523− struct menu *active_menu = NULL;
524546 int res;
525547 int s_scroll = 0;
526548
@@ -563,13 +585,13 @@ static void conf(struct menu *menu) · 36 unmodified lines
563585 if (single_menu_mode)
564586 submenu->data = (void *) (long) !submenu->data;
565587 else
566− conf(submenu);
588+ conf(submenu, NULL);
567589 break;
568590 case 't':
569591 if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
570592 conf_choice(submenu);
571593 else if (submenu->prompt->type == P_MENU)
572− conf(submenu);
594+ conf(submenu, NULL);
573595 break;
574596 case 's':
575597 conf_string(submenu);
@@ -608,7 +630,7 @@ static void conf(struct menu *menu) · 32 unmodified lines
608630 if (item_is_tag('t'))
609631 sym_toggle_tristate_value(sym);
610632 else if (item_is_tag('m'))
611− conf(submenu);
633+ conf(submenu, NULL);
612634 break;
613635 case 7:
614636 search_conf();
@@ -877,7 +899,7 @@ int main(int ac, char **av) · 262 unmodified lines
877899
878900 set_config_filename(conf_get_configname());
879901 do {
880− conf(&rootmenu);
902+ conf(&rootmenu, NULL);
881903 res = handle_exit();
882904 } while (res == KEY_ESC);
883905
scripts/kconfig/menu.c+44−11
@@ -507,10 +507,12 @@ const char *menu_get_help(struct menu *menu) · 506 unmodified lines
507507 return "";
508508 }
509509
510−static void get_prompt_str(struct gstr *r, struct property *prop)
510+static int get_prompt_str(struct gstr *r, struct property *prop, struct menu
511+ **jumps, int jump_nb)
511512 {
512513 int i, j;
513− struct menu *submenu[8], *menu;
514+ char header[4];
515+ struct menu *submenu[8], *menu, *location = NULL;
514516
515517 str_printf(r, _("Prompt: %s\n"), _(prop->text));
516518 str_printf(r, _(" Defined at %s:%d\n"), prop->menu->file->name,
@@ -521,13 +523,34 @@ static void get_prompt_str(struct gstr *r, struct property *prop) · 4 unmodified lines
521523 str_append(r, "\n");
522524 }
523525 menu = prop->menu->parent;
524− for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent)
526+ for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) {
527+ bool accessible = menu_is_visible(menu);
528+
525529 submenu[i++] = menu;
530+ if (location == NULL && accessible)
531+ location = menu;
532+ }
533+ if (jumps && jump_nb < JUMP_NB && location) {
534+ if (menu_is_visible(prop->menu)) {
535+ /*
536+ * There is not enough room to put the hint at the
537+ * beginning of the "Prompt" line. Put the hint on the
538+ * last "Location" line even when it would belong on
539+ * the former.
540+ */
541+ jumps[jump_nb] = prop->menu;
542+ } else
543+ jumps[jump_nb] = location;
544+ snprintf(header, 4, "(%d)", jump_nb + 1);
545+ } else
546+ location = NULL;
547+
526548 if (i > 0) {
527549 str_printf(r, _(" Location:\n"));
528− for (j = 4; --i >= 0; j += 2) {
550+ for (j = 1; --i >= 0; j += 2) {
529551 menu = submenu[i];
530− str_printf(r, "%*c-> %s", j, ' ', _(menu_get_prompt(menu)));
552+ str_printf(r, "%s%*c-> %s", menu == location ? header
553+ : " ", j, ' ', _(menu_get_prompt(menu)));
531554 if (menu->sym) {
532555 str_printf(r, " (%s [=%s])", menu->sym->name ?
533556 menu->sym->name : _("<choice>"),
@@ -536,12 +559,20 @@ static void get_prompt_str(struct gstr *r, struct property *prop) · 2 unmodified lines
536559 str_append(r, "\n");
537560 }
538561 }
562+
563+ return location ? 1 : 0;
539564 }
540565
541−void get_symbol_str(struct gstr *r, struct symbol *sym)
566+/*
567+ * jumps is optional and may be NULL
568+ * returns the number of jumps inserted
569+ */
570+int get_symbol_str(struct gstr *r, struct symbol *sym, struct menu **jumps,
571+ int jump_nb)
542572 {
543573 bool hit;
544574 struct property *prop;
575+ int i = 0;
545576
546577 if (sym && sym->name) {
547578 str_printf(r, "Symbol: %s [=%s]\n", sym->name,
@@ -557,7 +588,7 @@ void get_symbol_str(struct gstr *r, struct symbol *sym) · 9 unmodified lines
557588 }
558589 }
559590 for_all_prompts(sym, prop)
560− get_prompt_str(r, prop);
591+ i += get_prompt_str(r, prop, jumps, jump_nb + i);
561592 hit = false;
562593 for_all_properties(sym, prop, P_SELECT) {
563594 if (!hit) {
@@ -575,16 +606,18 @@ void get_symbol_str(struct gstr *r, struct symbol *sym) · 11 unmodified lines
575606 str_append(r, "\n");
576607 }
577608 str_append(r, "\n\n");
609+
610+ return i;
578611 }
579612
580−struct gstr get_relations_str(struct symbol **sym_arr)
613+struct gstr get_relations_str(struct symbol **sym_arr, struct menu **jumps)
581614 {
582615 struct symbol *sym;
583616 struct gstr res = str_new();
584− int i;
617+ int i, jump_nb = 0;
585618
586619 for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
587− get_symbol_str(&res, sym);
620+ jump_nb += get_symbol_str(&res, sym, jumps, jump_nb);
588621 if (!i)
589622 str_append(&res, _("No matches found.\n"));
590623 return res;
@@ -603,5 +636,5 @@ void menu_get_ext_help(struct menu *menu, struct gstr *help) · 12 unmodified lines
603636 }
604637 str_printf(help, "%s\n", _(help_text));
605638 if (sym)
606− get_symbol_str(help, sym);
639+ get_symbol_str(help, sym, NULL, 0);
607640 }
scripts/kconfig/nconf.c+1−1
@@ -721,7 +721,7 @@ again: · 720 unmodified lines
721721 dialog_input += strlen(CONFIG_);
722722
723723 sym_arr = sym_re_search(dialog_input);
724− res = get_relations_str(sym_arr);
724+ res = get_relations_str(sym_arr, NULL);
725725 free(sym_arr);
726726 show_scroll_win(main_window,
727727 _("Search Results"), str_get(&res));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t