Commit f4cab8adba8b4717a0f46103ac181c625f09ea05

Authored by perry.werneck@gmail.com
1 parent f5ed8d1e

Melhorando o diálogo de pastefile

Showing 1 changed file with 26 additions and 21 deletions   Show diff stats
src/gtk/dialog.c
@@ -281,6 +281,9 @@ @@ -281,6 +281,9 @@
281 GError *error = NULL; 281 GError *error = NULL;
282 gchar *text = NULL; 282 gchar *text = NULL;
283 283
  284 + if(!encoding)
  285 + g_get_charset(&encoding);
  286 +
284 trace("Loading \"%s\" encoding=%s",filename,encoding); 287 trace("Loading \"%s\" encoding=%s",filename,encoding);
285 288
286 if(!g_file_get_contents(filename,&text,NULL,&error)) 289 if(!g_file_get_contents(filename,&text,NULL,&error))
@@ -309,15 +312,17 @@ @@ -309,15 +312,17 @@
309 312
310 } 313 }
311 314
312 - static void add_option_menus(GtkWidget *widget, GtkAction *action, const gchar **encoding) 315 + static void add_option_menus(GtkWidget *widget, GtkAction *action, gchar **encoding)
313 { 316 {
314 - GtkWidget *box = gtk_hbox_new(FALSE,6); 317 + GtkWidget *box = gtk_hbox_new(FALSE,6);
  318 + gchar *ptr = g_object_get_data(G_OBJECT(action),"encoding");
315 int f; 319 int f;
316 320
317 -// http://people.gnome.org/~icq/scan-build/report-KvV84s.html  
318 -  
319 - *encoding = g_object_get_data(G_OBJECT(action),"encoding");  
320 - if(!*encoding) 321 + if(ptr)
  322 + {
  323 + *encoding = g_strdup(ptr);
  324 + }
  325 + else
321 { 326 {
322 // Add charset options 327 // Add charset options
323 static const struct _list 328 static const struct _list
@@ -340,7 +345,7 @@ @@ -340,7 +345,7 @@
340 int p = 0; 345 int p = 0;
341 346
342 g_get_charset(&charset); 347 g_get_charset(&charset);
343 - *encoding = charset; 348 + *encoding = g_strdup(charset);
344 349
345 text = g_strdup_printf(_("Current (%s)"),charset); 350 text = g_strdup_printf(_("Current (%s)"),charset);
346 gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(menu),p,charset,text); 351 gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(menu),p,charset,text);
@@ -372,7 +377,7 @@ @@ -372,7 +377,7 @@
372 { 377 {
373 const gchar * user_title = g_object_get_data(G_OBJECT(action),"title"); 378 const gchar * user_title = g_object_get_data(G_OBJECT(action),"title");
374 const gchar * filename = g_object_get_data(G_OBJECT(action),"filename"); 379 const gchar * filename = g_object_get_data(G_OBJECT(action),"filename");
375 - const gchar * encattr; 380 + gchar * encattr = NULL;
376 GtkWidget * dialog; 381 GtkWidget * dialog;
377 gchar * ptr; 382 gchar * ptr;
378 383
@@ -380,7 +385,8 @@ @@ -380,7 +385,8 @@
380 385
381 if(filename) 386 if(filename)
382 { 387 {
383 - paste_filename(widget,filename,encattr ? encattr : "UTF-8"); 388 + ptr = g_object_get_data(G_OBJECT(action),"encoding");
  389 + paste_filename(widget,filename,ptr);
384 return; 390 return;
385 } 391 }
386 392
@@ -398,21 +404,20 @@ @@ -398,21 +404,20 @@
398 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),ptr); 404 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),ptr);
399 g_free(ptr); 405 g_free(ptr);
400 406
401 - if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) 407 + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
402 { 408 {
403 - gtk_widget_destroy(dialog);  
404 - return;  
405 - }  
406 -  
407 - ptr = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); 409 + ptr = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
408 410
  411 + if(ptr)
  412 + {
  413 + set_string_to_config("load",gtk_action_get_name(action),"%s",ptr);
  414 + paste_filename(widget,ptr,encattr);
  415 + g_free(ptr);
  416 + }
  417 + }
409 gtk_widget_destroy(dialog); 418 gtk_widget_destroy(dialog);
410 419
411 - if(ptr)  
412 - {  
413 - set_string_to_config("load",gtk_action_get_name(action),"%s",ptr);  
414 - paste_filename(widget,ptr,encattr);  
415 - g_free(ptr);  
416 - } 420 + if(encattr)
  421 + g_free(encattr);
417 } 422 }
418 423