Revision 3259 src/filesel.c

View differences:

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

  
61
static gchar *filesel_get_filename_with_ext	(const gchar	*filename,
62
						 const gchar	*ext);
63

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

  
......
221 224

  
222 225
		gtk_widget_show_all(hbox);
223 226
		gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), hbox);
227
		if (default_type < 0 || default_type >= i)
228
			default_type = 0;
224 229
		gtk_combo_box_set_active(GTK_COMBO_BOX(combo), default_type);
225

  
226 230
		g_object_set_data(G_OBJECT(combo), "types", types);
227 231
		g_signal_connect(GTK_COMBO_BOX(combo), "changed",
228 232
				 G_CALLBACK(filesel_combo_changed_cb), dialog);
233

  
234
		if (file) {
235
			gchar *newfile;
236

  
237
			newfile = filesel_get_filename_with_ext
238
				(file, types[default_type].ext);
239
			gtk_file_chooser_set_current_name
240
				(GTK_FILE_CHOOSER(dialog), newfile);
241
			g_free(newfile);
242
		}
229 243
	}
230 244

  
231 245
	gtk_widget_show(dialog);
......
423 437
		return FALSE;
424 438
}
425 439

  
440
static gchar *filesel_get_filename_with_ext(const gchar *filename, const gchar *ext)
441
{
442
	gchar *base;
443
	gchar *new_filename;
444
	gchar *p;
445

  
446
	base = g_path_get_basename(filename);
447
	p = strrchr(base, '.');
448
	if (p)
449
		*p = '\0';
450
	new_filename = g_strconcat(base, ".", ext, NULL);
451
	debug_print("new_filename: %s\n", new_filename);
452
	g_free(base);
453

  
454
	return new_filename;
455
}
456

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

  
436 465
	active = gtk_combo_box_get_active(combo_box);
437 466
	filename = gtk_file_chooser_get_filename(chooser);
467
	if (!filename)
468
		return;
438 469
	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);
470
	debug_print("active: %d filename: %s\n", active, filename);
471
	debug_print("type ext: %s\n", types[active].ext);
472
	new_filename = filesel_get_filename_with_ext(filename, types[active].ext);
447 473
	gtk_file_chooser_set_current_name(chooser, new_filename);
448 474
	g_free(new_filename);
449
	g_free(base);
450 475
	g_free(filename);
451 476
}
452 477

  

Also available in: Unified diff