| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 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 |
|
| 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 |
|
| 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) |