]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtksourceview/test/test.ml
snapshort
[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 lang_mime_type = "text/x-c"
29 let lang_file = "test.lang"
30 let use_mime_type = false
31
32 let print_lang lang = prerr_endline (sprintf "language: %s" lang#get_name)
33
34 let print_lang_dirs languages_manager =
35   let i = ref 0 in
36   prerr_endline "lang_dirs:";
37   List.iter
38     (fun dir -> incr i; prerr_endline (sprintf "%d: %s" !i dir))
39     languages_manager#lang_files_dirs
40
41 let win = GWindow.window ~title:"LablGtkSourceView test" ()
42 let scrolled_win = GBin.scrolled_window ~packing:win#add ()
43 let source_view =
44   GSourceView.source_view
45     ~auto_indent:true
46 (*     ~insert_spaces_instead_of_tabs:true ~tabs_width:2 *)
47     ~show_line_numbers:true
48     ~margin:80 ~show_margin:true
49     ~smart_home_end:true
50     ~packing:scrolled_win#add ~height:500 ~width:650
51     ()
52 (* let languages_manager =
53   GSourceView.source_languages_manager ~lang_files_dirs:["/etc"] () *)
54 let languages_manager = GSourceView.source_languages_manager ()
55 let lang =
56   if use_mime_type then
57     match languages_manager#get_language_from_mime_type lang_mime_type with 
58     | None -> failwith (sprintf "no language for %s" lang_mime_type)
59     | Some lang -> lang
60   else
61     match
62       GSourceView.source_language_from_file ~languages_manager lang_file
63     with
64     | None -> failwith (sprintf "can't load %s" lang_file)
65     | Some lang -> lang
66 let _ =
67   let text =
68     let ic = open_in "test.txt" in
69     let size = in_channel_length ic in
70     let buf = String.create size in
71     really_input ic buf 0 size;
72     close_in ic;
73     buf
74   in
75   win#set_allow_shrink true;
76   source_view#misc#modify_font_by_name "Monospace 10";
77   print_lang_dirs languages_manager;
78   print_lang lang;
79   source_view#source_buffer#set_language lang;
80   source_view#source_buffer#set_highlight true;
81   source_view#source_buffer#set_text text;
82   ignore (win#connect#destroy (fun _ -> GMain.quit ()));
83 (*   ignore (source_view#connect#move_cursor (fun _ _ ~extend ->
84     prerr_endline "move_cursor"));
85   ignore (source_view#connect#undo (fun _ -> prerr_endline "undo")); *)
86   win#show ();
87   GMain.Main.main ()
88