Support user-defined return values via env vars, like dialog did.
This commit is contained in:
parent
3aab6a19a5
commit
5bade6fe6a
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
2003-06-07 Mike Newman <mikegtn@gnome.org>
|
||||||
|
|
||||||
|
* src/calendar.c: Allow user-defined return values via env vars
|
||||||
|
* src/entry.c: Prefer ZENITY_OK etc, but also check for DIALOG_OK
|
||||||
|
* src/fileselection.c: and fall through to original zenity behaviour.
|
||||||
|
* src/msg.c:
|
||||||
|
* src/progress.c:
|
||||||
|
* src/text.c:
|
||||||
|
* src/tree.c:
|
||||||
|
* src/util.c:
|
||||||
|
* src/util.h:
|
||||||
|
* src/zenity.h:
|
||||||
|
|
||||||
2003-06-07 Glynn Foster <glynn.foster@sun.com>
|
2003-06-07 Glynn Foster <glynn.foster@sun.com>
|
||||||
|
|
||||||
* src/zenity.glade: Untranslate silly strings pointed out by
|
* src/zenity.glade: Untranslate silly strings pointed out by
|
||||||
|
@ -257,7 +257,7 @@ zenity_about (ZenityData *data)
|
|||||||
glade_dialog = zenity_util_load_glade_file ("zenity_about_dialog");
|
glade_dialog = zenity_util_load_glade_file ("zenity_about_dialog");
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
/* Esc dialog */
|
/* Esc dialog */
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
|
|||||||
glade_dialog = zenity_util_load_glade_file ("zenity_calendar_dialog");
|
glade_dialog = zenity_util_load_glade_file ("zenity_calendar_dialog");
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,18 +105,18 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
if (date != NULL)
|
if (date != NULL)
|
||||||
g_date_free (date);
|
g_date_free (date);
|
||||||
|
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Esc dialog */
|
/* Esc dialog */
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
|
|||||||
glade_dialog = zenity_util_load_glade_file ("zenity_entry_dialog");
|
glade_dialog = zenity_util_load_glade_file ("zenity_entry_dialog");
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
||||||
|
|
||||||
if (text != NULL)
|
if (text != NULL)
|
||||||
@ -101,13 +101,13 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Esc dialog */
|
/* Esc dialog */
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
|||||||
glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog");
|
glade_dialog = zenity_util_load_glade_file ("zenity_fileselection_dialog");
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,19 +73,20 @@ zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer
|
|||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code
|
||||||
|
(ZENITY_OK);
|
||||||
g_printerr ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)));
|
g_printerr ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (widget)));
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Esc dialog */
|
/* Esc dialog */
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
G_CALLBACK (zenity_msg_dialog_response), data);
|
G_CALLBACK (zenity_msg_dialog_response), data);
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,12 +124,12 @@ zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE);
|
gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE);
|
||||||
gtk_widget_grab_focus(GTK_WIDGET (button));
|
gtk_widget_grab_focus(GTK_WIDGET (button));
|
||||||
if (progress_data->autoclose) {
|
if (progress_data->autoclose) {
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
|
|||||||
glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog");
|
glade_dialog = zenity_util_load_glade_file ("zenity_progress_dialog");
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
{
|
{
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -228,13 +228,13 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
* stuff. Should be using SIGHUP instead of 1 though.
|
* stuff. Should be using SIGHUP instead of 1 though.
|
||||||
*/
|
*/
|
||||||
kill (getpid (), 1);
|
kill (getpid (), 1);
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Esc dialog */
|
/* Esc dialog */
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
|
|||||||
glade_dialog = zenity_util_load_glade_file ("zenity_text_dialog");
|
glade_dialog = zenity_util_load_glade_file ("zenity_text_dialog");
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,13 +95,13 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
|
gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
|
||||||
g_printerr (gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0));
|
g_printerr (gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0));
|
||||||
}
|
}
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Esc dialog */
|
/* Esc dialog */
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/tree.c
10
src/tree.c
@ -279,7 +279,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog");
|
glade_dialog = zenity_util_load_glade_file ("zenity_tree_dialog");
|
||||||
|
|
||||||
if (glade_dialog == NULL) {
|
if (glade_dialog == NULL) {
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
|
|
||||||
if (n_columns == 0) {
|
if (n_columns == 0) {
|
||||||
g_printerr (_("No column titles specified for List dialog.\n"));
|
g_printerr (_("No column titles specified for List dialog.\n"));
|
||||||
data->exit_code = -1;
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,18 +517,18 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
GTK_TREE_VIEW (tree_view));
|
GTK_TREE_VIEW (tree_view));
|
||||||
}
|
}
|
||||||
zenity_tree_dialog_output ();
|
zenity_tree_dialog_output ();
|
||||||
zen_data->exit_code = 0;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Esc dialog */
|
/* Esc dialog */
|
||||||
zen_data->exit_code = 1;
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
64
src/util.c
64
src/util.c
@ -39,6 +39,12 @@
|
|||||||
#define URL_HANDLER_DIR "/desktop/gnome/url-handlers/"
|
#define URL_HANDLER_DIR "/desktop/gnome/url-handlers/"
|
||||||
#define DEFAULT_HANDLER_PATH "/desktop/gnome/url-handlers/unknown/command"
|
#define DEFAULT_HANDLER_PATH "/desktop/gnome/url-handlers/unknown/command"
|
||||||
|
|
||||||
|
#define ZENITY_OK_DEFAULT 0
|
||||||
|
#define ZENITY_CANCEL_DEFAULT 1
|
||||||
|
#define ZENITY_ESC_DEFAULT 1
|
||||||
|
#define ZENITY_ERROR_DEFAULT -1
|
||||||
|
#define ZENITY_EXTRA_DEFAULT 127
|
||||||
|
|
||||||
GladeXML*
|
GladeXML*
|
||||||
zenity_util_load_glade_file (const gchar *widget_root)
|
zenity_util_load_glade_file (const gchar *widget_root)
|
||||||
{
|
{
|
||||||
@ -592,3 +598,61 @@ zenity_util_show_help (const gchar *path, const gchar *document, GError **error)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
zenity_util_return_exit_code ( ZenityExitCode value )
|
||||||
|
{
|
||||||
|
|
||||||
|
const gchar *env_var = NULL;
|
||||||
|
gint retval;
|
||||||
|
|
||||||
|
switch (value) {
|
||||||
|
|
||||||
|
case ZENITY_OK:
|
||||||
|
env_var = g_getenv("ZENITY_OK");
|
||||||
|
if (! env_var)
|
||||||
|
env_var = g_getenv("DIALOG_OK");
|
||||||
|
if (! env_var)
|
||||||
|
retval = ZENITY_OK_DEFAULT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ZENITY_CANCEL:
|
||||||
|
env_var = g_getenv("ZENITY_CANCEL");
|
||||||
|
if (! env_var)
|
||||||
|
env_var = g_getenv("DIALOG_CANCEL");
|
||||||
|
if (! env_var)
|
||||||
|
retval = ZENITY_CANCEL_DEFAULT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ZENITY_ESC:
|
||||||
|
env_var = g_getenv("ZENITY_ESC");
|
||||||
|
if (! env_var)
|
||||||
|
env_var = g_getenv("DIALOG_ESC");
|
||||||
|
if (! env_var)
|
||||||
|
retval = ZENITY_ESC_DEFAULT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ZENITY_EXTRA:
|
||||||
|
env_var = g_getenv("ZENITY_EXTRA");
|
||||||
|
if (! env_var)
|
||||||
|
env_var = g_getenv("DIALOG_EXTRA");
|
||||||
|
if (! env_var)
|
||||||
|
retval = ZENITY_EXTRA_DEFAULT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ZENITY_ERROR:
|
||||||
|
env_var = g_getenv("ZENITY_ERROR");
|
||||||
|
if (! env_var)
|
||||||
|
env_var = g_getenv("DIALOG_ERROR");
|
||||||
|
if (! env_var)
|
||||||
|
retval = ZENITY_ERROR_DEFAULT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
retval = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (env_var)
|
||||||
|
retval = atoi (env_var);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <glade/glade.h>
|
#include <glade/glade.h>
|
||||||
|
#include "zenity.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ void zenity_util_set_window_icon_from_stock (GtkWidget *widge
|
|||||||
gboolean zenity_util_show_help (const gchar *path,
|
gboolean zenity_util_show_help (const gchar *path,
|
||||||
const gchar *document,
|
const gchar *document,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
gint zenity_util_return_exit_code (ZenityExitCode value);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* UTIL_H */
|
#endif /* UTIL_H */
|
||||||
|
@ -31,6 +31,14 @@ typedef struct {
|
|||||||
gint exit_code;
|
gint exit_code;
|
||||||
} ZenityData;
|
} ZenityData;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ZENITY_OK,
|
||||||
|
ZENITY_CANCEL,
|
||||||
|
ZENITY_ESC,
|
||||||
|
ZENITY_ERROR,
|
||||||
|
ZENITY_EXTRA
|
||||||
|
} ZenityExitCode;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
gchar *dialog_text;
|
gchar *dialog_text;
|
||||||
gint day;
|
gint day;
|
||||||
|
Reference in New Issue
Block a user