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>
* app/widgets/Makefile.am
......
......@@ -33,6 +33,8 @@
#include "widgets/gimpdataeditor.h"
#include "widgets/gimpdatafactoryview.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "dialogs/dialogs.h"
......@@ -53,9 +55,9 @@ struct _GimpDataDeleteData
/* local function prototypes */
static void data_delete_callback (GtkWidget *widget,
gboolean delete,
gpointer data);
static void data_delete_confirm_response (GtkWidget *dialog,
gint response_id,
GimpDataDeleteData *delete_data);
/* public functions */
......@@ -138,32 +140,33 @@ data_delete_data_cmd_callback (GtkAction *action,
{
GimpDataDeleteData *delete_data;
GtkWidget *dialog;
gchar *str;
delete_data = g_new0 (GimpDataDeleteData, 1);
delete_data->factory = view->factory;
delete_data->data = data;
str = g_strdup_printf (_("Are you sure you want to delete '%s' "
"from the list and from disk?"),
GIMP_OBJECT (data)->name);
dialog = gimp_query_boolean_box (_("Delete Data Object"),
GTK_WIDGET (view),
dialog = gimp_message_dialog_new (_("Delete Object"), GIMP_STOCK_WARNING,
GTK_WIDGET (view), 0,
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);
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_DELETE, GTK_RESPONSE_OK,
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);
}
}
......@@ -211,13 +214,13 @@ data_edit_data_cmd_callback (GtkAction *action,
/* private functions */
static void
data_delete_callback (GtkWidget *widget,
gboolean delete,
gpointer data)
data_delete_confirm_response (GtkWidget *dialog,
gint response_id,
GimpDataDeleteData *delete_data)
{
GimpDataDeleteData *delete_data = data;
gtk_widget_destroy (dialog);
if (delete)
if (response_id == GTK_RESPONSE_OK)
{
GError *error = NULL;
......@@ -229,4 +232,6 @@ data_delete_callback (GtkWidget *widget,
g_clear_error (&error);
}
}
g_free (delete_data);
}
......@@ -41,6 +41,8 @@
#include "widgets/gimpclipboard.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "dialogs/dialogs.h"
......@@ -54,9 +56,9 @@
static void edit_paste (GimpDisplay *gdisp,
gboolean paste_into);
static void edit_undo_clear_callback (GtkWidget *widget,
gboolean clear,
gpointer data);
static void edit_undo_clear_response (GtkWidget *dialog,
gint response_id,
GimpImage *gimage);
static void cut_named_buffer_callback (GtkWidget *widget,
const gchar *name,
gpointer data);
......@@ -99,16 +101,26 @@ edit_undo_clear_cmd_callback (GtkAction *action,
return_if_no_image (gimage, data);
return_if_no_widget (widget, data);
dialog = gimp_query_boolean_box (_("Clear Undo History"), widget,
gimp_standard_help_func,
GIMP_HELP_EDIT_UNDO_CLEAR,
GIMP_STOCK_QUESTION,
_("Really clear image's undo history?"),
GTK_STOCK_CLEAR, GTK_STOCK_CANCEL,
G_OBJECT (gimage),
"disconnect",
edit_undo_clear_callback,
dialog = gimp_message_dialog_new (_("Clear Undo History"), GIMP_STOCK_WARNING,
widget, 0,
gimp_standard_help_func, NULL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_CLEAR, GTK_RESPONSE_OK,
NULL);
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);
}
......@@ -284,14 +296,14 @@ edit_paste (GimpDisplay *gdisp,
}
static void
edit_undo_clear_callback (GtkWidget *widget,
gboolean clear,
gpointer data)
edit_undo_clear_response (GtkWidget *dialog,
gint response_id,
GimpImage *gimage)
{
if (clear)
{
GimpImage *gimage = data;
gtk_widget_destroy (dialog);
if (response_id == GTK_RESPONSE_OK)
{
gimp_image_undo_disable (gimage);
gimp_image_undo_enable (gimage);
gimp_image_flush (gimage);
......
......@@ -41,6 +41,8 @@
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpfiledialog.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmessagebox.h"
#include "widgets/gimpmessagedialog.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
......@@ -72,9 +74,9 @@ static void file_save_dialog_destroyed (GtkWidget *dialog,
static void file_new_template_callback (GtkWidget *widget,
const gchar *name,
gpointer data);
static void file_revert_confirm_callback (GtkWidget *widget,
gboolean revert,
gpointer data);
static void file_revert_confirm_response (GtkWidget *dialog,
gint response_id,
GimpDisplay *gdisp);
/* public functions */
......@@ -269,57 +271,58 @@ file_revert_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *gdisp;
GtkWidget *query_box;
GtkWidget *dialog;
const gchar *uri;
return_if_no_display (gdisp, data);
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)
{
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
{
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"
"'%s'?\n\n"
"You will lose all your changes, "
"including all undo information."),
basename, uri);
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_REVERT_TO_SAVED, GTK_RESPONSE_OK,
g_free (basename);
NULL);
query_box = gimp_query_boolean_box (_("Revert Image"),
gdisp->shell,
gimp_standard_help_func,
GIMP_HELP_FILE_REVERT,
GIMP_STOCK_QUESTION,
text,
GTK_STOCK_YES, GTK_STOCK_NO,
G_OBJECT (gdisp), "disconnect",
file_revert_confirm_callback,
g_signal_connect_object (gdisp, "disconnect",
G_CALLBACK (gtk_widget_destroy),
dialog, G_CONNECT_SWAPPED);
g_signal_connect (dialog, "response",
G_CALLBACK (file_revert_confirm_response),
gdisp);
g_free (text);
basename = g_path_get_basename (uri);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Revert '%s' to '%s'?"),
basename, uri);
g_free (basename);
g_object_set_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY,
query_box);
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),
GTK_WINDOW (gdisp->shell));
g_object_set_data (G_OBJECT (gdisp->gimage), REVERT_DATA_KEY, dialog);
gtk_widget_show (query_box);
gtk_widget_show (dialog);
}
}
......@@ -444,25 +447,24 @@ file_new_template_callback (GtkWidget *widget,
}
static void
file_revert_confirm_callback (GtkWidget *widget,
gboolean revert,
gpointer data)
file_revert_confirm_response (GtkWidget *dialog,
gint response_id,
GimpDisplay *gdisp)
{
GimpDisplay *gdisp = GIMP_DISPLAY (data);
GimpImage *old_gimage = gdisp->gimage;
gtk_widget_destroy (dialog);
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;
const gchar *uri;
GimpPDBStatusType status;
GError *error = NULL;
gimp = old_gimage->gimp;
uri = gimp_object_get_name (GIMP_OBJECT (old_gimage));
new_gimage = file_open_image (gimp, gimp_get_user_context (gimp),
......
......@@ -75,7 +75,13 @@ gimp_message_dialog_new (const gchar *title,
va_list args;
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,
"title", title,
......@@ -104,8 +110,8 @@ gimp_message_dialog_new (const gchar *title,
NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
dialog->box, FALSE, FALSE, 0);
gtk_widget_show (dialog->box);
GTK_WIDGET (dialog->box), FALSE, FALSE, 0);
gtk_widget_show (GTK_WIDGET (dialog->box));
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