Commit d1d9dec7 authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

remove gedit_button_new_with_stock_image since eel has an analougus

2003-01-02  Paolo Borelli  <pborelli@katamail.com>

	* gedit-utils.[ch]: remove gedit_button_new_with_stock_image
	since eel has an analougus function, modify gedit_warning to
	take a format, define common error strings MISSING_FILE and
	MISSING_WIDGETS.

	* dialogs/gedit-dialog-goto-line.c: remove separator and use
	gedit_warning and gedit_dialogs_add_button where appropriate.

	* dialogs/gedit-dialog-replace.c: ditto.

	* dialogs/gedit-dialog-uri.c: ditto.

	* dialogs/gedit-page-setup-dialog.c: ditto.

	* dialogs/gedit-plugin-program-location-dialog.c: ditto.

	* dialogs/gedit-preferences-dialog: fix the use of gedit_warning.

	* plugins/time/time.c: ditto.
parent 1345eafd
2003-01-02 Paolo Borelli <pborelli@katamail.com>
* gedit-utils.[ch]: remove gedit_button_new_with_stock_image
since eel has an analougus function, modify gedit_warning to
take a format, define common error strings MISSING_FILE and
MISSING_WIDGETS.
* dialogs/gedit-dialog-goto-line.c: remove separator and use
gedit_warning and gedit_dialogs_add_button where appropriate.
* dialogs/gedit-dialog-replace.c: ditto.
* dialogs/gedit-dialog-uri.c: ditto.
* dialogs/gedit-page-setup-dialog.c: ditto.
* dialogs/gedit-plugin-program-location-dialog.c: ditto.
* dialogs/gedit-preferences-dialog: fix the use of gedit_warning.
* plugins/time/time.c: ditto.
2003-01-02 Paolo Maggi <paolo.maggi@polito.it>
* gedit-document.[ch]: new function
......
......@@ -131,30 +131,30 @@ dialog_goto_line_get_dialog (void)
GladeXML *gui;
GtkWindow *window;
GtkWidget *content;
GtkWidget *button;
gedit_debug (DEBUG_SEARCH, "");
window = GTK_WINDOW (gedit_get_active_window ());
if (dialog != NULL)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW (window));
gtk_window_present (GTK_WINDOW (dialog->dialog));
gtk_widget_grab_focus (dialog->dialog);
return dialog;
}
gui = glade_xml_new (GEDIT_GLADEDIR "goto-line.glade2",
"goto_line_dialog_content", NULL);
if (!gui) {
g_warning
("Could not find goto-line.glade2, reinstall gedit.\n");
if (!gui)
{
gedit_warning (window,
MISSING_FILE,
GEDIT_GLADEDIR "goto-line.glade2");
return NULL;
}
window = GTK_WINDOW (bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi)));
dialog = g_new0 (GeditDialogGotoLine, 1);
dialog->dialog = gtk_dialog_new_with_buttons (_("Go to Line"),
......@@ -166,35 +166,32 @@ dialog_goto_line_get_dialog (void)
g_return_val_if_fail (dialog->dialog != NULL, NULL);
/* Add Goto Line button */
button = gedit_button_new_with_stock_image (_("_Go to Line"), GTK_STOCK_JUMP_TO);
g_return_val_if_fail (button != NULL, NULL);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
gtk_dialog_set_has_separator (GTK_DIALOG (dialog->dialog), FALSE);
gtk_widget_show (button);
gedit_dialog_add_button (GTK_DIALOG (dialog->dialog),
_("_Go to Line"), GTK_STOCK_JUMP_TO,
GTK_RESPONSE_OK);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog->dialog),
button, GTK_RESPONSE_OK);
content = glade_xml_get_widget (gui, "goto_line_dialog_content");
dialog->entry = glade_xml_get_widget (gui, "entry");
if (!dialog->entry) {
g_warning (
_("Could not find the required widgets inside %s."),
"goto-line.glade2");
if (!dialog->entry)
{
gedit_warning (window,
MISSING_WIDGETS,
GEDIT_GLADEDIR "goto-line.glade2");
g_object_unref (gui);
g_free (dialog);
return NULL;
}
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->dialog)->vbox),
content, FALSE, FALSE, 0);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->dialog),
GTK_RESPONSE_OK, FALSE);
GTK_RESPONSE_OK, FALSE);
gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
GTK_RESPONSE_OK);
......@@ -213,12 +210,9 @@ dialog_goto_line_get_dialog (void)
g_object_unref (gui);
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
return dialog;
}
void
gedit_dialog_goto_line (void)
{
......@@ -227,15 +221,8 @@ gedit_dialog_goto_line (void)
gedit_debug (DEBUG_SEARCH, "");
dialog = dialog_goto_line_get_dialog ();
if (dialog == NULL) {
g_warning ("Could not create the Goto Line dialog");
if (!dialog)
return;
}
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW
(bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi))));
gtk_widget_grab_focus (dialog->entry);
......
......@@ -138,6 +138,7 @@ text_not_found_dialog (const gchar *text, GtkWindow *parent)
gtk_dialog_set_default_response (GTK_DIALOG (message_dlg), GTK_RESPONSE_OK);
gtk_window_set_resizable (GTK_WINDOW (message_dlg), FALSE);
gtk_dialog_set_has_separator (GTK_DIALOG (message_dlg), FALSE);
gtk_dialog_run (GTK_DIALOG (message_dlg));
gtk_widget_destroy (message_dlg);
......@@ -238,13 +239,16 @@ dialog_replace_get_dialog (void)
GladeXML *gui;
GtkWindow *window;
GtkWidget *content;
GtkWidget *button;
GtkWidget *replace_with_label;
gedit_debug (DEBUG_SEARCH, "");
window = GTK_WINDOW (gedit_get_active_window ());
if (dialog != NULL)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW (window));
gtk_window_present (GTK_WINDOW (dialog->dialog));
gtk_widget_grab_focus (dialog->dialog);
......@@ -253,16 +257,14 @@ dialog_replace_get_dialog (void)
gui = glade_xml_new ( GEDIT_GLADEDIR "replace.glade2",
"replace_dialog_content", NULL);
if (!gui) {
g_warning
("Could not find replace.glade2, reinstall gedit.\n");
if (!gui)
{
gedit_warning (window,
MISSING_FILE,
GEDIT_GLADEDIR "replace.glade2");
return NULL;
}
window = GTK_WINDOW (bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi)));
dialog = g_new0 (GeditDialogReplace, 1);
dialog->dialog = gtk_dialog_new_with_buttons (_("Replace"),
......@@ -274,22 +276,16 @@ dialog_replace_get_dialog (void)
g_return_val_if_fail (dialog->dialog != NULL, NULL);
/* Add Replace All button */
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
gtk_dialog_set_has_separator (GTK_DIALOG (dialog->dialog), FALSE);
gtk_dialog_add_button (GTK_DIALOG (dialog->dialog),
_("Replace _All"), GEDIT_RESPONSE_REPLACE_ALL);
/* Add Replace button */
button = gedit_button_new_with_stock_image (_("_Replace"), GTK_STOCK_FIND_AND_REPLACE);
g_return_val_if_fail (button != NULL, NULL);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_show (button);
gedit_dialog_add_button (GTK_DIALOG (dialog->dialog),
_("_Replace"), GTK_STOCK_FIND_AND_REPLACE,
GEDIT_RESPONSE_REPLACE);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog->dialog),
button, GEDIT_RESPONSE_REPLACE);
/* Add Find button */
gtk_dialog_add_button (GTK_DIALOG (dialog->dialog),
GTK_STOCK_FIND, GEDIT_RESPONSE_FIND);
......@@ -315,8 +311,9 @@ dialog_replace_get_dialog (void)
!dialog->wrap_around_checkbutton ||
!dialog->search_backwards_checkbutton)
{
g_print
("Could not find the required widgets inside replace.glade2.\n");
gedit_warning (window,
MISSING_WIDGETS,
GEDIT_GLADEDIR "replace.glade2");
return NULL;
}
......@@ -347,8 +344,6 @@ dialog_replace_get_dialog (void)
g_object_unref (G_OBJECT (gui));
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
return dialog;
}
......@@ -381,8 +376,12 @@ dialog_find_get_dialog (void)
gedit_debug (DEBUG_SEARCH, "");
window = GTK_WINDOW (gedit_get_active_window ());
if (dialog != NULL)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW (window));
gtk_window_present (GTK_WINDOW (dialog->dialog));
gtk_widget_grab_focus (dialog->dialog);
......@@ -391,16 +390,14 @@ dialog_find_get_dialog (void)
gui = glade_xml_new (GEDIT_GLADEDIR "replace.glade2",
"replace_dialog_content", NULL);
if (!gui) {
g_warning
("Could not find replace.glade2, reinstall gedit.\n");
if (!gui)
{
gedit_warning (window,
MISSING_FILE,
GEDIT_GLADEDIR "replace.glade2");
return NULL;
}
window = GTK_WINDOW (bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi)));
dialog = g_new0 (GeditDialogFind, 1);
dialog->dialog = gtk_dialog_new_with_buttons (_("Find"),
......@@ -414,6 +411,9 @@ dialog_find_get_dialog (void)
g_return_val_if_fail (dialog->dialog != NULL, NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
gtk_dialog_set_has_separator (GTK_DIALOG (dialog->dialog), FALSE);
content = glade_xml_get_widget (gui, "replace_dialog_content");
dialog->search_entry = glade_xml_get_widget (gui, "search_for_text_entry");
......@@ -440,11 +440,12 @@ dialog_find_get_dialog (void)
!dialog->wrap_around_checkbutton ||
!dialog->search_backwards_checkbutton)
{
g_print
("Could not find the required widgets inside replace.glade2.\n");
gedit_warning (window,
MISSING_WIDGETS,
GEDIT_GLADEDIR "replace.glade2");
return NULL;
}
gtk_widget_hide (replace_with_label);
gtk_widget_hide (replace_entry);
......@@ -470,8 +471,6 @@ dialog_find_get_dialog (void)
g_object_unref (G_OBJECT (gui));
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
return dialog;
}
......@@ -557,7 +556,6 @@ insert_text_handler (GtkEditable *editable, const gchar *text, gint length, gint
g_free (escaped_text);
}
void
gedit_dialog_find (void)
{
......@@ -576,21 +574,14 @@ gedit_dialog_find (void)
gedit_debug (DEBUG_SEARCH, "");
dialog = dialog_find_get_dialog ();
if (dialog == NULL) {
g_warning ("Cannot create the Find dialog");
if (!dialog)
return;
}
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW
(bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi))));
if (GTK_WIDGET_VISIBLE (dialog->dialog))
return;
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->dialog),
GEDIT_RESPONSE_FIND, FALSE);
GEDIT_RESPONSE_FIND, FALSE);
active_child = GEDIT_MDI_CHILD (bonobo_mdi_get_active_child (BONOBO_MDI (gedit_mdi)));
g_return_if_fail (active_child != NULL);
......@@ -666,8 +657,7 @@ gedit_dialog_find (void)
gtk_widget_grab_focus (dialog->search_entry);
if (!GTK_WIDGET_VISIBLE (dialog->dialog))
gtk_widget_show (dialog->dialog);
gtk_widget_show (dialog->dialog);
}
void
......@@ -689,15 +679,8 @@ gedit_dialog_replace (void)
gedit_debug (DEBUG_SEARCH, "");
dialog = dialog_replace_get_dialog ();
if (dialog == NULL) {
g_warning ("Cannot create the Replace dialog");
if (!dialog)
return;
}
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW
(bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi))));
if (GTK_WIDGET_VISIBLE (dialog->dialog))
return;
......@@ -789,9 +772,8 @@ gedit_dialog_replace (void)
was_search_backwards);
gtk_widget_grab_focus (dialog->search_entry);
if (!GTK_WIDGET_VISIBLE (dialog->dialog))
gtk_widget_show (dialog->dialog);
gtk_widget_show (dialog->dialog);
}
static void
......@@ -1072,7 +1054,6 @@ replace_dlg_replace_button_pressed (GeditDialogReplace *dialog)
gedit_debug (DEBUG_SEARCH, "END");
}
static void
replace_dlg_replace_all_button_pressed (GeditDialogReplace *dialog)
{
......
......@@ -67,21 +67,25 @@ dialog_open_uri_get_dialog (void)
GtkWidget *encoding_label;
GtkWidget *encoding_hbox;
window = GTK_WINDOW (gedit_get_active_window ());
if (dialog != NULL)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW (window));
return dialog;
}
gui = glade_xml_new (GEDIT_GLADEDIR "uri.glade2",
"open_uri_dialog_content", NULL);
if (!gui) {
g_warning
("Could not find uri.glade2, reinstall gedit.\n");
if (!gui)
{
gedit_warning (window,
MISSING_FILE,
GEDIT_GLADEDIR "uri.glade2");
return NULL;
}
window = GTK_WINDOW (bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi)));
dialog = g_new0 (GeditDialogOpenUri, 1);
dialog->dialog = gtk_dialog_new_with_buttons (_("Open Location"),
......@@ -97,6 +101,9 @@ dialog_open_uri_get_dialog (void)
g_return_val_if_fail (dialog->dialog != NULL, NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
gtk_dialog_set_has_separator (GTK_DIALOG (dialog->dialog), FALSE);
content = glade_xml_get_widget (gui, "open_uri_dialog_content");
dialog->uri = glade_xml_get_widget (gui, "uri");
......@@ -106,7 +113,9 @@ dialog_open_uri_get_dialog (void)
if (!dialog->uri || !dialog->uri_list || !encoding_label || !encoding_hbox)
{
g_print ("Could not find the required widgets inside uri.glade.\n");
gedit_warning (window,
MISSING_WIDGETS,
GEDIT_GLADEDIR "uri.glade2");
return NULL;
}
......@@ -131,12 +140,9 @@ dialog_open_uri_get_dialog (void)
g_object_unref (gui);
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
return dialog;
}
void
gedit_dialog_open_uri (void)
{
......@@ -144,10 +150,8 @@ gedit_dialog_open_uri (void)
gint response;
dialog = dialog_open_uri_get_dialog ();
if (dialog == NULL) {
g_warning ("Could not create the Open URI dialog");
if (!dialog)
return;
}
gedit_encodings_option_menu_set_selected_encoding (
GEDIT_ENCODINGS_OPTION_MENU (dialog->encoding_menu),
......@@ -155,11 +159,6 @@ gedit_dialog_open_uri (void)
gtk_widget_grab_focus (dialog->uri);
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW
(bonobo_mdi_get_active_window
(BONOBO_MDI (gedit_mdi))));
gtk_entry_set_text (GTK_ENTRY (dialog->uri), "");
do {
......
......@@ -106,7 +106,6 @@ dialog_response_handler (GtkDialog *dlg, gint res_id, GeditPageSetupDialog *dia
}
}
static void
syntax_checkbutton_toggled (GtkToggleButton *button, GeditPageSetupDialog *dlg)
{
......@@ -561,7 +560,7 @@ setup_font_page (GeditPageSetupDialog *dlg)
}
static GeditPageSetupDialog *
get_page_setup_dialog (GtkWindow *parent)
page_setup_get_dialog (GtkWindow *parent)
{
static GeditPageSetupDialog *dialog = NULL;
GladeXML *gui;
......@@ -570,31 +569,20 @@ get_page_setup_dialog (GtkWindow *parent)
if (dialog != NULL)
{
gtk_window_present (GTK_WINDOW (dialog->dialog));
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
parent);
gtk_window_present (GTK_WINDOW (dialog->dialog));
return dialog;
}
gui = glade_xml_new (GEDIT_GLADEDIR "page-setup-dialog.glade2",
"dialog", NULL);
if (!gui)
{
gchar *tmp;
/* Translators: %s is a file path */
tmp = g_strdup_printf (
_("Could not find '%s'.\n\nPlease, reinstall gedit"),
GEDIT_GLADEDIR "page-setup-dialog.glade2");
gedit_warning (tmp, parent);
g_free (tmp);
gedit_warning (parent,
MISSING_FILE,
GEDIT_GLADEDIR "page-setup-dialog.glade2");
return NULL;
}
......@@ -634,17 +622,9 @@ get_page_setup_dialog (GtkWindow *parent)
!dialog->numbers_font_label ||
!dialog->restore_button)
{
gchar *tmp;
/* Translators: %s is a file path */
tmp = g_strdup_printf (
_("Could not find the required widgets inside '%s'.\n\n"
"Please, reinstall gedit."),
GEDIT_GLADEDIR "page-setup-dialog.glade2");
gedit_warning (tmp, parent);
g_free (tmp);
gedit_warning (parent,
MISSING_WIDGETS,
GEDIT_GLADEDIR "page-setup-dialog.glade2");
if (!dialog->dialog)
gtk_widget_destroy (dialog->dialog);
......@@ -655,7 +635,7 @@ get_page_setup_dialog (GtkWindow *parent)
return NULL;
}
setup_general_page (dialog);
setup_font_page (dialog);
......@@ -685,9 +665,8 @@ gedit_show_page_setup_dialog (GtkWindow *parent)
g_return_if_fail (parent != NULL);
dialog = get_page_setup_dialog (parent);
if (dialog == NULL)
dialog = page_setup_get_dialog (parent);
if (!dialog)
return;
if (!GTK_WIDGET_VISIBLE (dialog->dialog))
......
......@@ -43,7 +43,6 @@
#define PLUGIN_MANAGER_LOGO "/gedit-plugin-manager.png"
static void error_dialog (const gchar* str, GtkWindow *parent);
/* Return a newly allocated string containing the full location
* of program_name
......@@ -76,10 +75,11 @@ gedit_plugin_program_location_dialog (const gchar *program_name, const gchar *pl
gui = glade_xml_new (GEDIT_GLADEDIR "program-location-dialog.glade2",
"dialog_content", NULL);
if (!gui) {
gedit_warning (
"Could not find program-location-dialog.glade2, reinstall gedit.", parent);
if (!gui)
{
gedit_warning (parent,
MISSING_FILE,
GEDIT_GLADEDIR "program-location-dialog.glade2");
return NULL;
}
......@@ -105,8 +105,9 @@ gedit_plugin_program_location_dialog (const gchar *program_name, const gchar *pl
if (!content || !program_location_entry || !label || !logo)
{
g_warning (_("Could not find the required widgets inside %s."),
"program-location-dialog.glade2");
gedit_warning (parent,
MISSING_WIDGETS,
GEDIT_GLADEDIR "program-location-dialog.glade2");
return NULL;
}
......@@ -164,11 +165,13 @@ gedit_plugin_program_location_dialog (const gchar *program_name, const gchar *pl
if (!g_file_test (program_location, G_FILE_TEST_IS_EXECUTABLE))
{
error_dialog (_("The selected file is not executable."),
GTK_WINDOW (dialog));
gedit_warning (GTK_WINDOW (dialog),
_("The selected file is not executable."));
}
else
{
gtk_widget_hide (dialog);
}
break;
......@@ -184,8 +187,7 @@ gedit_plugin_program_location_dialog (const gchar *program_name, const gchar *pl
if (error != NULL)
{
gedit_warning (error->message, GTK_WINDOW (dialog));
gedit_warning (GTK_WINDOW (dialog), error->message);
g_error_free (error);
}
......@@ -213,23 +215,3 @@ gedit_plugin_program_location_dialog (const gchar *program_name, const gchar *pl
return program_location;
}
static void
error_dialog (const gchar* str, GtkWindow *parent)
{
GtkWidget *message_dlg;
message_dlg = gtk_message_dialog_new (
parent,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
str);
gtk_dialog_set_default_response (GTK_DIALOG (message_dlg), GTK_RESPONSE_OK);
gtk_window_set_resizable (GTK_WINDOW (message_dlg), FALSE);
gtk_dialog_run (GTK_DIALOG (message_dlg));
gtk_widget_destroy (message_dlg);
}
......@@ -1153,22 +1153,20 @@ get_preferences_dialog (GtkWindow *parent)
if (dialog != NULL)
{
gtk_window_present (GTK_WINDOW (dialog->dialog));
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
parent);
gtk_window_present (GTK_WINDOW (dialog->dialog));
return dialog;
}
gui = glade_xml_new (GEDIT_GLADEDIR "gedit-preferences.glade2",
"preferences_dialog", NULL);
if (!gui)
{
gedit_warning (_("Could not find '" GEDIT_GLADEDIR "gedit-preferences.glade2'.\n\n"
"Reinstall gedit."), parent);
gedit_warning (parent,
MISSING_FILE,
GEDIT_GLADEDIR "gedit-preferences.glade2");
return NULL;
}
......@@ -1271,9 +1269,9 @@ get_preferences_dialog (GtkWindow *parent)
!dialog->background_colorpicker_2 ||
!dialog->reset_button)
{
gedit_warning (_("Could not find the required widgets inside '"
GEDIT_GLADEDIR "gedit-preferences.glade2'.\n\n"
"Reinstall gedit."), parent);
gedit_warning (parent,
MISSING_WIDGETS,
GEDIT_GLADEDIR "gedit-preferences.glade2");
if (!dialog->dialog)
gtk_widget_destroy (dialog->dialog);
......@@ -1320,8 +1318,7 @@ gedit_show_preferences_dialog (GtkWindow *parent)
g_return_if_fail (parent != NULL);
dialog = get_preferences_dialog (parent);
if (dialog == NULL)
if (!dialog)
return;
if (!GTK_WIDGET_VISIBLE (dialog->dialog))
......
......@@ -36,6 +36,7 @@
#include <glib/gunicode.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-string.h>
......@@ -250,54 +251,6 @@ gedit_utils_is_uri_read_only (const gchar* uri)
return res;
}
GtkWidget*
gedit_button_new_with_stock_image (const gchar* text, const gchar* stock_id)
{
GtkWidget *button;
GtkStockItem item;
GtkWidget *label;
GtkWidget *image;
GtkWidget *hbox;
GtkWidget *align;
button = gtk_button_new ();
if (GTK_BIN (button)->child)
gtk_container_remove (GTK_CONTAINER (button),
GTK_BIN (button)->child);
if (gtk_stock_lookup (stock_id, &item))
{
label = gtk_label_new_with_mnemonic (text);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
hbox = gtk_hbox_new (FALSE, 2);
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (button), align);
gtk_container_add (GTK_CONTAINER (align), hbox);
gtk_widget_show_all (align);
return button;