From: mlichvar Date: Wed, 31 Jan 2007 13:46:03 +0000 (+0000) Subject: - provide option to change text of buttons (#126768) X-Git-Tag: r0-52-5~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60d3c50bddbffb19feaa5bc376d71798f208432a;p=thirdparty%2Fnewt.git - provide option to change text of buttons (#126768) --- diff --git a/dialogboxes.c b/dialogboxes.c index a86361a..93adc58 100644 --- a/dialogboxes.c +++ b/dialogboxes.c @@ -17,9 +17,11 @@ #define MAXBUF 200 #define MAXFORMAT 20 +#define BUTTONS 4 /* globals -- ick */ static int buttonHeight = 1; +static const char * buttonText[BUTTONS]; int max (int a, int b) { @@ -34,21 +36,45 @@ int min (int a, int b) static newtComponent (*makeButton)(int left, int right, const char * text) = newtCompactButton; +static const char * getButtonText(int button) { + const char * text; + if (button < 0 || button >= BUTTONS) + return NULL; + + text = buttonText[button]; + if (text) + return text; + + switch (button) { + case 0: text = "Ok"; + break; + case 1: text = "Cancel"; + break; + case 2: text = "Yes"; + break; + case 3: text = "No"; + break; + default: + return NULL; + } + return dgettext(PACKAGE, text); +} + static void addButtons(int height, int width, newtComponent form, newtComponent * okay, newtComponent * cancel, int flags) { // FIXME: DO SOMETHING ABOUT THE HARD-CODED CONSTANTS if (flags & FLAG_NOCANCEL) { *okay = makeButton((width - 8) / 2, height - buttonHeight - 1, - dgettext(PACKAGE, "Ok")); + getButtonText(BUTTON_OK)); *cancel = NULL; newtFormAddComponent(form, *okay); } else { *okay = makeButton((width - 18) / 3, height - buttonHeight - 1, - dgettext(PACKAGE,"Ok")); + getButtonText(BUTTON_OK)); *cancel = makeButton(((width - 18) / 3) * 2 + 9, height - buttonHeight - 1, - dgettext(PACKAGE,"Cancel")); + getButtonText(BUTTON_CANCEL)); newtFormAddComponents(form, *okay, *cancel, NULL); } } @@ -491,14 +517,14 @@ int messageBox(const char * text, int height, int width, int type, int flags) { case MSGBOX_MSG: // FIXME Do something about the hard-coded constants yes = makeButton((width - 8) / 2, height - 1 - buttonHeight, - dgettext(PACKAGE,"Ok")); + getButtonText(BUTTON_OK)); newtFormAddComponent(form, yes); break; default: yes = makeButton((width - 16) / 3, height - 1 - buttonHeight, - dgettext(PACKAGE,"Yes")); + getButtonText(BUTTON_YES)); no = makeButton(((width - 16) / 3) * 2 + 9, height - 1 - buttonHeight, - dgettext(PACKAGE,"No")); + getButtonText(BUTTON_NO)); newtFormAddComponents(form, yes, no, NULL); if (flags & FLAG_DEFAULT_NO) @@ -533,3 +559,9 @@ void useFullButtons(int state) { makeButton = newtCompactButton; } } + +void setButtonText(const char * text, int button) { + if (button < 0 || button >= BUTTONS) + return; + buttonText[button] = text; +} diff --git a/dialogboxes.h b/dialogboxes.h index b182464..6d133e1 100644 --- a/dialogboxes.h +++ b/dialogboxes.h @@ -19,6 +19,11 @@ #define DLG_CANCEL 1 #define DLG_ESCAPE 2 +#define BUTTON_OK 0 +#define BUTTON_CANCEL 1 +#define BUTTON_YES 2 +#define BUTTON_NO 3 + int min(int a, int b); int max(int a, int b); @@ -32,5 +37,6 @@ int inputBox(const char * text, int height, int width, poptContext optCon, int gauge(const char * text, int height, int width, poptContext optCon, int fd, int flags); void useFullButtons(int state); +void setButtonText(const char * text, int button); #endif diff --git a/whiptail.c b/whiptail.c index b036170..449f994 100644 --- a/whiptail.c +++ b/whiptail.c @@ -52,6 +52,10 @@ static void usage(int err) { "\t--default-item set default string\n" "\t--fb use full buttons\n" "\t--nocancel no cancel button\n" + "\t--yes-button set text of yes button\n" + "\t--no-button set text of no button\n" + "\t--ok-button set text of ok button\n" + "\t--cancel-button set text of cancel button\n" "\t--noitem display tags only\n" "\t--separate-output output one line at a time\n" "\t--output-fd output to fd, not stdout\n" @@ -347,6 +351,10 @@ int main(int argc, const char ** argv) { char * title = NULL; char *default_item = NULL; char * backtitle = NULL; + char * yes_button = NULL; + char * no_button = NULL; + char * ok_button = NULL; + char * cancel_button = NULL; int help = 0, version = 0; struct poptOption optionsTable[] = { { "backtitle", '\0', POPT_ARG_STRING, &backtitle, 0 }, @@ -373,6 +381,10 @@ int main(int argc, const char ** argv) { { "yesno", '\0', 0, 0, OPT_YESNO }, { "passwordbox", '\0', 0, 0, OPT_PASSWORDBOX }, { "output-fd", '\0', POPT_ARG_INT, &outputfd, 0 }, + { "yes-button", '\0', POPT_ARG_STRING, &yes_button, 0}, + { "no-button", '\0', POPT_ARG_STRING, &no_button, 0}, + { "ok-button", '\0', POPT_ARG_STRING, &ok_button, 0}, + { "cancel-button", '\0', POPT_ARG_STRING, &cancel_button, 0}, { "help", 'h', 0, &help, 0, NULL, NULL }, { "version", 'v', 0, &version, 0, NULL, NULL }, { 0, 0, 0, 0, 0 } @@ -509,6 +521,15 @@ int main(int argc, const char ** argv) { if (backtitle) newtDrawRootText(0, 0, backtitle); + if (ok_button) + setButtonText(ok_button, BUTTON_OK); + if (cancel_button) + setButtonText(cancel_button, BUTTON_CANCEL); + if (yes_button) + setButtonText(yes_button, BUTTON_YES); + if (no_button) + setButtonText(no_button, BUTTON_NO); + if (noCancel) flags |= FLAG_NOCANCEL; if (noItem) flags |= FLAG_NOITEM; if (noTags) flags |= FLAG_NOTAGS;