' Filesel.bas
' Translated from C to FB by TinyCla, 2006
'
' Reviewed by TJF (2011-2014)
' Details: http://developer.gnome.org/gtk/

'#INCLUDE ONCE "Gir/Gtk-3.0.bi"
#INCLUDE ONCE "Gir/Gtk-2.0.bi"
#INCLUDE ONCE "Gir/_GObjectMacros-2.0.bi"

' Get the selected filename and print it to the console
Sub file_ok_sel Cdecl ( Byval w As GtkWidget Ptr, Byval FiSe As GtkFileSelection Ptr )

  var file_name = gtk_file_selection_get_filename (GTK_FILE_SELECTION (FiSe))
  Print *file_name

End Sub


' ==============================================
' Main
' ==============================================

' Initialize the toolkit
gtk_init(@__FB_ARGC__, @__FB_ARGV__)

' Create a new file selection widget
var filew = gtk_file_selection_new ("File selection")

g_signal_connect (G_OBJECT (filew), "destroy", G_CALLBACK (@gtk_main_quit), NULL)

' Connect the ok_button to file_ok_sel function
g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), "clicked", G_CALLBACK (@file_ok_sel), filew)

' Connect the cancel_button to destroy the widget
g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), "clicked", G_CALLBACK (@gtk_widget_destroy), G_OBJECT (filew))

' Lets set the filename, as if this were a save dialog, and we are giving a default filename
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),  "penguin.png")

gtk_widget_show (filew)
gtk_main ()
