Commit ab6bc6dc8daec59f27bbed446ebe38b08dcee824
1 parent
a282480c
Exists in
master
and in
5 other branches
Implementando ação pastefile em windows
Showing
1 changed file
with
112 additions
and
6 deletions
Show diff stats
src/gtk/dialog.c
| ... | ... | @@ -132,12 +132,6 @@ |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - void paste_file_action(GtkAction *action, GtkWidget *widget) | |
| 136 | - { | |
| 137 | - trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); | |
| 138 | - | |
| 139 | - } | |
| 140 | - | |
| 141 | 135 | void hostname_action(GtkAction *action, GtkWidget *widget) |
| 142 | 136 | { |
| 143 | 137 | const gchar * title = g_object_get_data(G_OBJECT(action),"title"); |
| ... | ... | @@ -281,3 +275,115 @@ |
| 281 | 275 | N_( "Can't save copy to file\n%s" ), |
| 282 | 276 | v3270_get_copy(widget)); |
| 283 | 277 | } |
| 278 | + | |
| 279 | + static void paste_filename(GtkWidget *widget, const gchar *filename, const gchar *encoding) | |
| 280 | + { | |
| 281 | + GError *error = NULL; | |
| 282 | + gchar *text = NULL; | |
| 283 | + | |
| 284 | + trace("Loading \"%s\"",filename); | |
| 285 | + | |
| 286 | + if(!g_file_get_contents(filename,&text,NULL,&error)) | |
| 287 | + { | |
| 288 | + GtkWidget *popup = gtk_message_dialog_new_with_markup( | |
| 289 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
| 290 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 291 | + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, | |
| 292 | + _( "Error loading %s" ),filename); | |
| 293 | + | |
| 294 | + gtk_window_set_title(GTK_WINDOW(popup),_("Can´t load file")); | |
| 295 | + | |
| 296 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",error->message); | |
| 297 | + g_error_free(error); | |
| 298 | + | |
| 299 | + gtk_dialog_run(GTK_DIALOG(popup)); | |
| 300 | + gtk_widget_destroy(popup); | |
| 301 | + | |
| 302 | + } | |
| 303 | + | |
| 304 | + if(text) | |
| 305 | + { | |
| 306 | + v3270_paste_string(widget,text,encoding); | |
| 307 | + g_free(text); | |
| 308 | + } | |
| 309 | + | |
| 310 | + } | |
| 311 | + | |
| 312 | + static void add_encoding(GtkWidget *widget, const gchar **attr) | |
| 313 | + { | |
| 314 | +// GtkWidget *box; | |
| 315 | +// GtkWidget *combo; | |
| 316 | + const gchar **charset = NULL; | |
| 317 | +// int f; | |
| 318 | + | |
| 319 | + if(g_get_filename_charsets(&charset)) | |
| 320 | + { | |
| 321 | + *attr = "UTF-8"; | |
| 322 | + return; | |
| 323 | + } | |
| 324 | + | |
| 325 | +#ifdef WIN32 | |
| 326 | + | |
| 327 | + #warning Confirmar necessidade em windows | |
| 328 | + | |
| 329 | + box = gtk_hbox_new(FALSE,2); | |
| 330 | + combo = gtk_combo_box_text_new(); | |
| 331 | + | |
| 332 | + gtk_box_pack_start(GTK_BOX(box),gtk_label_new(_("Encoding:")),FALSE,FALSE,0); | |
| 333 | + gtk_box_pack_start(GTK_BOX(box),combo,FALSE,FALSE,0); | |
| 334 | + | |
| 335 | + gtk_widget_show_all(box); | |
| 336 | + gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(widget),box); | |
| 337 | + | |
| 338 | +#endif | |
| 339 | +} | |
| 340 | + | |
| 341 | + void paste_file_action(GtkAction *action, GtkWidget *widget) | |
| 342 | + { | |
| 343 | + const gchar * user_title = g_object_get_data(G_OBJECT(action),"title"); | |
| 344 | + const gchar * filename = g_object_get_data(G_OBJECT(action),"filename"); | |
| 345 | + const gchar * encattr = g_object_get_data(G_OBJECT(action),"encoding"); | |
| 346 | + GtkWidget * dialog; | |
| 347 | + gchar * ptr; | |
| 348 | + | |
| 349 | + trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); | |
| 350 | + | |
| 351 | + if(filename) | |
| 352 | + { | |
| 353 | + paste_filename(widget,filename,encattr ? encattr : "UTF-8"); | |
| 354 | + return; | |
| 355 | + } | |
| 356 | + | |
| 357 | + dialog = gtk_file_chooser_dialog_new( gettext(user_title ? user_title : N_( "Paste text file contents" )), | |
| 358 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
| 359 | + GTK_FILE_CHOOSER_ACTION_OPEN, | |
| 360 | + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
| 361 | + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | |
| 362 | + NULL ); | |
| 363 | + | |
| 364 | + if(!encattr) | |
| 365 | + add_encoding(dialog, &encattr); | |
| 366 | + | |
| 367 | + ptr = get_string_from_config("load",gtk_action_get_name(action),""); | |
| 368 | + if(*ptr) | |
| 369 | + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),ptr); | |
| 370 | + g_free(ptr); | |
| 371 | + | |
| 372 | + if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) | |
| 373 | + { | |
| 374 | + gtk_widget_destroy(dialog); | |
| 375 | + return; | |
| 376 | + } | |
| 377 | + | |
| 378 | + ptr = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
| 379 | + | |
| 380 | + gtk_widget_destroy(dialog); | |
| 381 | + | |
| 382 | + if(ptr) | |
| 383 | + { | |
| 384 | + set_string_to_config("load",gtk_action_get_name(action),"%s",ptr); | |
| 385 | + paste_filename(widget,ptr,encattr); | |
| 386 | + g_free(ptr); | |
| 387 | + } | |
| 388 | + } | |
| 389 | + | ... | ... |