Commit 95607cce authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

new function which works on all widgets in the dialog except the cancel

2004-08-10  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpfiledialog.[ch]
	(gimp_file_dialog_set_sensitive): new function which works on all
	widgets in the dialog except the cancel button.

	Remember if the active progress is cancelable and added two
	booleans "busy" and "canceled". Added GtkDialog::response()
	implementation which, if the dialog is busy, cancels the active
	progress and sets the dialog's "canceled" state.

	Moved the progress bar right above the action area so it is next
	to the cancel button and in the same place for both open and save
	dialogs.

	* app/gui/file-open-dialog.c
	* app/gui/file-save-dialog.c: use the new API to make image loading
	and saving cancelable again.

	* app/widgets/gimpthumbbox.c: use the same stuff to make
	thumbnailing cancelable. Increased the minimum height a bit so it
	doesn't resize when the progress bars are shown.
parent 02d2b990
2004-08-10 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpfiledialog.[ch]
(gimp_file_dialog_set_sensitive): new function which works on all
widgets in the dialog except the cancel button.
Remember if the active progress is cancelable and added two
booleans "busy" and "canceled". Added GtkDialog::response()
implementation which, if the dialog is busy, cancels the active
progress and sets the dialog's "canceled" state.
Moved the progress bar right above the action area so it is next
to the cancel button and in the same place for both open and save
dialogs.
* app/gui/file-open-dialog.c
* app/gui/file-save-dialog.c: use the new API to make image loading
and saving cancelable again.
* app/widgets/gimpthumbbox.c: use the same stuff to make
thumbnailing cancelable. Increased the minimum height a bit so it
doesn't resize when the progress bars are shown.
2004-08-10 Michael Natterer <mitch@gimp.org> 2004-08-10 Michael Natterer <mitch@gimp.org>
Redid the whole internal progress stuff: don't pass around Redid the whole internal progress stuff: don't pass around
......
...@@ -77,6 +77,8 @@ file_open_dialog_show (Gimp *gimp, ...@@ -77,6 +77,8 @@ file_open_dialog_show (Gimp *gimp,
if (! fileload) if (! fileload)
fileload = file_open_dialog_create (gimp); fileload = file_open_dialog_create (gimp);
gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (fileload), TRUE);
gimp_file_dialog_set_uri (GIMP_FILE_DIALOG (fileload), gimage, uri); gimp_file_dialog_set_uri (GIMP_FILE_DIALOG (fileload), gimage, uri);
if (parent) if (parent)
...@@ -117,19 +119,22 @@ file_open_dialog_response (GtkWidget *open_dialog, ...@@ -117,19 +119,22 @@ file_open_dialog_response (GtkWidget *open_dialog,
gint response_id, gint response_id,
Gimp *gimp) Gimp *gimp)
{ {
GSList *uris; GimpFileDialog *dialog = GIMP_FILE_DIALOG (open_dialog);
GSList *list; GSList *uris;
gboolean success = FALSE; GSList *list;
gboolean success = FALSE;
if (response_id != GTK_RESPONSE_OK) if (response_id != GTK_RESPONSE_OK)
{ {
gtk_widget_hide (open_dialog); if (! dialog->busy)
gtk_widget_hide (open_dialog);
return; return;
} }
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (open_dialog)); uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (open_dialog));
gtk_widget_set_sensitive (open_dialog, FALSE); gimp_file_dialog_set_sensitive (dialog, FALSE);
for (list = uris; list; list = g_slist_next (list)) for (list = uris; list; list = g_slist_next (list))
{ {
...@@ -141,7 +146,7 @@ file_open_dialog_response (GtkWidget *open_dialog, ...@@ -141,7 +146,7 @@ file_open_dialog_response (GtkWidget *open_dialog,
gimp, gimp,
list->data, list->data,
list->data, list->data,
GIMP_FILE_DIALOG (open_dialog)->file_proc)) dialog->file_proc))
{ {
success = TRUE; success = TRUE;
...@@ -150,12 +155,15 @@ file_open_dialog_response (GtkWidget *open_dialog, ...@@ -150,12 +155,15 @@ file_open_dialog_response (GtkWidget *open_dialog,
} }
g_free (filename); g_free (filename);
if (dialog->canceled)
break;
} }
if (success) if (success)
gtk_widget_hide (open_dialog); gtk_widget_hide (open_dialog);
gtk_widget_set_sensitive (open_dialog, TRUE); gimp_file_dialog_set_sensitive (dialog, TRUE);
g_slist_foreach (uris, (GFunc) g_free, NULL); g_slist_foreach (uris, (GFunc) g_free, NULL);
g_slist_free (uris); g_slist_free (uris);
......
...@@ -87,7 +87,7 @@ file_save_dialog_show (GimpImage *gimage, ...@@ -87,7 +87,7 @@ file_save_dialog_show (GimpImage *gimage,
if (! filesave) if (! filesave)
filesave = file_save_dialog_create (gimage->gimp); filesave = file_save_dialog_create (gimage->gimp);
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE); gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (filesave), TRUE);
if (GTK_WIDGET_VISIBLE (filesave)) if (GTK_WIDGET_VISIBLE (filesave))
{ {
...@@ -116,7 +116,7 @@ file_save_a_copy_dialog_show (GimpImage *gimage, ...@@ -116,7 +116,7 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! filesave) if (! filesave)
filesave = file_save_dialog_create (gimage->gimp); filesave = file_save_dialog_create (gimage->gimp);
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE); gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (filesave), TRUE);
if (GTK_WIDGET_VISIBLE (filesave)) if (GTK_WIDGET_VISIBLE (filesave))
{ {
...@@ -161,17 +161,19 @@ file_save_dialog_response (GtkWidget *save_dialog, ...@@ -161,17 +161,19 @@ file_save_dialog_response (GtkWidget *save_dialog,
gint response_id, gint response_id,
Gimp *gimp) Gimp *gimp)
{ {
GtkFileChooser *chooser = GTK_FILE_CHOOSER (save_dialog); GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
gchar *uri; gchar *uri;
gchar *filename; gchar *filename;
if (response_id != GTK_RESPONSE_OK) if (response_id != GTK_RESPONSE_OK)
{ {
file_dialog_hide (save_dialog); if (! dialog->busy)
file_dialog_hide (save_dialog);
return; return;
} }
uri = gtk_file_chooser_get_uri (chooser); uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (save_dialog));
filename = g_filename_from_uri (uri, NULL, NULL); filename = g_filename_from_uri (uri, NULL, NULL);
...@@ -181,9 +183,7 @@ file_save_dialog_response (GtkWidget *save_dialog, ...@@ -181,9 +183,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
} }
else else
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog); gimp_file_dialog_set_sensitive (dialog, FALSE);
gtk_widget_set_sensitive (save_dialog, FALSE);
if (file_save_dialog_save_image (save_dialog, if (file_save_dialog_save_image (save_dialog,
dialog->gimage, dialog->gimage,
...@@ -196,7 +196,7 @@ file_save_dialog_response (GtkWidget *save_dialog, ...@@ -196,7 +196,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
file_dialog_hide (save_dialog); file_dialog_hide (save_dialog);
} }
gtk_widget_set_sensitive (save_dialog, TRUE); gimp_file_dialog_set_sensitive (dialog, TRUE);
} }
g_free (uri); g_free (uri);
...@@ -250,7 +250,9 @@ file_save_overwrite (GtkWidget *save_dialog, ...@@ -250,7 +250,9 @@ file_save_overwrite (GtkWidget *save_dialog,
gtk_window_set_transient_for (GTK_WINDOW (query_box), gtk_window_set_transient_for (GTK_WINDOW (query_box),
GTK_WINDOW (save_dialog)); GTK_WINDOW (save_dialog));
gtk_widget_set_sensitive (save_dialog, FALSE); gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (save_dialog), FALSE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
GTK_RESPONSE_CANCEL, FALSE);
gtk_widget_show (query_box); gtk_widget_show (query_box);
} }
...@@ -260,12 +262,14 @@ file_save_overwrite_callback (GtkWidget *widget, ...@@ -260,12 +262,14 @@ file_save_overwrite_callback (GtkWidget *widget,
gboolean overwrite, gboolean overwrite,
gpointer data) gpointer data)
{ {
OverwriteData *overwrite_data = data; OverwriteData *overwrite_data = data;
GimpFileDialog *dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL, TRUE);
if (overwrite) if (overwrite)
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
gtk_widget_hide (widget); gtk_widget_hide (widget);
if (file_save_dialog_save_image (overwrite_data->save_dialog, if (file_save_dialog_save_image (overwrite_data->save_dialog,
...@@ -278,9 +282,10 @@ file_save_overwrite_callback (GtkWidget *widget, ...@@ -278,9 +282,10 @@ file_save_overwrite_callback (GtkWidget *widget,
{ {
file_dialog_hide (overwrite_data->save_dialog); file_dialog_hide (overwrite_data->save_dialog);
} }
} }
gtk_widget_set_sensitive (overwrite_data->save_dialog, TRUE); gimp_file_dialog_set_sensitive (dialog, TRUE);
g_free (overwrite_data->uri); g_free (overwrite_data->uri);
g_free (overwrite_data->raw_filename); g_free (overwrite_data->raw_filename);
......
...@@ -77,6 +77,8 @@ file_open_dialog_show (Gimp *gimp, ...@@ -77,6 +77,8 @@ file_open_dialog_show (Gimp *gimp,
if (! fileload) if (! fileload)
fileload = file_open_dialog_create (gimp); fileload = file_open_dialog_create (gimp);
gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (fileload), TRUE);
gimp_file_dialog_set_uri (GIMP_FILE_DIALOG (fileload), gimage, uri); gimp_file_dialog_set_uri (GIMP_FILE_DIALOG (fileload), gimage, uri);
if (parent) if (parent)
...@@ -117,19 +119,22 @@ file_open_dialog_response (GtkWidget *open_dialog, ...@@ -117,19 +119,22 @@ file_open_dialog_response (GtkWidget *open_dialog,
gint response_id, gint response_id,
Gimp *gimp) Gimp *gimp)
{ {
GSList *uris; GimpFileDialog *dialog = GIMP_FILE_DIALOG (open_dialog);
GSList *list; GSList *uris;
gboolean success = FALSE; GSList *list;
gboolean success = FALSE;
if (response_id != GTK_RESPONSE_OK) if (response_id != GTK_RESPONSE_OK)
{ {
gtk_widget_hide (open_dialog); if (! dialog->busy)
gtk_widget_hide (open_dialog);
return; return;
} }
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (open_dialog)); uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (open_dialog));
gtk_widget_set_sensitive (open_dialog, FALSE); gimp_file_dialog_set_sensitive (dialog, FALSE);
for (list = uris; list; list = g_slist_next (list)) for (list = uris; list; list = g_slist_next (list))
{ {
...@@ -141,7 +146,7 @@ file_open_dialog_response (GtkWidget *open_dialog, ...@@ -141,7 +146,7 @@ file_open_dialog_response (GtkWidget *open_dialog,
gimp, gimp,
list->data, list->data,
list->data, list->data,
GIMP_FILE_DIALOG (open_dialog)->file_proc)) dialog->file_proc))
{ {
success = TRUE; success = TRUE;
...@@ -150,12 +155,15 @@ file_open_dialog_response (GtkWidget *open_dialog, ...@@ -150,12 +155,15 @@ file_open_dialog_response (GtkWidget *open_dialog,
} }
g_free (filename); g_free (filename);
if (dialog->canceled)
break;
} }
if (success) if (success)
gtk_widget_hide (open_dialog); gtk_widget_hide (open_dialog);
gtk_widget_set_sensitive (open_dialog, TRUE); gimp_file_dialog_set_sensitive (dialog, TRUE);
g_slist_foreach (uris, (GFunc) g_free, NULL); g_slist_foreach (uris, (GFunc) g_free, NULL);
g_slist_free (uris); g_slist_free (uris);
......
...@@ -87,7 +87,7 @@ file_save_dialog_show (GimpImage *gimage, ...@@ -87,7 +87,7 @@ file_save_dialog_show (GimpImage *gimage,
if (! filesave) if (! filesave)
filesave = file_save_dialog_create (gimage->gimp); filesave = file_save_dialog_create (gimage->gimp);
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE); gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (filesave), TRUE);
if (GTK_WIDGET_VISIBLE (filesave)) if (GTK_WIDGET_VISIBLE (filesave))
{ {
...@@ -116,7 +116,7 @@ file_save_a_copy_dialog_show (GimpImage *gimage, ...@@ -116,7 +116,7 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! filesave) if (! filesave)
filesave = file_save_dialog_create (gimage->gimp); filesave = file_save_dialog_create (gimage->gimp);
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE); gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (filesave), TRUE);
if (GTK_WIDGET_VISIBLE (filesave)) if (GTK_WIDGET_VISIBLE (filesave))
{ {
...@@ -161,17 +161,19 @@ file_save_dialog_response (GtkWidget *save_dialog, ...@@ -161,17 +161,19 @@ file_save_dialog_response (GtkWidget *save_dialog,
gint response_id, gint response_id,
Gimp *gimp) Gimp *gimp)
{ {
GtkFileChooser *chooser = GTK_FILE_CHOOSER (save_dialog); GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
gchar *uri; gchar *uri;
gchar *filename; gchar *filename;
if (response_id != GTK_RESPONSE_OK) if (response_id != GTK_RESPONSE_OK)
{ {
file_dialog_hide (save_dialog); if (! dialog->busy)
file_dialog_hide (save_dialog);
return; return;
} }
uri = gtk_file_chooser_get_uri (chooser); uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (save_dialog));
filename = g_filename_from_uri (uri, NULL, NULL); filename = g_filename_from_uri (uri, NULL, NULL);
...@@ -181,9 +183,7 @@ file_save_dialog_response (GtkWidget *save_dialog, ...@@ -181,9 +183,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
} }
else else
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog); gimp_file_dialog_set_sensitive (dialog, FALSE);
gtk_widget_set_sensitive (save_dialog, FALSE);
if (file_save_dialog_save_image (save_dialog, if (file_save_dialog_save_image (save_dialog,
dialog->gimage, dialog->gimage,
...@@ -196,7 +196,7 @@ file_save_dialog_response (GtkWidget *save_dialog, ...@@ -196,7 +196,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
file_dialog_hide (save_dialog); file_dialog_hide (save_dialog);
} }
gtk_widget_set_sensitive (save_dialog, TRUE); gimp_file_dialog_set_sensitive (dialog, TRUE);
} }
g_free (uri); g_free (uri);
...@@ -250,7 +250,9 @@ file_save_overwrite (GtkWidget *save_dialog, ...@@ -250,7 +250,9 @@ file_save_overwrite (GtkWidget *save_dialog,
gtk_window_set_transient_for (GTK_WINDOW (query_box), gtk_window_set_transient_for (GTK_WINDOW (query_box),
GTK_WINDOW (save_dialog)); GTK_WINDOW (save_dialog));
gtk_widget_set_sensitive (save_dialog, FALSE); gimp_file_dialog_set_sensitive (GIMP_FILE_DIALOG (save_dialog), FALSE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (save_dialog),
GTK_RESPONSE_CANCEL, FALSE);
gtk_widget_show (query_box); gtk_widget_show (query_box);
} }
...@@ -260,12 +262,14 @@ file_save_overwrite_callback (GtkWidget *widget, ...@@ -260,12 +262,14 @@ file_save_overwrite_callback (GtkWidget *widget,
gboolean overwrite, gboolean overwrite,
gpointer data) gpointer data)
{ {
OverwriteData *overwrite_data = data; OverwriteData *overwrite_data = data;
GimpFileDialog *dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL, TRUE);
if (overwrite) if (overwrite)
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
gtk_widget_hide (widget); gtk_widget_hide (widget);
if (file_save_dialog_save_image (overwrite_data->save_dialog, if (file_save_dialog_save_image (overwrite_data->save_dialog,
...@@ -278,9 +282,10 @@ file_save_overwrite_callback (GtkWidget *widget, ...@@ -278,9 +282,10 @@ file_save_overwrite_callback (GtkWidget *widget,
{ {
file_dialog_hide (overwrite_data->save_dialog); file_dialog_hide (overwrite_data->save_dialog);
} }
} }
gtk_widget_set_sensitive (overwrite_data->save_dialog, TRUE); gimp_file_dialog_set_sensitive (dialog, TRUE);
g_free (overwrite_data->uri); g_free (overwrite_data->uri);
g_free (overwrite_data->raw_filename); g_free (overwrite_data->raw_filename);
......
...@@ -55,6 +55,8 @@ static void gimp_file_dialog_progress_iface_init (GimpProgressInterface *progre ...@@ -55,6 +55,8 @@ static void gimp_file_dialog_progress_iface_init (GimpProgressInterface *progre
static gboolean gimp_file_dialog_delete_event (GtkWidget *widget, static gboolean gimp_file_dialog_delete_event (GtkWidget *widget,
GdkEventAny *event); GdkEventAny *event);
static void gimp_file_dialog_response (GtkDialog *dialog,
gint response_id);
static GimpProgress * static GimpProgress *
gimp_file_dialog_progress_start (GimpProgress *progress, gimp_file_dialog_progress_start (GimpProgress *progress,
...@@ -76,8 +78,7 @@ static void gimp_file_dialog_add_proc_selection (GimpFileDialog *dialog, ...@@ -76,8 +78,7 @@ static void gimp_file_dialog_add_proc_selection (GimpFileDialog *dialog,
Gimp *gimp, Gimp *gimp,
GSList *file_procs, GSList *file_procs,
const gchar *automatic, const gchar *automatic,
const gchar *automatic_help_id, const gchar *automatic_help_id);
GtkWidget *vbox);
static void gimp_file_dialog_selection_changed (GtkFileChooser *chooser, static void gimp_file_dialog_selection_changed (GtkFileChooser *chooser,
GimpFileDialog *dialog); GimpFileDialog *dialog);
...@@ -134,8 +135,11 @@ static void ...@@ -134,8 +135,11 @@ static void
gimp_file_dialog_class_init (GimpFileDialogClass *klass) gimp_file_dialog_class_init (GimpFileDialogClass *klass)
{ {
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
widget_class->delete_event = gimp_file_dialog_delete_event; widget_class->delete_event = gimp_file_dialog_delete_event;
dialog_class->response = gimp_file_dialog_response;
} }
static void static void
...@@ -155,6 +159,21 @@ gimp_file_dialog_delete_event (GtkWidget *widget, ...@@ -155,6 +159,21 @@ gimp_file_dialog_delete_event (GtkWidget *widget,
return TRUE; return TRUE;
} }
static void
gimp_file_dialog_response (GtkDialog *dialog,
gint response_id)
{
GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
if (response_id != GTK_RESPONSE_OK && file_dialog->busy)
{
file_dialog->canceled = TRUE;
if (file_dialog->progress_active && file_dialog->progress_cancelable)
gimp_progress_cancel (GIMP_PROGRESS (dialog));
}
}
static GimpProgress * static GimpProgress *
gimp_file_dialog_progress_start (GimpProgress *progress, gimp_file_dialog_progress_start (GimpProgress *progress,
const gchar *message, const gchar *message,
...@@ -168,11 +187,11 @@ gimp_file_dialog_progress_start (GimpProgress *progress, ...@@ -168,11 +187,11 @@ gimp_file_dialog_progress_start (GimpProgress *progress,
gtk_progress_bar_set_text (bar, message); gtk_progress_bar_set_text (bar, message);
gtk_progress_bar_set_fraction (bar, 0.0); gtk_progress_bar_set_fraction (bar, 0.0);
/* gtk_widget_set_sensitive (dialog->cancel_button, cancelable); */
gtk_widget_show (dialog->progress); gtk_widget_show (dialog->progress);
dialog->progress_active = TRUE; dialog->progress_active = TRUE;
dialog->progress_cancelable = cancelable;
return progress; return progress;
} }
...@@ -191,11 +210,11 @@ gimp_file_dialog_progress_end (GimpProgress *progress) ...@@ -191,11 +210,11 @@ gimp_file_dialog_progress_end (GimpProgress *progress)
gtk_progress_bar_set_text (bar, ""); gtk_progress_bar_set_text (bar, "");
gtk_progress_bar_set_fraction (bar, 0.0); gtk_progress_bar_set_fraction (bar, 0.0);
/* gtk_widget_set_sensitive (dialog->cancel_button, FALSE); */
gtk_widget_hide (dialog->progress); gtk_widget_hide (dialog->progress);
dialog->progress_active = FALSE; dialog->progress_active = FALSE;
dialog->progress_cancelable = FALSE;
} }
} }
...@@ -254,7 +273,6 @@ gimp_file_dialog_new (Gimp *gimp, ...@@ -254,7 +273,6 @@ gimp_file_dialog_new (Gimp *gimp,
const gchar *help_id) const gchar *help_id)
{ {
GimpFileDialog *dialog; GimpFileDialog *dialog;
GtkWidget *extra_vbox;
GSList *file_procs; GSList *file_procs;
const gchar *automatic; const gchar *automatic;