Commit 62fdd17b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added infrastructure to access and set some state information of the

2008-05-08  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpfiledialog.[ch]: added infrastructure to 
access
	and set some state information of the GtkFileChooser.

	* app/dialogs/file-open-dialog.c
	* app/dialogs/file-save-dialog.c: don't keep the file-chooser
	dialogs around. Instead keep the state attached to the Gimp 
object
	(one state for load, one for save dialogs). Closes bug #528811.


svn path=/trunk/; revision=25586
parent 7bacfae9
2008-05-08 Sven Neumann <sven@gimp.org>
* app/widgets/gimpfiledialog.[ch]: added infrastructure to access
and set some state information of the GtkFileChooser.
* app/dialogs/file-open-dialog.c
* app/dialogs/file-save-dialog.c: don't keep the file-chooser
dialogs around. Instead keep the state attached to the Gimp object
(one state for load, one for save dialogs). Closes bug #528811.
2008-05-08 Sven Neumann <sven@gimp.org>
* app/widgets/widgets-types.h
......
......@@ -66,7 +66,8 @@ static gboolean file_open_dialog_open_layers (GtkWidget *open_dialog
GtkWidget *
file_open_dialog_new (Gimp *gimp)
{
GtkWidget *dialog;
GtkWidget *dialog;
GimpFileDialogState *state;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
......@@ -78,6 +79,11 @@ file_open_dialog_new (Gimp *gimp)
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
state = g_object_get_data (G_OBJECT (gimp), "gimp-file-open-dialog-state");
if (state)
gimp_file_dialog_set_state (GIMP_FILE_DIALOG (dialog), state);
g_signal_connect (dialog, "response",
G_CALLBACK (file_open_dialog_response),
gimp);
......@@ -98,10 +104,14 @@ file_open_dialog_response (GtkWidget *open_dialog,
GSList *list;
gboolean success = FALSE;
g_object_set_data_full (G_OBJECT (gimp), "gimp-file-open-dialog-state",
gimp_file_dialog_get_state (dialog),
(GDestroyNotify) gimp_file_dialog_state_destroy);
if (response_id != GTK_RESPONSE_OK)
{
if (! dialog->busy)
gtk_widget_hide (open_dialog);
gtk_widget_destroy (open_dialog);
return;
}
......@@ -155,13 +165,11 @@ file_open_dialog_response (GtkWidget *open_dialog,
if (success)
{
gtk_widget_hide (open_dialog);
if (dialog->image)
gimp_image_flush (dialog->image);
}
gimp_file_dialog_set_sensitive (dialog, TRUE);
gtk_widget_destroy (open_dialog);
}
g_slist_foreach (uris, (GFunc) g_free, NULL);
g_slist_free (uris);
......
......@@ -77,8 +77,9 @@ static gboolean file_save_dialog_save_image (GtkWidget *save_dial
GtkWidget *
file_save_dialog_new (Gimp *gimp)
{
GtkWidget *dialog;
const gchar *uri;
GtkWidget *dialog;
GimpFileDialogState *state;
const gchar *uri;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
......@@ -88,6 +89,11 @@ file_save_dialog_new (Gimp *gimp)
GTK_STOCK_SAVE,
GIMP_HELP_FILE_SAVE);
state = g_object_get_data (G_OBJECT (gimp), "gimp-file-save-dialog-state");
if (state)
gimp_file_dialog_set_state (GIMP_FILE_DIALOG (dialog), state);
uri = g_object_get_data (G_OBJECT (gimp), "gimp-file-save-last-uri");
if (uri)
......@@ -115,20 +121,20 @@ file_save_dialog_response (GtkWidget *save_dialog,
gchar *uri;
gchar *basename;
GimpPlugInProcedure *save_proc;
gulong handler_id;
g_object_set_data_full (G_OBJECT (gimp), "gimp-file-save-dialog-state",
gimp_file_dialog_get_state (dialog),
(GDestroyNotify) gimp_file_dialog_state_destroy);
if (response_id != GTK_RESPONSE_OK)
{
if (! dialog->busy)
gtk_widget_hide (save_dialog);
gtk_widget_destroy (save_dialog);
return;
}
gimp_file_dialog_set_sensitive (dialog, FALSE);
handler_id = g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&dialog);
if (file_save_dialog_check_uri (save_dialog, gimp,
&uri, &basename, &save_proc))
......@@ -141,14 +147,14 @@ file_save_dialog_response (GtkWidget *save_dialog,
{
if (dialog)
{
gtk_widget_hide (save_dialog);
GtkWindow *parent;
if (dialog->close_after_saving)
{
GtkWindow *parent;
parent = gtk_window_get_transient_for (GTK_WINDOW (dialog));
parent = gtk_window_get_transient_for (GTK_WINDOW (dialog));
gtk_widget_destroy (save_dialog);
if (dialog->close_after_saving)
{
if (GIMP_IS_DISPLAY_SHELL (parent))
{
GimpDisplay *display;
......@@ -165,13 +171,6 @@ file_save_dialog_response (GtkWidget *save_dialog,
g_free (uri);
g_free (basename);
}
/* dialog may have been destroyed while save plugin was running */
if (dialog)
{
gimp_file_dialog_set_sensitive (dialog, TRUE);
g_signal_handler_disconnect (dialog, handler_id);
}
}
static gboolean
......
......@@ -55,6 +55,12 @@
#include "gimp-intl.h"
struct _GimpFileDialogState
{
gchar *filter_name;
};
static void gimp_file_dialog_progress_iface_init (GimpProgressInterface *iface);
static gboolean gimp_file_dialog_delete_event (GtkWidget *widget,
GdkEventAny *event);
......@@ -489,6 +495,63 @@ gimp_file_dialog_set_image (GimpFileDialog *dialog,
g_free (basename);
}
GimpFileDialogState *
gimp_file_dialog_get_state (GimpFileDialog *dialog)
{
GimpFileDialogState *state;
GtkFileFilter *filter;
g_return_val_if_fail (GIMP_IS_FILE_DIALOG (dialog), NULL);
state = g_slice_new0 (GimpFileDialogState);
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
if (filter)
state->filter_name = g_strdup (gtk_file_filter_get_name (filter));
return state;
}
void
gimp_file_dialog_set_state (GimpFileDialog *dialog,
GimpFileDialogState *state)
{
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
g_return_if_fail (state != NULL);
if (state->filter_name)
{
GSList *filters;
GSList *list;
filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (dialog));
for (list = filters; list; list = list->next)
{
GtkFileFilter *filter = GTK_FILE_FILTER (list->data);
const gchar *name = gtk_file_filter_get_name (filter);
if (name && strcmp (state->filter_name, name) == 0)
{
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
break;
}
}
g_slist_free (filters);
}
}
void
gimp_file_dialog_state_destroy (GimpFileDialogState *state)
{
g_return_if_fail (state != NULL);
g_free (state->filter_name);
g_slice_free (GimpFileDialogState, state);
}
/* private functions */
......
......@@ -60,6 +60,9 @@ struct _GimpFileDialogClass
};
typedef struct _GimpFileDialogState GimpFileDialogState;
GType gimp_file_dialog_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_file_dialog_new (Gimp *gimp,
......@@ -80,6 +83,12 @@ void gimp_file_dialog_set_image (GimpFileDialog *dialog,
gboolean save_a_copy,
gboolean close_after_saving);
GimpFileDialogState * gimp_file_dialog_get_state (GimpFileDialog *dialog);
void gimp_file_dialog_set_state (GimpFileDialog *dialog,
GimpFileDialogState *state);
void gimp_file_dialog_state_destroy (GimpFileDialogState *state);
G_END_DECLS
#endif /* __GIMP_FILE_DIALOG_H__ */
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