]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtksourceview/test/test.ml
load "test.txt" and show it in a scrolled win
[helm.git] / helm / DEVEL / lablgtksourceview / test / test.ml
1 (* Copyright (C) 2005:
2  *      Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>,
3  *      Stefano Zacchiroli     <zack@cs.unibo.it>
4  *
5  * This file is part of lablgtksourceview, the OCaml binding for the
6  * GtkSourceView widget.
7  * 
8  * lablgtksourceview is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * lablgtksourceview is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with lablgtksourceview; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  * 02111-1307, USA.
22  * 
23  * For details, send a mail to the authors.
24  *)
25
26 open Printf
27
28 let win = GWindow.window ~title:"LablGtkSourceView test" ()
29 let scrolled_win = GBin.scrolled_window ~packing:win#add ()
30 let text =
31   let ic = open_in "test.txt" in
32   let size = in_channel_length ic in
33   let buf = String.create size in
34   really_input ic buf 0 size;
35   close_in ic;
36   buf
37 let source_buffer = GSourceView.source_buffer ~text ~check_brackets:true ()
38 let source_view =
39   GSourceView.source_view
40     ~source_buffer
41     ~auto_indent:true ~insert_spaces_instead_of_tabs:true ~tabs_width:2
42     ~show_line_numbers:true
43     ~margin:80 ~show_margin:true
44     ~smart_home_end:true
45     ~packing:scrolled_win#add ~height:500 ~width:650
46     ()
47 let _ =
48   win#set_allow_shrink true;
49   ignore (win#connect#destroy (fun _ -> GMain.quit ()));
50 (*   ignore (source_view#connect#move_cursor (fun _ _ ~extend ->
51     prerr_endline "move_cursor"));
52   ignore (source_view#connect#undo (fun _ -> prerr_endline "undo")); *)
53   win#show ();
54   GMain.Main.main ()
55