1515-- of the license. --
1616-- ----------------------------------------------------------------------------
1717
18+ with Ada.Characters.Handling ;
1819with Ada.Containers.Indefinite_Hashed_Maps ;
1920with Ada.Strings.Hash ;
2021with GNATCOLL.JSON ; use GNATCOLL.JSON;
@@ -37,7 +38,9 @@ with Gdk.RGBA; use Gdk.RGBA;
3738with Gdk.Window ; use Gdk.Window;
3839
3940with Gtk.Box ; use Gtk.Box;
41+ with Gtk.Dialog ; use Gtk.Dialog;
4042with Gtk.Enums ; use Gtk.Enums;
43+ with Gtk.GEntry ; use Gtk.GEntry;
4144with Gtk.Handlers ; use Gtk.Handlers;
4245with Gtk.Image ; use Gtk.Image;
4346with Gtk.Menu ; use Gtk.Menu;
@@ -61,6 +64,7 @@ with Commands; use Commands;
6164with Commands.Interactive ; use Commands.Interactive;
6265with Generic_Views ; use Generic_Views;
6366with GPS.Core_Kernels ; use GPS.Core_Kernels;
67+ with GPS.Dialogs ; use GPS.Dialogs;
6468with GPS.Intl ; use GPS.Intl;
6569with GPS.Kernel ; use GPS.Kernel;
6670with GPS.Kernel.Actions ; use GPS.Kernel.Actions;
@@ -863,23 +867,65 @@ package body Browsers.Canvas is
863867
864868 begin
865869 declare
866- Name : constant Virtual_File :=
867- Select_File
868- (Title => -(" Export Browser As " &
869- Description),
870- Parent => Get_Main_Window (Kernel),
871- File_Pattern => +(" *" & Extension),
872- Pattern_Name => -Description,
873- Default_Name => +(" gpsbrowser" & Extension),
874- Use_Native_Dialog => Use_Native_Dialogs.Get_Pref,
875- Kind => Save_File,
876- History => Get_History (Kernel));
877- Success : Boolean;
870+ Dialog : GPS_Dialog;
871+ Name : Virtual_File;
872+ Page_Format_Combo : Combo_Box;
873+ File_Ent : Gtk_Entry;
874+ Success : Boolean;
875+ Response : Gtk_Response_Type;
876+ P_Format : Page_Format;
878877 begin
878+ -- Create a dialog to select the page's format and a filename
879+ GPS.Dialogs.Gtk_New
880+ (Dialog,
881+ Title => -" Select page format and filename" ,
882+ Flags => Destroy_With_Parent or Modal,
883+ Kernel => Kernel);
884+ Dialog.Add_OK_Cancel;
885+
886+ -- Create a combo box with an entry to choose the page format
887+ Page_Format_Combo := Dialog.Add_Combo
888+ (Message => " Page format" ,
889+ Key => " browsers_page_format" ,
890+ Tooltip => " Select the page format. You can use predefined "
891+ & " formats (e.g: a4_portrait) via the combo box or specify "
892+ & " a custom size with the following format: '<width>, <height>'" );
893+
894+ -- Add the predefined page formats to the combo box
895+ for P_Format in Predefined_Page_Format_Type loop
896+ Page_Format_Combo.Add_Choice
897+ (Ada.Characters.Handling.To_Lower
898+ (Predefined_Page_Format_Type'Image (P_Format)));
899+ end loop ;
900+
901+ -- Create the filename selection entry
902+ File_Ent := Dialog.Add_File_Selection_Entry
903+ (Message => " Select file" ,
904+ Key => Histories.History_Key
905+ (" browsers_export_filename_" & Extension),
906+ File_Pattern => " *" & Extension,
907+ Pattern_Name => Description,
908+ Default_Name => " gpsbrowser" & Extension,
909+ Kind => Save_File);
910+
911+ -- Show the dialog
912+ Dialog.Show_All;
913+ Response := Dialog.Run;
914+
915+ if Response /= Gtk_Response_OK then
916+ Dialog.Destroy;
917+ return False;
918+ end if ;
919+
920+ -- The user pressed 'Ok': create the file if the filename is correct
921+
922+ Name := Create_From_UTF8 (File_Ent.Get_Text);
923+ P_Format := To_Page_Format (Page_Format_Combo.Get_Text);
924+
879925 if Name /= GNATCOLL.VFS.No_File then
880926 Success := Data.Browser.View.Export
881927 (Filename => Name.Display_Full_Name,
882- Page => A4_Landscape ,
928+ Page => P_Format ,
883929 Format => Data.Format,
884930 Visible_Area_Only => not Data.Whole);
885931
@@ -889,6 +935,8 @@ package body Browsers.Canvas is
889935 Mode => GPS.Kernel.Error);
890936 end if ;
891937 end if ;
938+
939+ Dialog.Destroy;
892940 end ;
893941
894942 return False;
0 commit comments