Skip to content

Commit 6364fd0

Browse files
wyqkpyann-morin-1998
authored andcommitted
menuconfig: Add Save/Load buttons
If menuconfig have Save/Load button like alternative .config editors, xconfig, nconfig, etc.We will have a obvious benefit when use menuconfig just like when we use others, we can Save/Load our .config quickly and conveniently. This patch add the Save/Load button for menuconfig. [remove trailing space while at it for below line: "*) Formerly when I used Page Down and Page Up, the cursor would be set" ] Changes: V1-V2: 1:use PATH_MAX instead of hard code suggested by Yann E. MORIN 2:drop the spurious empty-line removal suggested by Yann E. MORIN V2-V3: 1:ajust buttons position well centered reported by Yann E. MORIN Signed-off-by: Wang YanQing <udknight@gmail.com> Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
1 parent 87727d4 commit 6364fd0

2 files changed

Lines changed: 36 additions & 14 deletions

File tree

‎scripts/kconfig/lxdialog/menubox.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* *) A bugfix for the Page-Down problem
2828
*
29-
* *) Formerly when I used Page Down and Page Up, the cursor would be set
29+
* *) Formerly when I used Page Down and Page Up, the cursor would be set
3030
* to the first position in the menu box. Now lxdialog is a bit
3131
* smarter and works more like other menu systems (just have a look at
3232
* it).
@@ -154,12 +154,14 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
154154
*/
155155
static void print_buttons(WINDOW * win, int height, int width, int selected)
156156
{
157-
int x = width / 2 - 16;
157+
int x = width / 2 - 28;
158158
int y = height - 2;
159159

160160
print_button(win, gettext("Select"), y, x, selected == 0);
161161
print_button(win, gettext(" Exit "), y, x + 12, selected == 1);
162162
print_button(win, gettext(" Help "), y, x + 24, selected == 2);
163+
print_button(win, gettext(" Save "), y, x + 36, selected == 3);
164+
print_button(win, gettext(" Load "), y, x + 48, selected == 4);
163165

164166
wmove(win, y, x + 1 + 12 * selected);
165167
wrefresh(win);
@@ -372,7 +374,7 @@ int dialog_menu(const char *title, const char *prompt,
372374
case TAB:
373375
case KEY_RIGHT:
374376
button = ((key == KEY_LEFT ? --button : ++button) < 0)
375-
? 2 : (button > 2 ? 0 : button);
377+
? 4 : (button > 4 ? 0 : button);
376378

377379
print_buttons(dialog, height, width, button);
378380
wrefresh(menu);
@@ -399,17 +401,17 @@ int dialog_menu(const char *title, const char *prompt,
399401
return 2;
400402
case 's':
401403
case 'y':
402-
return 3;
404+
return 5;
403405
case 'n':
404-
return 4;
406+
return 6;
405407
case 'm':
406-
return 5;
408+
return 7;
407409
case ' ':
408-
return 6;
410+
return 8;
409411
case '/':
410-
return 7;
412+
return 9;
411413
case 'z':
412-
return 8;
414+
return 10;
413415
case '\n':
414416
return button;
415417
}

‎scripts/kconfig/mconf.c‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ static struct menu *current_menu;
280280
static int child_count;
281281
static int single_menu_mode;
282282
static int show_all_options;
283+
static int save_and_exit;
283284

284285
static void conf(struct menu *menu, struct menu *active_menu);
285286
static void conf_choice(struct menu *menu);
@@ -657,31 +658,37 @@ static void conf(struct menu *menu, struct menu *active_menu)
657658
show_helptext(_("README"), _(mconf_readme));
658659
break;
659660
case 3:
661+
conf_save();
662+
break;
663+
case 4:
664+
conf_load();
665+
break;
666+
case 5:
660667
if (item_is_tag('t')) {
661668
if (sym_set_tristate_value(sym, yes))
662669
break;
663670
if (sym_set_tristate_value(sym, mod))
664671
show_textbox(NULL, setmod_text, 6, 74);
665672
}
666673
break;
667-
case 4:
674+
case 6:
668675
if (item_is_tag('t'))
669676
sym_set_tristate_value(sym, no);
670677
break;
671-
case 5:
678+
case 7:
672679
if (item_is_tag('t'))
673680
sym_set_tristate_value(sym, mod);
674681
break;
675-
case 6:
682+
case 8:
676683
if (item_is_tag('t'))
677684
sym_toggle_tristate_value(sym);
678685
else if (item_is_tag('m'))
679686
conf(submenu, NULL);
680687
break;
681-
case 7:
688+
case 9:
682689
search_conf();
683690
break;
684-
case 8:
691+
case 10:
685692
show_all_options = !show_all_options;
686693
break;
687694
}
@@ -708,6 +715,17 @@ static void show_helptext(const char *title, const char *text)
708715
show_textbox(title, text, 0, 0);
709716
}
710717

718+
static void conf_message_callback(const char *fmt, va_list ap)
719+
{
720+
char buf[PATH_MAX+1];
721+
722+
vsnprintf(buf, sizeof(buf), fmt, ap);
723+
if (save_and_exit)
724+
printf("%s", buf);
725+
else
726+
show_textbox(NULL, buf, 6, 60);
727+
}
728+
711729
static void show_help(struct menu *menu)
712730
{
713731
struct gstr help = str_new();
@@ -876,6 +894,7 @@ static int handle_exit(void)
876894
{
877895
int res;
878896

897+
save_and_exit = 1;
879898
dialog_clear();
880899
if (conf_get_changed())
881900
res = dialog_yesno(NULL,
@@ -947,6 +966,7 @@ int main(int ac, char **av)
947966
}
948967

949968
set_config_filename(conf_get_configname());
969+
conf_set_message_callback(conf_message_callback);
950970
do {
951971
conf(&rootmenu, NULL);
952972
res = handle_exit();

0 commit comments

Comments
 (0)