]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/otherlibs/labltk/browser/jg_completion.ml
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / otherlibs / labltk / browser / jg_completion.ml
1 (*************************************************************************)
2 (*                                                                       *)
3 (*                Objective Caml LablTk library                          *)
4 (*                                                                       *)
5 (*            Jacques Garrigue, Kyoto University RIMS                    *)
6 (*                                                                       *)
7 (*   Copyright 1999 Institut National de Recherche en Informatique et    *)
8 (*   en Automatique and Kyoto University.  All rights reserved.          *)
9 (*   This file is distributed under the terms of the GNU Library         *)
10 (*   General Public License, with the special exception on linking       *)
11 (*   described in file ../../../LICENSE.                                 *)
12 (*                                                                       *)
13 (*************************************************************************)
14
15 (* $Id: jg_completion.ml 4144 2001-12-07 13:41:02Z xleroy $ *)
16
17 let lt_string ?(nocase=false) s1 s2 =
18   if nocase then String.lowercase s1 < String.lowercase s2 else s1 < s2
19
20 class completion ?nocase texts = object
21   val mutable texts = texts
22   val nocase = nocase
23   val mutable prefix = ""
24   val mutable current = 0
25   method add c =
26     prefix <- prefix ^ c;
27     while current < List.length texts - 1 &&
28       lt_string (List.nth texts current) prefix ?nocase
29     do
30       current <- current + 1
31     done;
32     current
33   method current = current
34   method get_current = List.nth texts current
35   method reset =
36     prefix <- "";
37     current <- 0
38 end
39
40 class timed ?nocase ?wait texts = object (self)
41   inherit completion texts ?nocase as super
42   val wait = match wait with None -> 500 | Some n -> n
43   val mutable timer = None
44   method add c =
45     begin match timer with
46       None -> self#reset
47     | Some t -> Timer.remove t
48     end;
49     timer <- Some (Timer.add ~ms:wait ~callback:(fun () -> self#reset));
50     super#add c
51   method reset =
52     timer <- None; super#reset
53 end