thanks for the answer. I was stopped with this.
"MISSING A callback handler is also needed for the X button when you close the dialog otherwise it never closes and remains in the background." I tried the attached code to solve this, but without success. The code execution doesn't stop.. Thanks
-- window_callbacks.ads
with Gtkada.Builder; use Gtkada.Builder;
package Window_Callbacks is
function On_Window1_Delete_Event (Builder : access Gtkada_Builder_Record'Class) return Boolean;
procedure On_File1_File_Set (Builder : access Gtkada_Builder_Record'Class);
end Window_Callbacks;
-- window_callbacks.adb
-- units from GtkAda
with Gtk.Main;
-- units from GtkAda
with Gtk.File_Chooser; use Gtk.File_Chooser;
with Gtk.File_Chooser_Button; use Gtk.File_Chooser_Button;
with Gtkada.File_Selection; use Gtkada.File_Selection;
-- units from Glib
with Glib; use Glib;
with Glib.Object; use Glib.Object;
-- Ada predefined units
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Ada.Exceptions;
package body Window_Callbacks is
-----------------------------------------------
-- On_Window1_Delete_Event
-----------------------------------------------
function On_Window1_Delete_Event
(Builder : access Gtkada_Builder_Record'Class) return Boolean is
pragma Unreferenced (Builder);
begin
Gtk.Main.Main_Quit;
return False;
end On_Window1_Delete_Event;
---------------------------------
-- On_File1_File_Set --
---------------------------------
procedure On_File1_File_Set (Builder : access Gtkada_Builder_Record'Class) is
Button : access Gtk_File_Chooser_Button_Record;
function Name_Strict (File_Name : string) return string is
I : natural := File_Name'Last;
begin
loop
exit when File_Name (I) = Solidus or File_Name (I) = Reverse_Solidus or I = File_Name'First;
I := @ - 1;
end loop;
if File_Name (I) = Solidus or File_Name (I) = Reverse_Solidus then
return File_Name (I+1..File_Name'Last); --folder is present
else
return File_Name; -- folder is absent
end if;
end;
begin
-- Get the file chooser button
Button := Gtk_File_Chooser_Button (Get_Object(Builder, "file1"));
-- Get the filename
declare
File_Name : constant string := Get_FileName (Button);
Folder_Name : constant string := Get_Current_Folder (Button);
begin
Ada.Text_IO.Put_Line ("File selected : " & File_Name);
Ada.Text_IO.Put_Line ("Current Folder : " & Folder_Name);
Ada.Text_IO.Put_Line ("Strict File Name : " & Name_Strict (File_Name));
New_line;
end;
end On_File1_File_Set;
end Window_Callbacks;
-- Glade_8
-- units from Gtk
with Gtk.Main;
with Glib.Error; use Glib.Error;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Builder; use Gtk.Builder;
with Gtkada.Builder; use Gtkada.Builder;
-- Ada predefined units
with Ada.Text_IO; use Ada.Text_IO;
-- Application specific units
with Window_Callbacks; use Window_Callbacks;
procedure Glade_8 is
Mon_Interface : Constant String :=
"<?xml version=""1.0"" encoding=""UTF-8""?>"
& "<!-- Generated with glade 3.40.0 -->"
& "<interface>"
& " <requires lib=""gtk+"" version=""3.20""/>"
& " <object class=""GtkAdjustment"" id=""adjustment1"">"
& " <property name=""upper"">100</property>"
& " <property name=""step-increment"">1</property>"
& " <property name=""page-increment"">10</property>"
& " </object>"
& " <object class=""GtkListStore"" id=""liststore1"">"
& " <columns>"
& " <!-- column-name gchararray1 -->"
& " <column type=""gchararray""/>"
& " </columns>"
& " <data>"
& " <row>"
& " <col id=""0"" translatable=""yes"">test1</col>"
& " </row>"
& " <row>"
& " <col id=""0"" translatable=""yes"">test2</col>"
& " </row>"
& " <row>"
& " <col id=""0"" translatable=""yes"">test3</col>"
& " </row>"
& " </data>"
& " </object>"
& " <object class=""GtkWindow"" id=""window"">"
& " <property name=""can-focus"">False</property>"
& " <child>"
& " <object class=""GtkFixed"" id=""fixed1"">"
& " <property name=""visible"">True</property>"
& " <property name=""can-focus"">False</property>"
& " <child>"
& " <object class=""GtkFileChooserButton"" id=""file1"">"
& " <property name=""width-request"">196</property>"
& " <property name=""visible"">True</property>"
& " <property name=""can-focus"">False</property>"
& " <property name=""title"" translatable=""yes""/>"
& " <signal name=""file-set"" handler=""on_file1_file_set"" swapped=""no""/>"
& " </object>"
& " <packing>"
& " <property name=""x"">9</property>"
& " <property name=""y"">234</property>"
& " </packing>"
& " </child>"
& " </object>"
& " </child>"
& " </object>"
& "</interface>";
Builder : Gtkada_Builder;
Error : aliased Glib.Error.GError;
use type Glib.Guint;
begin
Gtk.Main.Init;
-- Etape 1 : créer un Builder
Gtk_New (Builder);
if Add_From_String (Gtk_Builder(Builder), Mon_Interface, Error'Access) = 0 then
Put_Line ("Error : " & Get_Message (Error));
Error_Free (Error);
return;
end if;
-- Etape 2 : créer les handlers des events
Register_Handler (Builder, "on_window1_delete_event", On_Window1_Delete_Event'Access);
Register_Handler (Builder, "on_file1_file_set", On_File1_File_Set'Access);
-- Etape 3 : Do_Connect connecte tous les handlers enregistrés en une fois.
Do_Connect (Builder);
-- Etape 4 : Afficher la fenetre avec ses dépendances
Show_All (Gtk_Widget (Get_Object (GTK_Builder (Builder), "window")));
-- Etape 5 : Lancer la boucle infinie.
Gtk.Main.Main;
-- Etape 6 : Unref pour libérer la memoire associée au Builder.
Unref (Builder);
end Glade_8;