Commit ee2cbb44 authored by Manish Singh's avatar Manish Singh Committed by Manish Singh

use new GtkFileSelection multiselect API.

2002-02-16  Manish Singh  <yosh@gimp.org>

        * app/gui/file-open-dialog.c: use new GtkFileSelection multiselect
        API.
parent 72284d38
2002-02-16 Manish Singh <yosh@gimp.org>
* app/gui/file-open-dialog.c: use new GtkFileSelection multiselect
API.
2002-02-15 Michael Natterer <mitch@gimp.org> 2002-02-15 Michael Natterer <mitch@gimp.org>
* app/display/gimpdisplayshell-handlers.c: added back the handler * app/display/gimpdisplayshell-handlers.c: added back the handler
......
...@@ -79,7 +79,6 @@ static void file_open_ok_callback (GtkWidget *widget, ...@@ -79,7 +79,6 @@ static void file_open_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void file_open_type_callback (GtkWidget *widget, static void file_open_type_callback (GtkWidget *widget,
gpointer data); gpointer data);
static GSList * tvsel_to_slist (GtkTreeView *file_list);
...@@ -205,13 +204,9 @@ file_open_dialog_create (Gimp *gimp) ...@@ -205,13 +204,9 @@ file_open_dialog_create (Gimp *gimp)
gtk_quit_add_destroy (1, GTK_OBJECT (fileload)); gtk_quit_add_destroy (1, GTK_OBJECT (fileload));
gtk_file_selection_set_select_multiple (GTK_FILE_SELECTION (fileload), TRUE);
tree_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (GTK_FILE_SELECTION (fileload)->file_list)); tree_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (GTK_FILE_SELECTION (fileload)->file_list));
/* disabled until fixed in GTK+
*
* gtk_tree_selection_set_mode (tree_sel, GTK_SELECTION_MULTIPLE);
*/
/* Catch file-list clicks so we can update the preview thumbnail */ /* Catch file-list clicks so we can update the preview thumbnail */
g_signal_connect (G_OBJECT (tree_sel), "changed", g_signal_connect (G_OBJECT (tree_sel), "changed",
G_CALLBACK (file_open_selchanged_callback), G_CALLBACK (file_open_selchanged_callback),
...@@ -606,12 +601,13 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -606,12 +601,13 @@ file_open_genbutton_callback (GtkWidget *widget,
Gimp *gimp; Gimp *gimp;
/* added for multi-file preview generation... */ /* added for multi-file preview generation... */
GtkFileSelection *fs; GtkFileSelection *fs;
gchar *full_filename = NULL; gchar *full_filename = NULL;
gchar *dirname = NULL; gchar *raw_filename = NULL;
struct stat buf; struct stat buf;
gint err; gint err;
GSList *list, *toplist; gchar **selections;
gint i;
fs = GTK_FILE_SELECTION (data); fs = GTK_FILE_SELECTION (data);
...@@ -628,16 +624,11 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -628,16 +624,11 @@ file_open_genbutton_callback (GtkWidget *widget,
/* new mult-file preview make: */ /* new mult-file preview make: */
/* Have to read the list before touching anything else */ selections = gtk_file_selection_get_selections (fs);
toplist = tvsel_to_slist (GTK_TREE_VIEW (fs->file_list));
dirname = g_path_get_dirname (gtk_file_selection_get_filename (fs)); for (i = 0; selections[i] != NULL; i++)
for (list= toplist; list; list = g_slist_next (list))
{ {
full_filename = g_build_filename (dirname, full_filename = selections[i];
(gchar *) list->data,
NULL);
err = stat (full_filename, &buf); err = stat (full_filename, &buf);
...@@ -646,13 +637,15 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -646,13 +637,15 @@ file_open_genbutton_callback (GtkWidget *widget,
/* Is not directory. */ /* Is not directory. */
GimpPDBStatusType dummy; GimpPDBStatusType dummy;
raw_filename = g_path_get_basename (full_filename);
gimage_to_be_thumbed = file_open_image (gimp, gimage_to_be_thumbed = file_open_image (gimp,
full_filename, full_filename,
list->data, raw_filename,
NULL, NULL,
NULL, NULL,
GIMP_RUN_NONINTERACTIVE, GIMP_RUN_NONINTERACTIVE,
&dummy); &dummy);
g_free (raw_filename);
if (gimage_to_be_thumbed) if (gimage_to_be_thumbed)
{ {
...@@ -682,13 +675,7 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -682,13 +675,7 @@ file_open_genbutton_callback (GtkWidget *widget,
} }
} }
g_free (full_filename); g_strfreev (selections);
for (list = toplist; list; list = g_slist_next (list))
g_free (list->data);
g_slist_free (toplist);
g_free (dirname);
gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE);
gimp_unset_busy (gimp); gimp_unset_busy (gimp);
...@@ -698,28 +685,28 @@ static void ...@@ -698,28 +685,28 @@ static void
file_open_ok_callback (GtkWidget *widget, file_open_ok_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
GtkFileSelection *fs; GtkFileSelection *fs;
Gimp *gimp; Gimp *gimp;
gchar *full_filename; gchar *full_filename;
gchar *raw_filename; gchar *raw_filename;
gchar *dirname; struct stat buf;
struct stat buf; gint err;
gint err; GimpPDBStatusType status;
GimpPDBStatusType status; gchar **selections;
GSList *list; gint i;
fs = GTK_FILE_SELECTION (data); fs = GTK_FILE_SELECTION (data);
gimp = GIMP (g_object_get_data (G_OBJECT (fs), "gimp")); gimp = GIMP (g_object_get_data (G_OBJECT (fs), "gimp"));
full_filename = g_strdup (gtk_file_selection_get_filename (fs)); selections = gtk_file_selection_get_selections (fs);
raw_filename = g_strdup (gtk_entry_get_text (GTK_ENTRY(fs->selection_entry)));
g_assert (full_filename && raw_filename); if (selections == NULL)
if (strlen (raw_filename) == 0)
return; return;
full_filename = selections[0];
raw_filename = g_strdup (gtk_entry_get_text (GTK_ENTRY(fs->selection_entry)));
err = stat (full_filename, &buf); err = stat (full_filename, &buf);
if (err == 0 && (buf.st_mode & S_IFDIR)) if (err == 0 && (buf.st_mode & S_IFDIR))
...@@ -735,6 +722,9 @@ file_open_ok_callback (GtkWidget *widget, ...@@ -735,6 +722,9 @@ file_open_ok_callback (GtkWidget *widget,
gtk_file_selection_set_filename (fs, full_filename); gtk_file_selection_set_filename (fs, full_filename);
} }
g_free (raw_filename);
g_strfreev (selections);
return; return;
} }
...@@ -758,84 +748,41 @@ file_open_ok_callback (GtkWidget *widget, ...@@ -758,84 +748,41 @@ file_open_ok_callback (GtkWidget *widget,
g_message (_("Opening '%s' failed."), full_filename); g_message (_("Opening '%s' failed."), full_filename);
} }
/* /*
* Now deal with multiple selections from the filesel list * Now deal with multiple selections from the filesel list
*/ */
/* Have to read the list before touching anything else */ for (i = 1; selections[i] != NULL; i++)
list = tvsel_to_slist (GTK_TREE_VIEW (fs->file_list));
raw_filename = g_strdup (raw_filename);
dirname = g_path_get_dirname (full_filename);
while (list)
{ {
g_free (full_filename); full_filename = selections[i];
full_filename = g_build_filename (dirname, g_free (raw_filename);
(gchar *) list->data, NULL); raw_filename = g_path_get_basename (full_filename);
if (strcmp (list->data, raw_filename)) err = stat (full_filename, &buf);
{ /* don't load current selection twice */
err = stat (full_filename, &buf);
if (! (err == 0 && (buf.st_mode & S_IFDIR))) if (! (err == 0 && (buf.st_mode & S_IFDIR)))
{ /* Is not directory. */ { /* Is not directory. */
status = file_open_with_proc_and_display (gimp, status = file_open_with_proc_and_display (gimp,
full_filename, full_filename,
(const gchar *) list->data, raw_filename,
load_file_proc); load_file_proc);
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
file_dialog_hide (data); file_dialog_hide (data);
} }
else if (status != GIMP_PDB_CANCEL) else if (status != GIMP_PDB_CANCEL)
{ {
/* same as previous. --bex */ /* same as previous. --bex */
g_message (_("Opening '%s' failed."), full_filename); g_message (_("Opening '%s' failed."), full_filename);
} }
} }
}
g_free (list->data);
list = g_slist_next (list);
} }
g_slist_free (list);
g_free (dirname);
g_free (full_filename);
g_free (raw_filename); g_free (raw_filename);
g_strfreev (selections);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
} }
static void
tvsel_to_slist_helper (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data)
{
GSList **list = data;
gchar *filename;
gtk_tree_model_get (model, iter, 0, &filename, -1);
*list = g_slist_prepend (*list, filename);
}
static GSList *
tvsel_to_slist (GtkTreeView *file_list)
{
GtkTreeSelection *sel;
GSList *list = NULL;
sel = gtk_tree_view_get_selection (file_list);
gtk_tree_selection_selected_foreach (sel, tvsel_to_slist_helper, &list);
return list;
}
...@@ -79,7 +79,6 @@ static void file_open_ok_callback (GtkWidget *widget, ...@@ -79,7 +79,6 @@ static void file_open_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void file_open_type_callback (GtkWidget *widget, static void file_open_type_callback (GtkWidget *widget,
gpointer data); gpointer data);
static GSList * tvsel_to_slist (GtkTreeView *file_list);
...@@ -205,13 +204,9 @@ file_open_dialog_create (Gimp *gimp) ...@@ -205,13 +204,9 @@ file_open_dialog_create (Gimp *gimp)
gtk_quit_add_destroy (1, GTK_OBJECT (fileload)); gtk_quit_add_destroy (1, GTK_OBJECT (fileload));
gtk_file_selection_set_select_multiple (GTK_FILE_SELECTION (fileload), TRUE);
tree_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (GTK_FILE_SELECTION (fileload)->file_list)); tree_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (GTK_FILE_SELECTION (fileload)->file_list));
/* disabled until fixed in GTK+
*
* gtk_tree_selection_set_mode (tree_sel, GTK_SELECTION_MULTIPLE);
*/
/* Catch file-list clicks so we can update the preview thumbnail */ /* Catch file-list clicks so we can update the preview thumbnail */
g_signal_connect (G_OBJECT (tree_sel), "changed", g_signal_connect (G_OBJECT (tree_sel), "changed",
G_CALLBACK (file_open_selchanged_callback), G_CALLBACK (file_open_selchanged_callback),
...@@ -606,12 +601,13 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -606,12 +601,13 @@ file_open_genbutton_callback (GtkWidget *widget,
Gimp *gimp; Gimp *gimp;
/* added for multi-file preview generation... */ /* added for multi-file preview generation... */
GtkFileSelection *fs; GtkFileSelection *fs;
gchar *full_filename = NULL; gchar *full_filename = NULL;
gchar *dirname = NULL; gchar *raw_filename = NULL;
struct stat buf; struct stat buf;
gint err; gint err;
GSList *list, *toplist; gchar **selections;
gint i;
fs = GTK_FILE_SELECTION (data); fs = GTK_FILE_SELECTION (data);
...@@ -628,16 +624,11 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -628,16 +624,11 @@ file_open_genbutton_callback (GtkWidget *widget,
/* new mult-file preview make: */ /* new mult-file preview make: */
/* Have to read the list before touching anything else */ selections = gtk_file_selection_get_selections (fs);
toplist = tvsel_to_slist (GTK_TREE_VIEW (fs->file_list));
dirname = g_path_get_dirname (gtk_file_selection_get_filename (fs)); for (i = 0; selections[i] != NULL; i++)
for (list= toplist; list; list = g_slist_next (list))
{ {
full_filename = g_build_filename (dirname, full_filename = selections[i];
(gchar *) list->data,
NULL);
err = stat (full_filename, &buf); err = stat (full_filename, &buf);
...@@ -646,13 +637,15 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -646,13 +637,15 @@ file_open_genbutton_callback (GtkWidget *widget,
/* Is not directory. */ /* Is not directory. */
GimpPDBStatusType dummy; GimpPDBStatusType dummy;
raw_filename = g_path_get_basename (full_filename);
gimage_to_be_thumbed = file_open_image (gimp, gimage_to_be_thumbed = file_open_image (gimp,
full_filename, full_filename,
list->data, raw_filename,
NULL, NULL,
NULL, NULL,
GIMP_RUN_NONINTERACTIVE, GIMP_RUN_NONINTERACTIVE,
&dummy); &dummy);
g_free (raw_filename);
if (gimage_to_be_thumbed) if (gimage_to_be_thumbed)
{ {
...@@ -682,13 +675,7 @@ file_open_genbutton_callback (GtkWidget *widget, ...@@ -682,13 +675,7 @@ file_open_genbutton_callback (GtkWidget *widget,
} }
} }
g_free (full_filename); g_strfreev (selections);
for (list = toplist; list; list = g_slist_next (list))
g_free (list->data);
g_slist_free (toplist);
g_free (dirname);
gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE);
gimp_unset_busy (gimp); gimp_unset_busy (gimp);
...@@ -698,28 +685,28 @@ static void ...@@ -698,28 +685,28 @@ static void
file_open_ok_callback (GtkWidget *widget, file_open_ok_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
GtkFileSelection *fs; GtkFileSelection *fs;
Gimp *gimp; Gimp *gimp;
gchar *full_filename; gchar *full_filename;
gchar *raw_filename; gchar *raw_filename;
gchar *dirname; struct stat buf;
struct stat buf; gint err;
gint err; GimpPDBStatusType status;
GimpPDBStatusType status; gchar **selections;
GSList *list; gint i;
fs = GTK_FILE_SELECTION (data); fs = GTK_FILE_SELECTION (data);
gimp = GIMP (g_object_get_data (G_OBJECT (fs), "gimp")); gimp = GIMP (g_object_get_data (G_OBJECT (fs), "gimp"));
full_filename = g_strdup (gtk_file_selection_get_filename (fs)); selections = gtk_file_selection_get_selections (fs);
raw_filename = g_strdup (gtk_entry_get_text (GTK_ENTRY(fs->selection_entry)));
g_assert (full_filename && raw_filename); if (selections == NULL)
if (strlen (raw_filename) == 0)
return; return;
full_filename = selections[0];
raw_filename = g_strdup (gtk_entry_get_text (GTK_ENTRY(fs->selection_entry)));
err = stat (full_filename, &buf); err = stat (full_filename, &buf);
if (err == 0 && (buf.st_mode & S_IFDIR)) if (err == 0 && (buf.st_mode & S_IFDIR))
...@@ -735,6 +722,9 @@ file_open_ok_callback (GtkWidget *widget, ...@@ -735,6 +722,9 @@ file_open_ok_callback (GtkWidget *widget,
gtk_file_selection_set_filename (fs, full_filename); gtk_file_selection_set_filename (fs, full_filename);
} }
g_free (raw_filename);
g_strfreev (selections);
return; return;
} }
...@@ -758,84 +748,41 @@ file_open_ok_callback (GtkWidget *widget, ...@@ -758,84 +748,41 @@ file_open_ok_callback (GtkWidget *widget,
g_message (_("Opening '%s' failed."), full_filename); g_message (_("Opening '%s' failed."), full_filename);
} }
/* /*
* Now deal with multiple selections from the filesel list * Now deal with multiple selections from the filesel list
*/ */
/* Have to read the list before touching anything else */ for (i = 1; selections[i] != NULL; i++)
list = tvsel_to_slist (GTK_TREE_VIEW (fs->file_list));
raw_filename = g_strdup (raw_filename);
dirname = g_path_get_dirname (full_filename);
while (list)
{ {
g_free (full_filename); full_filename = selections[i];
full_filename = g_build_filename (dirname, g_free (raw_filename);
(gchar *) list->data, NULL); raw_filename = g_path_get_basename (full_filename);
if (strcmp (list->data, raw_filename)) err = stat (full_filename, &buf);
{ /* don't load current selection twice */
err = stat (full_filename, &buf);
if (! (err == 0 && (buf.st_mode & S_IFDIR))) if (! (err == 0 && (buf.st_mode & S_IFDIR)))
{ /* Is not directory. */ { /* Is not directory. */
status = file_open_with_proc_and_display (gimp, status = file_open_with_proc_and_display (gimp,
full_filename, full_filename,
(const gchar *) list->data, raw_filename,
load_file_proc); load_file_proc);
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
file_dialog_hide (data); file_dialog_hide (data);
} }
else if (status != GIMP_PDB_CANCEL) else if (status != GIMP_PDB_CANCEL)
{ {
/* same as previous. --bex */ /* same as previous. --bex */
g_message (_("Opening '%s' failed."), full_filename); g_message (_("Opening '%s' failed."), full_filename);
} }
} }
}
g_free (list->data);
list = g_slist_next (list);
} }
g_slist_free (list);
g_free (dirname);
g_free (full_filename);
g_free (raw_filename); g_free (raw_filename);
g_strfreev (selections);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
} }
static void
tvsel_to_slist_helper (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data)
{
GSList **list = data;
gchar *filename;
gtk_tree_model_get (model, iter, 0, &filename, -1);
*list = g_slist_prepend (*list, filename);
}
static GSList *
tvsel_to_slist (GtkTreeView *file_list)
{
GtkTreeSelection *sel;
GSList *list = NULL;
sel = gtk_tree_view_get_selection (file_list);
gtk_tree_selection_selected_foreach (sel, tvsel_to_slist_helper, &list);
return list;
}
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