Source file selection.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(** Handling current selection.

Current selection is retrieved using {!val-get}. For widgets
handling user selection, when the user selects something,
the widget will {!val-set} the function called to retrieve the selection.
{!val-unset} removes the selection function.
*)

(**/**)
let selection = ref (None: (unit -> string option) option)
(**/**)

let unset () = selection := None
let set f =
  selection := Some f;
  Log.debug (fun m -> m "Selection set")

let get () =
  match !selection with
  | None -> None
  | Some f ->
      try f ()
      with e ->
          Log.err (fun m -> m "Selection.get: %s" (Printexc.to_string e));
          unset ();
          None