Debian Codegraph @

ide/rocqide/ui_dialogs.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 type button_contents =
12 | ButtonWithStock of GtkStock.id
13 | ButtonWithLabel of string
14
15 let question_box ?parent ?icon ~title ?(buttons = []) ?(default = 1) message =
16 let button_nb = ref 0 in
17 let window = GWindow.dialog ~position:`CENTER ~modal:true ?parent ~type_hint:`DIALOG ~title () in
18 let hbox = GPack.hbox ~border_width:15 ~packing:window#vbox#add () in
19 let bbox = window#action_area in
20 Option.iter (fun icon -> hbox#pack icon#coerce ~padding:4) icon;
21 ignore (GMisc.label ~text:message ~packing:hbox#add ());
22 (* the function called to create each button by iterating *)
23 let rec iter_buttons pos = function
24 | but_content :: others ->
25 let label, stock =
26 match but_content with
27 | ButtonWithLabel label -> Some label, None
28 | ButtonWithStock stock -> None, Some stock
29 in
30 let but = GButton.button ?label ?stock ~packing:(bbox#pack ~expand:true) () in
31 ignore (but#connect#clicked ~callback:(fun () -> button_nb := pos; window#destroy ()));
32 (* If it's the default button then give it the focus *)
33 if pos = default then
34 but#grab_default ();
35 iter_buttons (pos + 1) others;
36 | [] -> ()
37 in
38 iter_buttons 1 buttons;
39 ignore (window#connect#destroy ~callback:GMain.Main.quit);
40 window#set_position `CENTER;
41 window#show ();
42 GMain.Main.main ();
43 !button_nb
44
45 let message_box ?parent ?icon ~title ?(ok = ButtonWithStock `OK) message =
46 ignore (question_box ?parent ?icon ~title ~buttons:[ ok ] message)