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

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>
Redid the whole internal progress stuff: don't pass around
......
......@@ -77,6 +77,8 @@ file_open_dialog_show (Gimp *gimp,
if (! fileload)
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);
if (parent)
......@@ -117,19 +119,22 @@ file_open_dialog_response (GtkWidget *open_dialog,
gint response_id,
Gimp *gimp)
{
GSList *uris;
GSList *list;
gboolean success = FALSE;
GimpFileDialog *dialog = GIMP_FILE_DIALOG (open_dialog);
GSList *uris;
GSList *list;
gboolean success = FALSE;
if (response_id != GTK_RESPONSE_OK)
{
gtk_widget_hide (open_dialog);
if (! dialog->busy)
gtk_widget_hide (open_dialog);
return;
}
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))
{
......@@ -141,7 +146,7 @@ file_open_dialog_response (GtkWidget *open_dialog,
gimp,
list->data,
list->data,
GIMP_FILE_DIALOG (open_dialog)->file_proc))
dialog->file_proc))
{
success = TRUE;
......@@ -150,12 +155,15 @@ file_open_dialog_response (GtkWidget *open_dialog,
}
g_free (filename);
if (dialog->canceled)
break;
}
if (success)
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_free (uris);
......
......@@ -87,7 +87,7 @@ file_save_dialog_show (GimpImage *gimage,
if (! filesave)
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))
{
......@@ -116,7 +116,7 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! filesave)
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))
{
......@@ -161,17 +161,19 @@ file_save_dialog_response (GtkWidget *save_dialog,
gint response_id,
Gimp *gimp)
{
GtkFileChooser *chooser = GTK_FILE_CHOOSER (save_dialog);
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
gchar *uri;
gchar *filename;
if (response_id != GTK_RESPONSE_OK)
{
file_dialog_hide (save_dialog);
if (! dialog->busy)
file_dialog_hide (save_dialog);
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);
......@@ -181,9 +183,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
}
else
{
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
gtk_widget_set_sensitive (save_dialog, FALSE);
gimp_file_dialog_set_sensitive (dialog, FALSE);
if (file_save_dialog_save_image (save_dialog,
dialog->gimage,
......@@ -196,7 +196,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
file_dialog_hide (save_dialog);
}
gtk_widget_set_sensitive (save_dialog, TRUE);
gimp_file_dialog_set_sensitive (dialog, TRUE);
}
g_free (uri);
......@@ -250,7 +250,9 @@ file_save_overwrite (GtkWidget *save_dialog,
gtk_window_set_transient_for (GTK_WINDOW (query_box),
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);
}
......@@ -260,12 +262,14 @@ file_save_overwrite_callback (GtkWidget *widget,
gboolean overwrite,
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)
{
GimpFileDialog *dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
gtk_widget_hide (widget);
if (file_save_dialog_save_image (overwrite_data->save_dialog,
......@@ -278,9 +282,10 @@ file_save_overwrite_callback (GtkWidget *widget,
{
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->raw_filename);
......
......@@ -77,6 +77,8 @@ file_open_dialog_show (Gimp *gimp,
if (! fileload)
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);
if (parent)
......@@ -117,19 +119,22 @@ file_open_dialog_response (GtkWidget *open_dialog,
gint response_id,
Gimp *gimp)
{
GSList *uris;
GSList *list;
gboolean success = FALSE;
GimpFileDialog *dialog = GIMP_FILE_DIALOG (open_dialog);
GSList *uris;
GSList *list;
gboolean success = FALSE;
if (response_id != GTK_RESPONSE_OK)
{
gtk_widget_hide (open_dialog);
if (! dialog->busy)
gtk_widget_hide (open_dialog);
return;
}
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))
{
......@@ -141,7 +146,7 @@ file_open_dialog_response (GtkWidget *open_dialog,
gimp,
list->data,
list->data,
GIMP_FILE_DIALOG (open_dialog)->file_proc))
dialog->file_proc))
{
success = TRUE;
......@@ -150,12 +155,15 @@ file_open_dialog_response (GtkWidget *open_dialog,
}
g_free (filename);
if (dialog->canceled)
break;
}
if (success)
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_free (uris);
......
......@@ -87,7 +87,7 @@ file_save_dialog_show (GimpImage *gimage,
if (! filesave)
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))
{
......@@ -116,7 +116,7 @@ file_save_a_copy_dialog_show (GimpImage *gimage,
if (! filesave)
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))
{
......@@ -161,17 +161,19 @@ file_save_dialog_response (GtkWidget *save_dialog,
gint response_id,
Gimp *gimp)
{
GtkFileChooser *chooser = GTK_FILE_CHOOSER (save_dialog);
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
gchar *uri;
gchar *filename;
if (response_id != GTK_RESPONSE_OK)
{
file_dialog_hide (save_dialog);
if (! dialog->busy)
file_dialog_hide (save_dialog);
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);
......@@ -181,9 +183,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
}
else
{
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog);
gtk_widget_set_sensitive (save_dialog, FALSE);
gimp_file_dialog_set_sensitive (dialog, FALSE);
if (file_save_dialog_save_image (save_dialog,
dialog->gimage,
......@@ -196,7 +196,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
file_dialog_hide (save_dialog);
}
gtk_widget_set_sensitive (save_dialog, TRUE);
gimp_file_dialog_set_sensitive (dialog, TRUE);
}
g_free (uri);
......@@ -250,7 +250,9 @@ file_save_overwrite (GtkWidget *save_dialog,
gtk_window_set_transient_for (GTK_WINDOW (query_box),
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);
}
......@@ -260,12 +262,14 @@ file_save_overwrite_callback (GtkWidget *widget,
gboolean overwrite,
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)
{
GimpFileDialog *dialog = GIMP_FILE_DIALOG (overwrite_data->save_dialog);
gtk_widget_hide (widget);
if (file_save_dialog_save_image (overwrite_data->save_dialog,
......@@ -278,9 +282,10 @@ file_save_overwrite_callback (GtkWidget *widget,
{
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->raw_filename);
......
......@@ -55,6 +55,8 @@ static void gimp_file_dialog_progress_iface_init (GimpProgressInterface *progre
static gboolean gimp_file_dialog_delete_event (GtkWidget *widget,
GdkEventAny *event);
static void gimp_file_dialog_response (GtkDialog *dialog,
gint response_id);
static GimpProgress *
gimp_file_dialog_progress_start (GimpProgress *progress,
......@@ -76,8 +78,7 @@ static void gimp_file_dialog_add_proc_selection (GimpFileDialog *dialog,
Gimp *gimp,
GSList *file_procs,
const gchar *automatic,
const gchar *automatic_help_id,
GtkWidget *vbox);
const gchar *automatic_help_id);
static void gimp_file_dialog_selection_changed (GtkFileChooser *chooser,
GimpFileDialog *dialog);
......@@ -134,8 +135,11 @@ static void
gimp_file_dialog_class_init (GimpFileDialogClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
widget_class->delete_event = gimp_file_dialog_delete_event;
dialog_class->response = gimp_file_dialog_response;
}
static void
......@@ -155,6 +159,21 @@ gimp_file_dialog_delete_event (GtkWidget *widget,
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 *
gimp_file_dialog_progress_start (GimpProgress *progress,
const gchar *message,
......@@ -168,11 +187,11 @@ gimp_file_dialog_progress_start (GimpProgress *progress,
gtk_progress_bar_set_text (bar, message);
gtk_progress_bar_set_fraction (bar, 0.0);
/* gtk_widget_set_sensitive (dialog->cancel_button, cancelable); */
gtk_widget_show (dialog->progress);
dialog->progress_active = TRUE;
dialog->progress_active = TRUE;
dialog->progress_cancelable = cancelable;
return progress;
}
......@@ -191,11 +210,11 @@ gimp_file_dialog_progress_end (GimpProgress *progress)
gtk_progress_bar_set_text (bar, "");
gtk_progress_bar_set_fraction (bar, 0.0);
/* gtk_widget_set_sensitive (dialog->cancel_button, FALSE); */
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,
const gchar *help_id)
{
GimpFileDialog *dialog;
GtkWidget *extra_vbox;
GSList *file_procs;
const gchar *automatic;
const gchar *automatic_help_id;
......@@ -304,20 +322,50 @@ gimp_file_dialog_new (Gimp *gimp,
gimp_file_dialog_add_filters (dialog, gimp, file_procs);
extra_vbox = gtk_vbox_new (FALSE, 12);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), extra_vbox);
gtk_widget_show (extra_vbox);
gimp_file_dialog_add_proc_selection (dialog, gimp, file_procs, automatic,
automatic_help_id);
dialog->progress = gtk_progress_bar_new ();
gtk_box_pack_start (GTK_BOX (extra_vbox), dialog->progress, FALSE, FALSE, 0);
/* don't gtk_widget_show (dialog->progress); */
gimp_file_dialog_add_proc_selection (dialog, gimp, file_procs, automatic,
automatic_help_id, extra_vbox);
gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox), dialog->progress,
FALSE, FALSE, 0);
return GTK_WIDGET (dialog);
}
void
gimp_file_dialog_set_sensitive (GimpFileDialog *dialog,
gboolean sensitive)
{
GList *children;
GList *list;
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
children =
gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox));
for (list = children; list; list = g_list_next (list))
{
/* skip the last item (the action area) */
if (! g_list_next (list))
break;
gtk_widget_set_sensitive (list->data, sensitive);
}
g_list_free (children);
if (sensitive)
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL, sensitive);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GTK_RESPONSE_OK, sensitive);
dialog->busy = ! sensitive;
dialog->canceled = FALSE;
}
void
gimp_file_dialog_set_file_proc (GimpFileDialog *dialog,
PlugInProcDef *file_proc)
......@@ -497,13 +545,13 @@ gimp_file_dialog_add_proc_selection (GimpFileDialog *dialog,
Gimp *gimp,
GSList *file_procs,
const gchar *automatic,
const gchar *automatic_help_id,
GtkWidget *vbox)
const gchar *automatic_help_id)
{
GtkWidget *scrolled_window;
dialog->proc_expander = gtk_expander_new_with_mnemonic (NULL);
gtk_box_pack_start (GTK_BOX (vbox), dialog->proc_expander, TRUE, TRUE, 0);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog),
dialog->proc_expander);
gtk_widget_show (dialog->proc_expander);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
......
......@@ -50,7 +50,11 @@ struct _GimpFileDialog
GtkWidget *proc_view;
gboolean progress_active;
gboolean progress_cancelable;
GtkWidget *progress;
gboolean busy;
gboolean canceled;
};
struct _GimpFileDialogClass
......@@ -68,6 +72,9 @@ GtkWidget * gimp_file_dialog_new (Gimp *gimp,
const gchar *stock_id,
const gchar *help_id);
void gimp_file_dialog_set_sensitive (GimpFileDialog *dialog,
gboolean sensitive);
void gimp_file_dialog_set_file_proc (GimpFileDialog *dialog,
PlugInProcDef *file_proc);
......
......@@ -35,6 +35,7 @@
#include "file/file-utils.h"
#include "gimpfiledialog.h" /* eek */
#include "gimppreview.h"
#include "gimpthumbbox.h"
#include "gimpwidgets-utils.h"
......@@ -199,7 +200,6 @@ gimp_thumb_box_progress_start (GimpProgress *progress,
GtkProgressBar *bar = GTK_PROGRESS_BAR (thumb_box->progress);
gtk_progress_bar_set_fraction (bar, 0.0);
/* gtk_widget_set_sensitive (thumb_box->cancel_button, cancelable); */
thumb_box->progress_active = TRUE;
......@@ -219,7 +219,6 @@ gimp_thumb_box_progress_end (GimpProgress *progress)
GtkProgressBar *bar = GTK_PROGRESS_BAR (thumb_box->progress);
gtk_progress_bar_set_fraction (bar, 0.0);
/* gtk_widget_set_sensitive (thumb_box->cancel_button, FALSE); */
thumb_box->progress_active = FALSE;
}
......@@ -351,7 +350,7 @@ gimp_thumb_box_new (Gimp *gimp)
gtk_box_pack_start (GTK_BOX (vbox2), box->filename, FALSE, FALSE, 0);
gtk_widget_show (box->filename);
box->info = gtk_label_new (" \n \n ");
box->info = gtk_label_new (" \n \n \n ");
gtk_misc_set_alignment (GTK_MISC (box->info), 0.5, 0.0);
gtk_label_set_justify (GTK_LABEL (box->info), GTK_JUSTIFY_CENTER);
gtk_box_pack_start (GTK_BOX (vbox2), box->info, FALSE, FALSE, 0);
......@@ -466,100 +465,115 @@ static void
gimp_thumb_box_create_thumbnails (GimpThumbBox *box,
gboolean always_create)
{
Gimp *gimp = box->imagefile->gimp;
Gimp *gimp = box->imagefile->gimp;
GtkWidget *toplevel;
GimpFileDialog *dialog = NULL;
GSList *list;
gint n_uris;
gint i;
if (gimp->config->thumbnail_size != GIMP_THUMBNAIL_SIZE_NONE &&
gimp->config->layer_previews)
{
GSList *list;
gint n_uris;
gint i;
if (gimp->config->thumbnail_size == GIMP_THUMBNAIL_SIZE_NONE ||
! gimp->config->layer_previews)
return;
gimp_set_busy (gimp);
gtk_widget_set_sensitive (gtk_widget_get_toplevel (GTK_WIDGET (box)),
FALSE);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (box));
if (box->uris)
gtk_widget_show (box->progress);
if (GIMP_IS_FILE_DIALOG (toplevel))
dialog = GIMP_FILE_DIALOG (toplevel);
n_uris = g_slist_length (box->uris);
gimp_set_busy (gimp);
if (n_uris > 1)
{
gchar *str;
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (box->thumb_progress),
NULL);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (box->thumb_progress),
0.0);
gtk_widget_hide (box->info);
gtk_widget_show (box->thumb_progress);
if (dialog)
gimp_file_dialog_set_sensitive (dialog, FALSE);
else
gtk_widget_set_sensitive (toplevel, FALSE);
for (list = box->uris->next, i = 0;
list;
list = g_slist_next (list), i++)
{
str = g_strdup_printf (_("Thumbnail %d of %d"), i, n_uris);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (box->thumb_progress),
str);
g_free (str);
if (box->uris)
gtk_widget_show (box->progress);
while (g_main_context_pending (NULL))
g_main_context_iteration (NULL, FALSE);
n_uris = g_slist_length (box->uris);