Commit 2b2737f2 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

handle parent widget not being a GtkWindow by calling

2004-10-13  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpmessagedialog.c: handle parent widget not being
	a GtkWindow by calling gtk_widget_get_toplevel().

	* app/actions/data-commands.c
	* app/actions/edit-commands.c
	* app/actions/file-commands.c: ported more boolean queries to
	GimpMessageDialog.
parent 8300c550
2004-10-13 Sven Neumann <sven@gimp.org>
* app/widgets/gimpmessagedialog.c: handle parent widget not being
a GtkWindow by calling gtk_widget_get_toplevel().
* app/actions/data-commands.c
* app/actions/edit-commands.c
* app/actions/file-commands.c: ported more boolean queries to
GimpMessageDialog.
2004-10-13 Sven Neumann <sven@gimp.org> 2004-10-13 Sven Neumann <sven@gimp.org>
* app/widgets/Makefile.am * app/widgets/Makefile.am
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "widgets/gimpdataeditor.h" #include "widgets/gimpdataeditor.h"
#include "widgets/gimpdatafactoryview.h" #include "widgets/gimpdatafactoryview.h"
#include "widgets/gimpdialogfactory.h" #include "widgets/gimpdialogfactory.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "dialogs/dialogs.h" #include "dialogs/dialogs.h"
...@@ -53,9 +55,9 @@ struct _GimpDataDeleteData ...@@ -53,9 +55,9 @@ struct _GimpDataDeleteData
/* local function prototypes */ /* local function prototypes */
static void data_delete_callback (GtkWidget *widget, static void data_delete_confirm_response (GtkWidget *dialog,
gboolean delete, gint response_id,
gpointer data); GimpDataDeleteData *delete_data);
/* public functions */ /* public functions */
...@@ -138,32 +140,33 @@ data_delete_data_cmd_callback (GtkAction *action, ...@@ -138,32 +140,33 @@ data_delete_data_cmd_callback (GtkAction *action,
{ {
GimpDataDeleteData *delete_data; GimpDataDeleteData *delete_data;
GtkWidget *dialog; GtkWidget *dialog;
gchar *str;
delete_data = g_new0 (GimpDataDeleteData, 1); delete_data = g_new0 (GimpDataDeleteData, 1);
delete_data->factory = view->factory; delete_data->factory = view->factory;
delete_data->data = data; delete_data->data = data;
str = g_strdup_printf (_("Are you sure you want to delete '%s' " dialog = gimp_message_dialog_new (_("Delete Object"), GIMP_STOCK_WARNING,
"from the list and from disk?"), GTK_WIDGET (view), 0,
GIMP_OBJECT (data)->name); gimp_standard_help_func, NULL,
dialog = gimp_query_boolean_box (_("Delete Data Object"), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_WIDGET (view), GTK_STOCK_DELETE, GTK_RESPONSE_OK,
gimp_standard_help_func, NULL,
GIMP_STOCK_QUESTION,
str,
GTK_STOCK_DELETE, GTK_STOCK_CANCEL,
G_OBJECT (data),
"disconnect",
data_delete_callback,
delete_data);
g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_free, delete_data); NULL);
g_free (str); g_signal_connect_object (data, "disconnect",
G_CALLBACK (gtk_widget_destroy),
dialog, G_CONNECT_SWAPPED);
g_signal_connect (dialog, "response",
G_CALLBACK (data_delete_confirm_response),
delete_data);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Are you sure you want to delete "
"'%s' from the list and from disk?"),
GIMP_OBJECT (data)->name);
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }
} }
...@@ -211,13 +214,13 @@ data_edit_data_cmd_callback (GtkAction *action, ...@@ -211,13 +214,13 @@ data_edit_data_cmd_callback (GtkAction *action,
/* private functions */ /* private functions */
static void static void
data_delete_callback (GtkWidget *widget, data_delete_confirm_response (GtkWidget *dialog,
gboolean delete, gint response_id,
gpointer data) GimpDataDeleteData *delete_data)
{ {
GimpDataDeleteData *delete_data = data; gtk_widget_destroy (dialog);
if (delete) if (response_id == GTK_RESPONSE_OK)
{ {
GError *error = NULL; GError *error = NULL;
...@@ -229,4 +232,6 @@ data_delete_callback (GtkWidget *widget, ...@@ -229,4 +232,6 @@ data_delete_callback (GtkWidget *widget,
g_clear_error (&error); g_clear_error (&error);
} }
} }
g_free (delete_data);
} }
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include "widgets/gimpclipboard.h" #include "widgets/gimpclipboard.h"
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimpdialogfactory.h" #include "widgets/gimpdialogfactory.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "dialogs/dialogs.h" #include "dialogs/dialogs.h"
...@@ -54,9 +56,9 @@ ...@@ -54,9 +56,9 @@
static void edit_paste (GimpDisplay *gdisp, static void edit_paste (GimpDisplay *gdisp,
gboolean paste_into); gboolean paste_into);
static void edit_undo_clear_callback (GtkWidget *widget, static void edit_undo_clear_response (GtkWidget *dialog,
gboolean clear, gint response_id,
gpointer data); GimpImage *gimage);
static void cut_named_buffer_callback (GtkWidget *widget, static void cut_named_buffer_callback (GtkWidget *widget,
const gchar *name, const gchar *name,
gpointer data); gpointer data);
...@@ -99,16 +101,26 @@ edit_undo_clear_cmd_callback (GtkAction *action, ...@@ -99,16 +101,26 @@ edit_undo_clear_cmd_callback (GtkAction *action,
return_if_no_image (gimage, data); return_if_no_image (gimage, data);
return_if_no_widget (widget, data); return_if_no_widget (widget, data);
dialog = gimp_query_boolean_box (_("Clear Undo History"), widget, dialog = gimp_message_dialog_new (_("Clear Undo History"), GIMP_STOCK_WARNING,
gimp_standard_help_func, widget, 0,
GIMP_HELP_EDIT_UNDO_CLEAR, gimp_standard_help_func, NULL,
GIMP_STOCK_QUESTION,
_("Really clear image's undo history?"), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_CLEAR, GTK_STOCK_CANCEL, GTK_STOCK_CLEAR, GTK_RESPONSE_OK,
G_OBJECT (gimage),
"disconnect", NULL);
edit_undo_clear_callback,
gimage); g_signal_connect_object (gimage, "disconnect",
G_CALLBACK (gtk_widget_destroy),
dialog, G_CONNECT_SWAPPED);
g_signal_connect (dialog, "response",
G_CALLBACK (edit_undo_clear_response),
gimage);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Really clear image's undo history?"));
gtk_widget_show (dialog); gtk_widget_show (dialog);
} }
...@@ -284,14 +296,14 @@ edit_paste (GimpDisplay *gdisp, ...@@ -284,14 +296,14 @@ edit_paste (GimpDisplay *gdisp,
} }
static void static void
edit_undo_clear_callback (GtkWidget *widget, edit_undo_clear_response (GtkWidget *dialog,
gboolean clear, gint response_id,
gpointer data) GimpImage *gimage)
{ {
if (clear) gtk_widget_destroy (dialog);
{
GimpImage *gimage = data;
if (response_id == GTK_RESPONSE_OK)
{
gimp_image_undo_disable (gimage); gimp_image_undo_disable (gimage);
gimp_image_undo_enable (gimage); gimp_image_undo_enable (gimage);
gimp_image_flush (gimage); gimp_image_flush (gimage);
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include "widgets/gimpdialogfactory.h" #include "widgets/gimpdialogfactory.h"
#include "widgets/gimpfiledialog.h" #include "widgets/gimpfiledialog.h"
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "display/gimpdisplay.h" #include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h" #include "display/gimpdisplay-foreach.h"
...@@ -72,9 +74,9 @@ static void file_save_dialog_destroyed (GtkWidget *dialog, ...@@ -72,9 +74,9 @@ static void file_save_dialog_destroyed (GtkWidget *dialog,
static void file_new_template_callback (GtkWidget *widget, static void file_new_template_callback (GtkWidget *widget,
const gchar *name, const gchar *name,
gpointer data); gpointer data);
static void file_revert_confirm_callback (GtkWidget *widget, static void file_revert_confirm_response (GtkWidget *dialog,
gboolean revert, gint response_id,
gpointer data); GimpDisplay *gdisp);
/* public functions */ /* public functions */
...@@ -269,57 +271,58 @@ file_revert_cmd_callback (GtkAction *action, ...@@ -269,57 +271,58 @@ file_revert_cmd_callback (GtkAction *action,
gpointer data) gpointer data)
{ {
GimpDisplay *gdisp; GimpDisplay *gdisp;
GtkWidget *query_box; GtkWidget *dialog;
const gchar *uri; const gchar *uri;
return_if_no_display (gdisp, data); return_if_no_display (gdisp, data);
uri = gimp_object_get_name (GIMP_OBJECT (gdisp->gimage)); uri = gimp_object_get_name (GIMP_OBJECT (gdisp->gimage));
query_box = g_object_get_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY); dialog = g_object_get_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY);
if (! uri) if (! uri)
{ {
g_message (_("Revert failed. No file name associated with this image.")); g_message (_("Revert failed. No file name associated with this image."));
} }
else if (query_box) else if (dialog)
{ {
gtk_window_present (GTK_WINDOW (query_box->window)); gtk_window_present (GTK_WINDOW (dialog));
} }
else else
{ {
gchar *basename; gchar *basename;
gchar *text;
basename = g_path_get_basename (uri); dialog =
gimp_message_dialog_new (_("Revert Image"), GIMP_STOCK_QUESTION,
gdisp->shell, 0,
gimp_standard_help_func, GIMP_HELP_FILE_REVERT,
text = g_strdup_printf (_("Revert '%s' to\n" GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
"'%s'?\n\n" GTK_STOCK_REVERT_TO_SAVED, GTK_RESPONSE_OK,
"You will lose all your changes, "
"including all undo information."),
basename, uri);
g_free (basename); NULL);
query_box = gimp_query_boolean_box (_("Revert Image"), g_signal_connect_object (gdisp, "disconnect",
gdisp->shell, G_CALLBACK (gtk_widget_destroy),
gimp_standard_help_func, dialog, G_CONNECT_SWAPPED);
GIMP_HELP_FILE_REVERT,
GIMP_STOCK_QUESTION,
text,
GTK_STOCK_YES, GTK_STOCK_NO,
G_OBJECT (gdisp), "disconnect",
file_revert_confirm_callback,
gdisp);
g_free (text); g_signal_connect (dialog, "response",
G_CALLBACK (file_revert_confirm_response),
gdisp);
g_object_set_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY, basename = g_path_get_basename (uri);
query_box); gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Revert '%s' to '%s'?"),
basename, uri);
g_free (basename);
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("By reverting the image to the state saved "
"on disk, you will lose all changes, "
"including all undo information."));
gtk_window_set_transient_for (GTK_WINDOW (query_box), g_object_set_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY, dialog);
GTK_WINDOW (gdisp->shell));
gtk_widget_show (query_box); gtk_widget_show (dialog);
} }
} }
...@@ -444,25 +447,24 @@ file_new_template_callback (GtkWidget *widget, ...@@ -444,25 +447,24 @@ file_new_template_callback (GtkWidget *widget,
} }
static void static void
file_revert_confirm_callback (GtkWidget *widget, file_revert_confirm_response (GtkWidget *dialog,
gboolean revert, gint response_id,
gpointer data) GimpDisplay *gdisp)
{ {
GimpDisplay *gdisp = GIMP_DISPLAY (data); GimpImage *old_gimage = gdisp->gimage;
GimpImage *old_gimage = gdisp->gimage;
gtk_widget_destroy (dialog);
g_object_set_data (G_OBJECT (old_gimage), REVERT_DATA_KEY, NULL); g_object_set_data (G_OBJECT (old_gimage), REVERT_DATA_KEY, NULL);
if (revert) if (response_id == GTK_RESPONSE_OK)
{ {
Gimp *gimp; Gimp *gimp = old_gimage->gimp;
GimpImage *new_gimage; GimpImage *new_gimage;
const gchar *uri; const gchar *uri;
GimpPDBStatusType status; GimpPDBStatusType status;
GError *error = NULL; GError *error = NULL;
gimp = old_gimage->gimp;
uri = gimp_object_get_name (GIMP_OBJECT (old_gimage)); uri = gimp_object_get_name (GIMP_OBJECT (old_gimage));
new_gimage = file_open_image (gimp, gimp_get_user_context (gimp), new_gimage = file_open_image (gimp, gimp_get_user_context (gimp),
......
...@@ -75,7 +75,13 @@ gimp_message_dialog_new (const gchar *title, ...@@ -75,7 +75,13 @@ gimp_message_dialog_new (const gchar *title,
va_list args; va_list args;
g_return_val_if_fail (title != NULL, NULL); g_return_val_if_fail (title != NULL, NULL);
g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL); g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
if (parent)
{
if (! GTK_IS_WINDOW (parent))
parent = gtk_widget_get_toplevel (parent);
}
dialog = g_object_new (GIMP_TYPE_MESSAGE_DIALOG, dialog = g_object_new (GIMP_TYPE_MESSAGE_DIALOG,
"title", title, "title", title,
...@@ -104,8 +110,8 @@ gimp_message_dialog_new (const gchar *title, ...@@ -104,8 +110,8 @@ gimp_message_dialog_new (const gchar *title,
NULL); NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
dialog->box, FALSE, FALSE, 0); GTK_WIDGET (dialog->box), FALSE, FALSE, 0);
gtk_widget_show (dialog->box); gtk_widget_show (GTK_WIDGET (dialog->box));
return GTK_WIDGET (dialog); return GTK_WIDGET (dialog);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment