From: "ldries46" <bertus.dries@planet.nl>
Subject: Re: Documentation or examples wanted for the File_Chooser_Dialog
Date: Sun, 10 May 2009 16:27:41 +0200
Date: 2009-05-10T16:27:41+02:00 [thread overview]
Message-ID: <4a06e454$0$1649$703f8584@textnews.kpn.nl> (raw)
In-Reply-To: 11bbcsfmckzik$.1kok2zp59s132$.dlg@40tude.net
First Thanks for the hint. I now have a working routine. I now want to
present this as an example for anyone who wants to use the FilechooserDialog
routine.
In this routine I set a default directory and saves the directory where the
file was eventually was found.
procedure On_Open_C_Activate
(Object : access Gtk_Image_Menu_Item_Record'Class)
is
Default_ext : Integer;
Filename : Unbounded_String;
Base_Dir : Unbounded_String := To_Unbounded_String("." & DS);
Default_Dir : Unbounded_String;
In_String : Unbounded_String;
C_File : File_Type;
soort : file_soort;
ok : boolean := false;
empty : boolean := false;
File_Dialog : Gtk_File_Chooser_Dialog;
All_Files : Gtk_File_Filter;
Header : Gtk_File_Filter;
C_Body : Gtk_File_Filter;
CPP_Body : Gtk_File_Filter;
Final_Filter : Gtk_File_Filter;
Button_Open : Gtk.Widget.Gtk_Widget;
Button_Cancel : Gtk.Widget.Gtk_Widget;
begin
Default_Dir := To_Unbounded_String(Get_Value(n_ini, "Directory",
"Default_Open", To_String(Base_Dir)));
Default_Ext := Get_Value(n_ini, "File", "Type", 1);
Gtk_New(File_Dialog,"Open C, C++ or Header File", CtoADAWindow,
Action_Open);
if Base_Dir /= Default_Dir then
empty := Set_Current_Folder(+File_Dialog, To_String(Default_Dir));
end if;
Gtk_New(All_Files);
Set_Name(All_Files, "All files");
Add_Pattern(All_Files, "*.*");
Add_Filter(+File_Dialog, All_Files);
Gtk_New(Header);
Set_Name(Header, "C/C++ header files");
Add_Pattern(Header, "*.h");
Add_Filter(+File_Dialog, Header);
Gtk_New(C_Body);
Set_Name(C_Body, "C body files");
Add_Pattern(C_Body, "*.c");
Add_Filter(+File_Dialog, C_Body);
Gtk_New(CPP_Body);
Set_Name(CPP_Body, "C++ body files");
Add_Pattern(CPP_Body, "*.cpp");
Add_Filter(+File_Dialog, CPP_Body);
case Default_Ext is
when 1 => Set_Filter(+File_Dialog, All_Files);
when 2 => Set_Filter(+File_Dialog, Header);
when 3 => Set_Filter(+File_Dialog, C_Body);
when 4 => Set_Filter(+File_Dialog, CPP_Body);
when others => Set_Filter(+File_Dialog, Header);
end case;
Button_Open := Add_Button(File_Dialog, "Open", gtk_response_accept);
Button_Cancel := Add_Button(File_Dialog, "Cancel",
gtk_response_cancel);
Final_Filter := Get_Filter(+File_Dialog);
if Run(File_Dialog) = gtk_response_accept then
FileName := To_Unbounded_String(Get_FileName(+File_Dialog));
Default_Dir :=
To_Unbounded_String(Get_Current_Folder(+File_Dialog));
Set_Value(n_ini, "Directory", "Default_Open",
To_String(Default_Dir));
Open(C_File, In_File, To_String(Filename));
while not End_Of_File(C_File) loop
In_String := To_Unbounded_String(Get_Line(C_File));
Insert_at_Cursor (Get_Buffer (CtoADAWindow.C_View),
To_String(In_String) & ASCII.CR & ASCII.LF);
end loop;
Close(C_File);
Soort_File ( FileName );
soort := C2ADA(CtoADAWindow.C_View, CtoADAWindow.ADA_View);
end if;
Hide(File_Dialog);
Destroy(File_Dialog);
if Final_Filter = All_Files then
Default_Ext := 1;
elsif Final_Filter = Header then
Default_Ext := 2;
elsif Final_Filter = C_Body then
Default_Ext := 3;
elsif Final_Filter = CPP_Body then
Default_Ext := 4;
else
Default_Ext := 1;
end if;
Set_Value(n_ini, "File", "Type", Default_Ext);
end On_Open_C_Activate;
>
> The documentation is actually not bad, IMO. (But learning GTK is always an
> act of masochism. (:-))
>
>> I hope that there is documentation or examples
>> that are more clear for leople who do want to learn something.
>
> You could start Gtk_Dialog:
>
> http://www.adacore.com/wp-content/files/auto_update/gtkada-docs/gtkada_rm/gtkada_rm/gtk-dialog.html
>
> Gtk_Dialog_Record is the parent of Gtk_File_Chooser_Dialog_Record.. The
> testgtk application is contains an example for Gtk_Dialog_Record. You
> could
> try to replace Gtk_Dialog with Gtk_File_Chooser_Dialog_Record there.
>
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2009-05-10 14:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-08 16:01 Documentation or examples wanted for the File_Chooser_Dialog ldries46
2009-05-08 16:25 ` Dmitry A. Kazakov
2009-05-08 20:43 ` ldries46
2009-05-09 7:00 ` Dmitry A. Kazakov
2009-05-10 14:27 ` ldries46 [this message]
2009-05-11 10:50 ` Philipp Riegger
2009-05-14 7:34 ` ldries46
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox