File: wg_RoutedMessageViews.ml

package info (click to toggle)
coq 8.16.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 40,596 kB
  • sloc: ml: 219,376; sh: 3,545; python: 3,231; ansic: 2,529; makefile: 767; lisp: 279; javascript: 63; xml: 24; sed: 2
file content (47 lines) | stat: -rw-r--r-- 1,746 bytes parent folder | download | duplicates (3)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)

class type message_views_router = object
  method route : int -> Wg_MessageView.message_view
  method default_route : Wg_MessageView.message_view

  method has_selection : bool
  method get_selected_text : string

  method register_route : int -> Wg_MessageView.message_view -> unit
  method delete_route : int -> unit
end

let message_views ~route_0 : message_views_router =
  let route_table = Hashtbl.create 17 in
  let () = Hashtbl.add route_table 0 route_0 in
object
  method route i =
    try Hashtbl.find route_table i
    with Not_found ->
      (* at least the message will be printed somewhere*)
      Hashtbl.find route_table 0

  method default_route = route_0

  method register_route i mv = Hashtbl.add route_table i mv

  method delete_route i = Hashtbl.remove route_table i

  method has_selection =
    Hashtbl.fold (fun _ v -> (||) v#has_selection) route_table false

  method get_selected_text =
    Option.default ""
      (Hashtbl.fold (fun _ v acc ->
         if v#has_selection then Some v#get_selected_text else acc)
      route_table None)

end