Commit d5cf690a authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

plug-ins/FractalExplorer/Dialogs.c plug-ins/flame/flame.c first plug-ins

2004-04-15  Michael Natterer  <mitch@gimp.org>

	* plug-ins/FractalExplorer/Dialogs.c
	* plug-ins/flame/flame.c
	* plug-ins/gfig/gfig.c: first plug-ins ported to GtkFileChooser.
parent 25589863
2004-04-15 Michael Natterer <mitch@gimp.org>
* plug-ins/FractalExplorer/Dialogs.c
* plug-ins/flame/flame.c
* plug-ins/gfig/gfig.c: first plug-ins ported to GtkFileChooser.
2004-04-15 Michael Natterer <mitch@gimp.org>
* app/display/gimpdisplayshell-callbacks.c
......
......@@ -72,18 +72,18 @@ static explorer_vals_t standardvals =
FORWARD DECLARATIONS
*********************************************************************/
static void load_file_selection_response (GtkFileSelection *fs,
gint response_id,
gpointer data);
static void file_selection_response (GtkFileSelection *fs,
gint response_id,
gpointer data);
static void create_load_file_selection (GtkWidget *widget,
GtkWidget *dialog);
static void create_file_selection (GtkWidget *widget,
GtkWidget *dialog);
static void explorer_logo_dialog (GtkWidget *parent);
static void load_file_chooser_response (GtkFileChooser *chooser,
gint response_id,
gpointer data);
static void save_file_chooser_response (GtkFileChooser *chooser,
gint response_id,
gpointer data);
static void create_load_file_chooser (GtkWidget *widget,
GtkWidget *dialog);
static void create_save_file_chooser (GtkWidget *widget,
GtkWidget *dialog);
static void explorer_logo_dialog (GtkWidget *parent);
/**********************************************************************
CALLBACKS
......@@ -796,7 +796,7 @@ explorer_dialog (void)
button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (create_load_file_selection),
G_CALLBACK (create_load_file_chooser),
dialog);
gtk_widget_show (button);
gimp_help_set_help_data (button, _("Load a fractal from file"), NULL);
......@@ -813,7 +813,7 @@ explorer_dialog (void)
button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (create_file_selection),
G_CALLBACK (create_save_file_chooser),
dialog);
gtk_widget_show (button);
gimp_help_set_help_data (button, _("Save active fractal to file"), NULL);
......@@ -1845,45 +1845,28 @@ save_callback (void)
}
static void
file_selection_response (GtkFileSelection *fs,
gint response_id,
gpointer data)
save_file_chooser_response (GtkFileChooser *chooser,
gint response_id,
gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
{
const gchar *filenamebuf;
filename = gtk_file_chooser_get_filename (chooser);
filenamebuf = gtk_file_selection_get_filename (fs);
/* Get the name */
if (!filenamebuf || strlen (filenamebuf) == 0)
{
g_message (_("Save: No filename given"));
return;
}
if (g_file_test (filenamebuf, G_FILE_TEST_IS_DIR))
{
/* Can't save to directory */
g_message (_("Cannot save to a folder."));
return;
}
filename = g_strdup (filenamebuf);
save_callback ();
}
gtk_widget_destroy (GTK_WIDGET (fs));
gtk_widget_destroy (GTK_WIDGET (chooser));
}
static void
load_file_selection_response (GtkFileSelection *fs,
gint response_id,
gpointer data)
load_file_chooser_response (GtkFileChooser *chooser,
gint response_id,
gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
{
filename = g_strdup (gtk_file_selection_get_filename (fs));
filename = gtk_file_chooser_get_filename (chooser);
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
......@@ -1896,27 +1879,34 @@ load_file_selection_response (GtkFileSelection *fs,
dialog_update_preview ();
}
gtk_widget_destroy (GTK_WIDGET (fs));
gtk_widget_destroy (GTK_WIDGET (chooser));
}
static void
create_load_file_selection (GtkWidget *widget,
GtkWidget *dialog)
create_load_file_chooser (GtkWidget *widget,
GtkWidget *dialog)
{
static GtkWidget *window = NULL;
if (!window)
{
window = gtk_file_selection_new (_("Load Fractal Parameters"));
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_NONE);
window =
gtk_file_chooser_dialog_new (_("Load Fractal Parameters"),
GTK_WINDOW (dialog),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (dialog));
gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_OK);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
g_signal_connect (window, "response",
G_CALLBACK (load_file_selection_response),
G_CALLBACK (load_file_chooser_response),
window);
}
......@@ -1924,29 +1914,36 @@ create_load_file_selection (GtkWidget *widget,
}
static void
create_file_selection (GtkWidget *widget,
GtkWidget *dialog)
create_save_file_chooser (GtkWidget *widget,
GtkWidget *dialog)
{
static GtkWidget *window = NULL;
if (!window)
if (! window)
{
window = gtk_file_selection_new (_("Save Fractal Parameters"));
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_NONE);
window =
gtk_file_chooser_dialog_new (_("Save Fractal Parameters"),
GTK_WINDOW (dialog),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (dialog));
gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_OK);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
g_signal_connect (window, "response",
G_CALLBACK (file_selection_response),
G_CALLBACK (save_file_chooser_response),
window);
}
if (tpath)
{
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), tpath);
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (window), tpath);
}
else if (fractalexplorer_path)
{
......@@ -1960,14 +1957,14 @@ create_file_selection (GtkWidget *widget,
if (!dir)
dir = g_strdup (gimp_directory ());
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), dir);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (window), dir);
g_free (dir);
gimp_path_free (path_list);
}
else
{
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), "/tmp");
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (window), "/tmp");
}
gtk_window_present (GTK_WINDOW (window));
......
......@@ -374,15 +374,13 @@ doit (GimpDrawable *drawable)
}
static void
file_response_callback (GtkFileSelection *fs,
gint response_id,
gpointer data)
file_response_callback (GtkFileChooser *chooser,
gint response_id,
gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
{
const gchar *filename;
filename = gtk_file_selection_get_filename (fs);
gchar *filename = gtk_file_chooser_get_filename (chooser);
if (load_save)
{
......@@ -394,6 +392,7 @@ file_response_callback (GtkFileSelection *fs,
{
g_message (_("'%s' is not a regular file"),
gimp_filename_to_utf8 (filename));
g_free (filename);
return;
}
......@@ -403,6 +402,7 @@ file_response_callback (GtkFileSelection *fs,
{
g_message (_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
g_free (filename);
return;
}
......@@ -433,15 +433,18 @@ file_response_callback (GtkFileSelection *fs,
{
g_message (_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
g_free (filename);
return;
}
print_control_point (f, &config.cp, 0);
fclose (f);
}
g_free (filename);
}
gtk_widget_hide (GTK_WIDGET (fs));
gtk_widget_destroy (GTK_WIDGET (chooser));
if (! GTK_WIDGET_SENSITIVE (load_button))
gtk_widget_set_sensitive (load_button, TRUE);
......@@ -451,14 +454,25 @@ file_response_callback (GtkFileSelection *fs,
}
static void
make_file_dlg (GtkWidget *parent)
make_file_dlg (const gchar *title,
GtkWidget *parent)
{
file_dlg = gtk_file_selection_new (NULL);
file_dlg = gtk_file_chooser_dialog_new (title, GTK_WINDOW (parent),
load_save ?
GTK_FILE_CHOOSER_ACTION_OPEN :
GTK_FILE_CHOOSER_ACTION_SAVE,
gtk_window_set_transient_for (GTK_WINDOW (file_dlg), GTK_WINDOW (parent));
gtk_window_set_destroy_with_parent (GTK_WINDOW (file_dlg), TRUE);
GTK_STOCK_CANCEL, GTK_STOCK_CANCEL,
load_save ?
GTK_STOCK_OPEN : GTK_STOCK_SAVE,
GTK_RESPONSE_OK,
gtk_window_set_position (GTK_WINDOW (file_dlg), GTK_WIN_POS_MOUSE);
NULL);
g_object_add_weak_pointer (G_OBJECT (file_dlg), (gpointer *) &file_dlg);
gtk_dialog_set_default_response (GTK_DIALOG (file_dlg), GTK_RESPONSE_OK);
gtk_window_set_destroy_with_parent (GTK_WINDOW (file_dlg), TRUE);
g_signal_connect (file_dlg, "delete_event",
G_CALLBACK (gtk_true),
......@@ -736,42 +750,28 @@ load_callback (GtkWidget *widget,
{
if (! file_dlg)
{
make_file_dlg (gtk_widget_get_toplevel (widget));
}
else
{
if (GTK_WIDGET_VISIBLE (file_dlg))
{
gtk_window_present (GTK_WINDOW (file_dlg));
return;
}
load_save = 1;
make_file_dlg (_("Load Flame"), gtk_widget_get_toplevel (widget));
gtk_widget_set_sensitive (save_button, FALSE);
}
gtk_window_set_title (GTK_WINDOW (file_dlg), _("Load Flame"));
load_save = 1;
gtk_widget_set_sensitive (save_button, FALSE);
gtk_widget_show (file_dlg);
gtk_window_present (GTK_WINDOW (file_dlg));
}
static void
save_callback (GtkWidget *widget,
gpointer data)
{
if (!file_dlg)
{
make_file_dlg (gtk_widget_get_toplevel (widget));
}
else
if (! file_dlg)
{
if (GTK_WIDGET_VISIBLE (file_dlg))
{
gtk_window_present (GTK_WINDOW (file_dlg));
return;
}
load_save = 0;
make_file_dlg (_("Save Flame"), gtk_widget_get_toplevel (widget));
gtk_widget_set_sensitive (load_button, FALSE);
}
gtk_window_set_title (GTK_WINDOW (file_dlg), _("Save Flame"));
load_save = 0;
gtk_widget_set_sensitive (load_button, FALSE);
gtk_widget_show (file_dlg);
gtk_window_present (GTK_WINDOW (file_dlg));
}
static void
......
......@@ -1072,31 +1072,18 @@ gfig_save_callbk (void)
}
static void
file_selection_response (GtkFileSelection *fs,
gint response_id,
GFigObj *obj)
file_chooser_response (GtkFileChooser *chooser,
gint response_id,
GFigObj *obj)
{
if (response_id == GTK_RESPONSE_OK)
{
const gchar *filenamebuf;
GFigObj *real_current;
gchar *filename;
GFigObj *real_current;
filenamebuf = gtk_file_selection_get_filename (fs);
filename = gtk_file_chooser_get_filename (chooser);
/* Get the name */
if (strlen (filenamebuf) == 0)
{
g_message ("Save: No filename given");
return;
}
if (g_file_test (filenamebuf, G_FILE_TEST_IS_DIR))
{
g_message (_("Cannot save to a folder."));
return;
}
obj->filename = g_strdup (filenamebuf);
obj->filename = filename;
real_current = current_obj;
current_obj = obj;
......@@ -1104,34 +1091,39 @@ file_selection_response (GtkFileSelection *fs,
current_obj = current_obj;
}
gtk_widget_destroy (GTK_WIDGET (fs));
gtk_widget_destroy (GTK_WIDGET (chooser));
}
static void
create_file_selection (GFigObj *obj,
gchar *tpath,
GtkWidget *parent)
create_save_file_chooser (GFigObj *obj,
gchar *tpath,
GtkWidget *parent)
{
static GtkWidget *window = NULL;
if (!window)
if (! window)
{
window = gtk_file_selection_new (_("Save Gfig Drawing"));
window =
gtk_file_chooser_dialog_new (_("Save Gfig Drawing"),
GTK_WINDOW (parent),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (parent));
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
NULL);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
g_signal_connect (window, "response",
G_CALLBACK (file_selection_response),
G_CALLBACK (file_chooser_response),
obj);
}
if (tpath)
{
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), tpath);
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (window), tpath);
}
else if (gfig_path)
{
......@@ -1145,7 +1137,7 @@ create_file_selection (GFigObj *obj,
if (! dir)
dir = g_strdup (gimp_directory ());
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), dir);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (window), dir);
g_free (dir);
}
......@@ -1153,7 +1145,7 @@ create_file_selection (GFigObj *obj,
{
const gchar *tmp = g_get_tmp_dir ();
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), tmp);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (window), tmp);
}
gtk_window_present (GTK_WINDOW (window));
......@@ -1165,7 +1157,7 @@ gfig_save (GtkWidget *parent)
/* Save the current object */
if (!current_obj->filename)
{
create_file_selection (current_obj, NULL, parent);
create_save_file_chooser (current_obj, NULL, parent);
return;
}
gfig_save_callbk ();
......@@ -3386,17 +3378,17 @@ list_button_update (GFigObj *obj)
static void
gfig_load_file_selection_response (GtkFileSelection *fs,
gint response_id,
gpointer data)
gfig_load_file_chooser_response (GtkFileChooser *chooser,
gint response_id,
gpointer data)
{
if (response_id == GTK_RESPONSE_OK)
{
const gchar *filename;
GFigObj *gfig;
GFigObj *current_saved;
gchar *filename;
GFigObj *gfig;
GFigObj *current_saved;
filename = gtk_file_selection_get_filename (fs);
filename = gtk_file_chooser_get_filename (chooser);
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
......@@ -3418,9 +3410,11 @@ gfig_load_file_selection_response (GtkFileSelection *fs,
new_obj_2edit (gfig);
}
}
g_free (filename);
}
gtk_widget_destroy (GTK_WIDGET (fs));
gtk_widget_destroy (GTK_WIDGET (chooser));
}
static void
......@@ -3430,17 +3424,22 @@ load_button_callback (GtkWidget *widget,
static GtkWidget *window = NULL;
/* Load a single object */
window = gtk_file_selection_new (_("Load Gfig object collection"));
window = gtk_file_chooser_dialog_new (_("Load Gfig object collection"),
GTK_WINDOW (gtk_widget_get_toplevel (widget)),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
gtk_window_set_transient_for (GTK_WINDOW (window),
GTK_WINDOW (gtk_widget_get_toplevel (widget)));
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
gtk_dialog_set_default_response (GTK_DIALOG (window), GTK_RESPONSE_OK);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
g_signal_connect (window, "response",
G_CALLBACK (gfig_load_file_selection_response),
G_CALLBACK (gfig_load_file_chooser_response),
window);
gtk_widget_show (window);
......@@ -3970,8 +3969,8 @@ static void
gfig_rename_menu_callback (GtkWidget *widget,
gpointer data)
{
create_file_selection (gfig_obj_for_menu, gfig_obj_for_menu->filename,
gtk_widget_get_toplevel (widget));
create_save_file_chooser (gfig_obj_for_menu, gfig_obj_for_menu->filename,
gtk_widget_get_toplevel (widget));
}
static void
......
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