diff --git a/src/plugins/gui/gtk_helper.ml b/src/plugins/gui/gtk_helper.ml index 66d03ad71356a761044236c43c3bb6af0c98718c..a2125f34f9829c33cf8d44b2ba539df6138c0b31 100644 --- a/src/plugins/gui/gtk_helper.ml +++ b/src/plugins/gui/gtk_helper.ml @@ -960,6 +960,45 @@ let source_files_chooser (main_ui: source_files_chooser_host) defaults f = dialog#show (); () +let default_dir = ref "" + +let select_file ?title ?(dir=default_dir) ?(filename="") () = + let filename = + if Filename.is_relative filename then + if !dir <> "" then !dir ^ "/" ^ filename + else "" + else begin + dir:= Filename.dirname filename; + filename + end + in + let dialog: GWindow.Buttons.file_selection GWindow.file_chooser_dialog = + GWindow.file_chooser_dialog + ~action:`OPEN + ?title + ~filename + ~modal:true + () + in + let result = ref None in + let action r = + (match r with + | `OK -> + let file = dialog#filename in + (match file with + | None -> () + | Some file -> + dir := Filename.dirname file; + result := Some file) + | _ -> ()); + dialog#destroy () + in + dialog#add_select_button "Open" `OK; + dialog#add_button "Cancel" `CANCEL; + dialog#show (); + action (dialog#run ()); + !result + let spawn_command ?(timeout=0) ?stdout ?stderr s args f = let check_result = Command.command_async s ?stdout ?stderr args in let has_timeout = timeout > 0 in diff --git a/src/plugins/gui/gtk_helper.mli b/src/plugins/gui/gtk_helper.mli index 1d99d79c24597bea3683004d061e87f46a8121c3..60a28341d818bfef30f25ddf52756f924c8d67f8 100644 --- a/src/plugins/gui/gtk_helper.mli +++ b/src/plugins/gui/gtk_helper.mli @@ -321,6 +321,15 @@ val source_files_chooser: (string list -> unit) -> unit +(** Launches a standard gtk file chooser window and returns the name + of the selected file. Replaces GToolbox.select_file that has not been + ported to lablgtk3. + + @since Frama-C+dev +*) +val select_file: + ?title:string -> ?dir:(string ref)-> ?filename:string -> unit -> string option + (* ************************************************************************** *) (** {2 Miscellaneous} *) (* ************************************************************************** *)