diff options
author | Ettore Perazzoli <ettore@src.gnome.org> | 2001-07-01 14:13:11 +0800 |
---|---|---|
committer | Ettore Perazzoli <ettore@src.gnome.org> | 2001-07-01 14:13:11 +0800 |
commit | d1706596df85327b41dd4b4fe39dd88f4a954dae (patch) | |
tree | 5efd893363ccf27895ba9436b56fa9f0f0505a9a | |
parent | d801d2df671bea7e08711f0027fbf8f3dc873b01 (diff) | |
download | gsoc2013-evolution-d1706596df85327b41dd4b4fe39dd88f4a954dae.tar.gz gsoc2013-evolution-d1706596df85327b41dd4b4fe39dd88f4a954dae.tar.zst gsoc2013-evolution-d1706596df85327b41dd4b4fe39dd88f4a954dae.zip |
Added a simple `e_request_string()' utility function.
svn path=/trunk/; revision=10650
-rw-r--r-- | e-util/ChangeLog | 5 | ||||
-rw-r--r-- | e-util/Makefile.am | 2 | ||||
-rw-r--r-- | e-util/e-request.c | 104 | ||||
-rw-r--r-- | e-util/e-request.h | 34 |
4 files changed, 145 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index bf42704386..5b4627448e 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,8 @@ +2001-07-01 Ettore Perazzoli <ettore@ximian.com> + + * e-request.c: New. + * e-request.h: New. + 2001-06-25 Jeffrey Stedfast <fejj@ximian.com> * e-sexp.c (term_eval_and): When ANDing two bools, don't use a diff --git a/e-util/Makefile.am b/e-util/Makefile.am index b4d20054da..390b2507a4 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -40,6 +40,8 @@ libeutil_la_SOURCES = \ e-msgport.h \ e-path.c \ e-path.h \ + e-request.c \ + e-request.h \ e-sexp.c \ e-sexp.h \ e-time-utils.c \ diff --git a/e-util/e-request.c b/e-util/e-request.c new file mode 100644 index 0000000000..410aaa7365 --- /dev/null +++ b/e-util/e-request.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-request.c + * + * Copyright (C) 2000, 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "e-request.h" + +#include <libgnomeui/gnome-dialog.h> +#include <libgnomeui/gnome-stock.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkentry.h> + + +/** + * e_request_string: + * @parent: + * @title: + * @prompt: + * @default: + * + * Requst a string to the user. + * + * Return value: NULL if the user cancelled the dialog, the inserted string + * otherwise. The string must be freed by the caller. + **/ +char * +e_request_string (GtkWindow *parent, + const char *title, + const char *prompt, + const char *default_string) +{ + GtkWidget *dialog; + GtkWidget *prompt_label; + GtkWidget *entry; + GtkWidget *vbox; + char *retval; + + g_return_val_if_fail (title != NULL, NULL); + g_return_val_if_fail (prompt != NULL, NULL); + + dialog = gnome_dialog_new (title, GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); + gnome_dialog_set_parent (GNOME_DIALOG (dialog), parent); + gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); + gnome_dialog_close_hides (GNOME_DIALOG (dialog), TRUE); + + vbox = GNOME_DIALOG (dialog)->vbox; + + prompt_label = gtk_label_new (prompt); + gtk_box_pack_start (GTK_BOX (vbox), prompt_label, TRUE, TRUE, 0); + + entry = gtk_entry_new (); + gtk_entry_set_text (GTK_ENTRY (entry), default_string); + gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); + gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0); + + gtk_widget_grab_focus (entry); + gnome_dialog_editable_enters (GNOME_DIALOG (dialog), GTK_EDITABLE (entry)); + + gtk_widget_show (prompt_label); + gtk_widget_show (entry); + gtk_widget_show (dialog); + + switch (gnome_dialog_run (GNOME_DIALOG (dialog))) { + case 0: + /* OK. */ + retval = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); + break; + case -1: + case 1: + /* Cancel. */ + retval = NULL; + break; + default: + g_assert_not_reached (); + retval = NULL; + } + + gtk_widget_destroy (dialog); + + return retval; +} diff --git a/e-util/e-request.h b/e-util/e-request.h new file mode 100644 index 0000000000..f4404b83d5 --- /dev/null +++ b/e-util/e-request.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-request.c + * + * Copyright (C) 2000, 2001 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef E_REQUEST_H +#define E_REQUEST_H + +#include <gtk/gtkwindow.h> + +char *e_request_string (GtkWindow *parent, + const char *title, + const char *prompt, + const char *default_string); + +#endif |