Debian Codegraph @

ide/rocqide/wg_RoutedMessageViews.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 class type message_views_router = object
12 method route : int -> Wg_MessageView.message_view
13 method default_route : Wg_MessageView.message_view
14
15 method select_all : unit -> unit
16 method has_selection : bool
17 method get_selected_text : string
18
19 method register_route : int -> Wg_MessageView.message_view -> unit
20 method delete_route : int -> unit
21 end
22
23 let message_views ~route_0 : message_views_router =
24 let route_table = Hashtbl.create 17 in
25 let () = Hashtbl.add route_table 0 route_0 in
26 object
27 method route i =
28 try Hashtbl.find route_table i
29 with Not_found ->
30 (* at least the message will be printed somewhere*)
31 Hashtbl.find route_table 0
32
33 method default_route = route_0
34
35 method register_route i mv = Hashtbl.add route_table i mv
36
37 method delete_route i = Hashtbl.remove route_table i
38
39 method select_all () = Hashtbl.iter (fun _ v -> v#select_all ()) route_table
40
41 method has_selection =
42 Hashtbl.fold (fun _ v -> (||) v#has_selection) route_table false
43
44 method get_selected_text =
45 Option.default ""
46 (Hashtbl.fold (fun _ v acc ->
47 if v#has_selection then Some v#get_selected_text else acc)
48 route_table None)
49
50 end