]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
- provide option to change text of buttons (#126768)
authormlichvar <mlichvar>
Wed, 31 Jan 2007 13:46:03 +0000 (13:46 +0000)
committermlichvar <mlichvar>
Wed, 31 Jan 2007 13:46:03 +0000 (13:46 +0000)
dialogboxes.c
dialogboxes.h
whiptail.c

index a86361a89f52a8187e30779eda39ef28cb8428ce..93adc58f55e4094f03745de81ecaa2627a42b657 100644 (file)
 
 #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;
+}
index b1824640f305967f1f1ed310dc310018e234d5a4..6d133e161544405734c2fc5c7ed759bedae355db 100644 (file)
 #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
index b036170cc11081fdce668059ee9f53825b0d380c..449f99498ea6a353e1c41dcafced881a3c660a61 100644 (file)
@@ -52,6 +52,10 @@ static void usage(int err) {
               "\t--default-item <string>               set default string\n"
               "\t--fb                          use full buttons\n"
               "\t--nocancel                    no cancel button\n"
+              "\t--yes-button <text>           set text of yes button\n"
+              "\t--no-button <text>            set text of no button\n"
+              "\t--ok-button <text>            set text of ok button\n"
+              "\t--cancel-button <text>                set text of cancel button\n"
               "\t--noitem                      display tags only\n"
               "\t--separate-output <fd>                output one line at a time\n"
               "\t--output-fd <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;