1999-12-16 04:25:11 -08:00
|
|
|
(*************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml LablTk library *)
|
|
|
|
(* *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1999 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
|
|
(* This file is distributed under the terms of the GNU Library *)
|
|
|
|
(* General Public License. *)
|
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let lt_string ?(nocase=false) s1 s2 =
|
1999-11-30 06:59:39 -08:00
|
|
|
if nocase then String.lowercase s1 < String.lowercase s2 else s1 < s2
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
class completion ?nocase texts = object
|
1999-11-30 06:59:39 -08:00
|
|
|
val mutable texts = texts
|
|
|
|
val nocase = nocase
|
|
|
|
val mutable prefix = ""
|
|
|
|
val mutable current = 0
|
|
|
|
method add c =
|
|
|
|
prefix <- prefix ^ c;
|
|
|
|
while current < List.length texts - 1 &
|
2000-04-11 20:43:25 -07:00
|
|
|
lt_string (List.nth texts current) prefix ?nocase
|
1999-11-30 06:59:39 -08:00
|
|
|
do
|
|
|
|
current <- current + 1
|
|
|
|
done;
|
|
|
|
current
|
|
|
|
method current = current
|
2000-04-02 18:57:52 -07:00
|
|
|
method get_current = List.nth texts current
|
1999-11-30 06:59:39 -08:00
|
|
|
method reset =
|
|
|
|
prefix <- "";
|
|
|
|
current <- 0
|
|
|
|
end
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
class timed ?nocase ?wait texts = object (self)
|
|
|
|
inherit completion texts ?nocase as super
|
1999-11-30 06:59:39 -08:00
|
|
|
val wait = match wait with None -> 500 | Some n -> n
|
|
|
|
val mutable timer = None
|
|
|
|
method add c =
|
|
|
|
begin match timer with
|
|
|
|
None -> self#reset
|
|
|
|
| Some t -> Timer.remove t
|
|
|
|
end;
|
2000-04-11 20:43:25 -07:00
|
|
|
timer <- Some (Timer.add ~ms:wait ~callback:(fun () -> self#reset));
|
1999-11-30 06:59:39 -08:00
|
|
|
super#add c
|
|
|
|
method reset =
|
|
|
|
timer <- None; super#reset
|
|
|
|
end
|