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$ *)
|
|
|
|
|
|
|
|
open Tk
|
|
|
|
open Jg_tk
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let get_all tw = Text.get tw ~start:tstart ~stop:(tposend 1)
|
1999-11-30 06:59:39 -08:00
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let tag_and_see tw ~tag ~start ~stop =
|
|
|
|
Text.tag_remove tw ~start:(tpos 0) ~stop:tend ~tag;
|
|
|
|
Text.tag_add tw ~start ~stop ~tag;
|
1999-11-30 06:59:39 -08:00
|
|
|
try
|
2000-04-11 20:43:25 -07:00
|
|
|
Text.see tw ~index:(`Tagfirst tag, []);
|
|
|
|
Text.mark_set tw ~mark:"insert" ~index:(`Tagfirst tag, [])
|
1999-11-30 06:59:39 -08:00
|
|
|
with Protocol.TkError _ -> ()
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let output tw ~buf ~pos ~len =
|
|
|
|
Text.insert tw ~index:tend ~text:(String.sub buf ~pos ~len)
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
let add_scrollbar tw =
|
2000-04-11 20:43:25 -07:00
|
|
|
let sb = Scrollbar.create (Winfo.parent tw) ~command:(Text.yview tw)
|
|
|
|
in Text.configure tw ~yscrollcommand:(Scrollbar.set sb); sb
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
let create_with_scrollbar parent =
|
|
|
|
let frame = Frame.create parent in
|
|
|
|
let tw = Text.create frame in
|
|
|
|
frame, tw, add_scrollbar tw
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let goto_tag tw ~tag =
|
1999-11-30 06:59:39 -08:00
|
|
|
let index = (`Tagfirst tag, []) in
|
2000-04-11 20:43:25 -07:00
|
|
|
try Text.see tw ~index;
|
|
|
|
Text.mark_set tw ~index ~mark:"insert"
|
1999-11-30 06:59:39 -08:00
|
|
|
with Protocol.TkError _ -> ()
|
|
|
|
|
|
|
|
let search_string tw =
|
|
|
|
let tl = Jg_toplevel.titled "Search" in
|
2000-04-11 20:43:25 -07:00
|
|
|
Wm.transient_set tl ~master:Widget.default_toplevel;
|
1999-11-30 06:59:39 -08:00
|
|
|
let fi = Frame.create tl
|
|
|
|
and fd = Frame.create tl
|
|
|
|
and fm = Frame.create tl
|
|
|
|
and buttons = Frame.create tl
|
2000-04-11 20:43:25 -07:00
|
|
|
and direction = Textvariable.create ~on:tl ()
|
|
|
|
and mode = Textvariable.create ~on:tl ()
|
|
|
|
and count = Textvariable.create ~on:tl ()
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
2000-04-11 20:43:25 -07:00
|
|
|
let label = Label.create fi ~text:"Pattern:"
|
|
|
|
and text = Entry.create fi ~width:20
|
|
|
|
and back = Radiobutton.create fd ~variable:direction
|
|
|
|
~text:"Backwards" ~value:"backward"
|
|
|
|
and forw = Radiobutton.create fd ~variable:direction
|
|
|
|
~text:"Forwards" ~value:"forward"
|
|
|
|
and exact = Radiobutton.create fm ~variable:mode
|
|
|
|
~text:"Exact" ~value:"exact"
|
|
|
|
and nocase = Radiobutton.create fm ~variable:mode
|
|
|
|
~text:"No case" ~value:"nocase"
|
|
|
|
and regexp = Radiobutton.create fm ~variable:mode
|
|
|
|
~text:"Regexp" ~value:"regexp"
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
2000-04-11 20:43:25 -07:00
|
|
|
let search = Button.create buttons ~text:"Search" ~command:
|
1999-11-30 06:59:39 -08:00
|
|
|
begin fun () ->
|
|
|
|
try
|
|
|
|
let pattern = Entry.get text in
|
|
|
|
let dir, ofs = match Textvariable.get direction with
|
|
|
|
"forward" -> `Forwards, 1
|
|
|
|
| "backward" -> `Backwards, -1
|
1999-12-07 07:01:12 -08:00
|
|
|
| _ -> assert false
|
1999-11-30 06:59:39 -08:00
|
|
|
and mode = match Textvariable.get mode with "exact" -> [`Exact]
|
|
|
|
| "nocase" -> [`Nocase] | "regexp" -> [`Regexp] | _ -> []
|
|
|
|
in
|
|
|
|
let ndx =
|
2000-04-11 20:43:25 -07:00
|
|
|
Text.search tw ~pattern ~switches:([dir;`Count count] @ mode)
|
|
|
|
~start:(`Mark "insert", [`Char ofs])
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
2000-04-11 20:43:25 -07:00
|
|
|
tag_and_see tw ~tag:"sel" ~start:(ndx,[])
|
|
|
|
~stop:(ndx,[`Char(int_of_string (Textvariable.get count))])
|
1999-11-30 06:59:39 -08:00
|
|
|
with Invalid_argument _ -> ()
|
|
|
|
end
|
2000-04-11 20:43:25 -07:00
|
|
|
and ok = Jg_button.create_destroyer tl ~parent:buttons ~text:"Cancel" in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
Focus.set text;
|
2000-04-11 20:43:25 -07:00
|
|
|
Jg_bind.return_invoke text ~button:search;
|
1999-11-30 06:59:39 -08:00
|
|
|
Jg_bind.escape_destroy tl;
|
2000-04-02 18:57:52 -07:00
|
|
|
Textvariable.set direction "forward";
|
|
|
|
Textvariable.set mode "nocase";
|
2000-04-11 20:43:25 -07:00
|
|
|
pack [label] ~side:`Left;
|
|
|
|
pack [text] ~side:`Right ~fill:`X ~expand:true;
|
|
|
|
pack [back; forw] ~side:`Left;
|
|
|
|
pack [exact; nocase; regexp] ~side:`Left;
|
|
|
|
pack [search; ok] ~side:`Left ~fill:`X ~expand:true;
|
|
|
|
pack [fi; fd; fm; buttons] ~side:`Top ~fill:`X
|