Revision 3258 src/filesel.c

View differences:

filesel.c
47 47
					 const gchar		*file,
48 48
					 GtkFileChooserAction	 action,
49 49
					 gboolean		 multiple,
50
					 GSList			*types,
50
					 FileselFileType	*types,
51 51
					 gint			 default_type,
52 52
					 gint			*selected_type);
53 53

  
......
58 58
						    gboolean	 expanded);
59 59
static gboolean filesel_save_expander_get_expanded (GtkWidget	*dialog);
60 60

  
61
static void filesel_combo_changed_cb	(GtkComboBox		*combo_box,
62
					 gpointer		 data);
63

  
61 64
#if GTK_CHECK_VERSION(2, 8, 0)
62 65
static GtkFileChooserConfirmation filesel_confirm_overwrite_cb
63 66
					(GtkFileChooser		*chooser,
......
160 163
static GSList *filesel_select_file_full(const gchar *title, const gchar *file,
161 164
					GtkFileChooserAction action,
162 165
					gboolean multiple,
163
					GSList *types,
166
					FileselFileType *types,
164 167
					gint default_type, gint *selected_type)
165 168
{
166 169
	gchar *cwd;
......
202 205

  
203 206
	/* create types combo box */
204 207
	if (types) {
205
		GSList *cur;
206 208
		GtkWidget *hbox;
207 209
		GtkWidget *label;
210
		gint i;
208 211

  
209 212
		hbox = gtk_hbox_new(FALSE, 12);
210 213
		label = gtk_label_new(_("File type:"));
211 214
		gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
212 215

  
213 216
		combo = gtk_combo_box_new_text();
214
		for (cur = types; cur != NULL; cur = cur->next) {
215
			gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *)cur->data);
217
		for (i = 0; types[i].type != NULL; i++) {
218
			gtk_combo_box_append_text(GTK_COMBO_BOX(combo), types[i].type);
216 219
		}
217 220
		gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
218 221

  
219 222
		gtk_widget_show_all(hbox);
220 223
		gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), hbox);
221 224
		gtk_combo_box_set_active(GTK_COMBO_BOX(combo), default_type);
225

  
226
		g_object_set_data(G_OBJECT(combo), "types", types);
227
		g_signal_connect(GTK_COMBO_BOX(combo), "changed",
228
				 G_CALLBACK(filesel_combo_changed_cb), dialog);
222 229
	}
223 230

  
224 231
	gtk_widget_show(dialog);
......
296 303
	return filename;
297 304
}
298 305

  
299
gchar *filesel_save_as_type(const gchar *file, GSList *types,
306
gchar *filesel_save_as_type(const gchar *file, FileselFileType *types,
300 307
			    gint default_type, gint *selected_type)
301 308
{
302 309
	GSList *list;
......
304 311

  
305 312
	list = filesel_select_file_full(_("Save as"), file,
306 313
					GTK_FILE_CHOOSER_ACTION_SAVE, FALSE,
307
					types, default_type, selected_type);
314
					types,
315
					default_type, selected_type);
308 316
	if (list) {
309 317
		filename = (gchar *)list->data;
310 318
		slist_free_strings(list->next);
......
415 423
		return FALSE;
416 424
}
417 425

  
426
static void filesel_combo_changed_cb(GtkComboBox *combo_box, gpointer data)
427
{
428
	GtkFileChooser *chooser = data;
429
	gint active;
430
	gchar *filename;
431
	gchar *base;
432
	gchar *new_filename;
433
	gchar *p;
434
	FileselFileType *types;
435

  
436
	active = gtk_combo_box_get_active(combo_box);
437
	filename = gtk_file_chooser_get_filename(chooser);
438
	types = g_object_get_data(G_OBJECT(combo_box), "types");
439
	g_print("active: %d filename: %s\n", active, filename);
440
	g_print("type ext: %s\n", types[active].ext);
441
	base = g_path_get_basename(filename);
442
	p = strrchr(base, '.');
443
	if (p)
444
		*p = '\0';
445
	new_filename = g_strconcat(base, ".", types[active].ext, NULL);
446
	g_print("new_filename: %s\n", new_filename);
447
	gtk_file_chooser_set_current_name(chooser, new_filename);
448
	g_free(new_filename);
449
	g_free(base);
450
	g_free(filename);
451
}
452

  
418 453
#if GTK_CHECK_VERSION(2, 8, 0)
419 454
static GtkFileChooserConfirmation filesel_confirm_overwrite_cb
420 455
					(GtkFileChooser		*chooser,

Also available in: Unified diff