[gtkada] More on File_Chooser_Dialog
Dmitry A. Kazakov
mailbox at dmitry-kazakov.de
Fri Dec 10 20:22:46 CET 2010
On Fri, 10 Dec 2010 08:09:29 -0600, you wrote:
> I wouldn't mind seeing a working example of File_Chooser_Dialog. I didn't
> notice before but what I have appear on my screen doesn't have buttons for
> Select and Cancel like the picture in the Gtk literature. It does have
> navigation buttons at the top to walk the directory path and "+" and "-"
> buttons on the shortcut window on the left but no way to actual select a
> file.
with Gtk.Window; use Gtk.Window;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Dialog; use Gtk.Dialog;
with Gtk.Box; use Gtk.Box;
with Gtk.Button; use Gtk.Button;
with Gtk.Label; use Gtk.Label;
with Gtk.File_Chooser_Dialog; use Gtk.File_Chooser_Dialog;
with Gtk.File_Chooser; use Gtk.File_Chooser;
with Gtk.Handlers;
with Gtk.Main;
procedure File_Chooser is
Window : Gtk_Window;
Button : Gtk_Button;
Box : Gtk_VBox;
Text : Gtk_Label;
package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
package Return_Handlers is
new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
function Delete_Event (Widget : access Gtk_Widget_Record'Class)
return Boolean is
begin
return False;
end Delete_Event;
procedure On_Destroy (Widget : access Gtk_Widget_Record'Class) is
begin
Gtk.Main.Main_Quit;
end On_Destroy;
procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
Dialog : Gtk_File_Chooser_Dialog;
Action : File_Chooser_Action := Action_Open;
Button : Gtk_Widget;
begin
Gtk_New (Dialog, "Select files", Window, Action);
Button := Add_Button (Dialog, "OK", Gtk_Response_Accept);
if Run (Gtk_Dialog (Dialog)) = Gtk_Response_Accept then
Set_Text (Text, Get_Filename (+Dialog));
else
Set_Text (Text, "");
end if;
Destroy (Dialog);
end Clicked;
begin
Gtk.Main.Init;
Gtk.Window.Gtk_New (Window);
Return_Handlers.Connect (Window, "delete_event", Delete_Event'Access);
Handlers.Connect (Window, "destroy", On_Destroy'Access);
Gtk_New_VBox (Box);
Gtk_New (Button, "Choose a file");
Pack_Start (Box, Button);
Handlers.Connect (Button, "clicked", Clicked'Access);
Gtk_New (Text);
Pack_End (Box, Text);
Add (Window, Box);
Show_All (Window);
Gtk.Main.Main;
end File_Chooser;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
More information about the gtkada
mailing list