2 * Stefano Zacchiroli <zack@cs.unibo.it>
3 * Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
5 * This file is part of lablgtksourceview, the OCaml binding for the
6 * GtkSourceView widget.
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.
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.
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
23 * For details, send a mail to the authors.
32 open OgtkSourceViewProps
35 let get_bool = function `BOOL b -> b | _ -> assert false
37 let get_uint = function `INT i -> i | _ -> assert false
39 let get_int = function `INT i -> i | _ -> assert false
42 (** {2 GtkSourceBuffer} *)
44 class source_buffer_signals obj_arg =
46 inherit ['a] gobject_signals (obj_arg : [> Gtk_sourceview.source_buffer] obj)
47 inherit GText.buffer_signals obj_arg
48 inherit source_buffer_sigs
51 class source_buffer (obj: Gtk_sourceview.source_buffer obj) =
53 inherit GText.buffer_skel obj
54 method connect = new source_buffer_signals obj
55 method misc = new gobject_ops obj
56 method check_brackets = get_bool (self#misc#get_property "check-brackets")
57 method set_check_brackets x = self#misc#set_property "check-brackets" (bool x)
58 method highlight = get_bool (self#misc#get_property "highlight")
59 method set_highlight x = self#misc#set_property "highlight" (bool x)
60 method max_undo_levels = get_int (self#misc#get_property "max-undo-levels")
61 method set_max_undo_levels x =
62 self#misc#set_property "max-undo-levels" (int x)
63 method escape_char = get_uint (self#misc#get_property "escape-char")
64 method set_escape_char x = self#misc#set_property "escape-char" (uint x)
65 method can_undo = SourceBuffer.can_undo obj
66 method can_redo = SourceBuffer.can_redo obj
67 method undo () = SourceBuffer.undo obj
68 method redo () = SourceBuffer.redo obj
69 method begin_not_undoable_action () =
70 SourceBuffer.begin_not_undoable_action obj
71 method end_not_undoable_action () =
72 SourceBuffer.end_not_undoable_action obj
75 let source_buffer ?text =
76 SourceBuffer.make_params [] ~cont:(fun pl () ->
77 let buf = new source_buffer (SourceBuffer.create pl) in
80 | Some text -> buf#set_text text);
83 (* alias used below, needed because "source_buffer" is a name in scope *)
84 let source_buffer' = source_buffer
86 (** {2 GtkSourceView} *)
88 class source_view_signals obj_arg =
90 inherit widget_signals_impl (obj_arg : [> Gtk_sourceview.source_view] obj)
91 inherit GText.view_signals obj_arg
92 inherit source_view_sigs
95 class source_view (obj: Gtk_sourceview.source_view obj) =
97 inherit GText.view_skel obj
98 method connect = new source_view_signals obj
99 method set_show_line_numbers x =
100 self#misc#set_property "show_line_numbers" (bool x)
101 method show_line_numbers =
102 get_bool (self#misc#get_property "show_line_numbers")
103 method set_show_line_markers x =
104 self#misc#set_property "show_line_markers" (bool x)
105 method show_line_markers =
106 get_bool (self#misc#get_property "show_line_markers")
107 method set_tabs_width x = self#misc#set_property "tabs_width" (uint x)
108 method tabs_width = get_uint (self#misc#get_property "tabs_width")
109 method set_auto_indent x = self#misc#set_property "auto_indent" (bool x)
110 method auto_indent = get_bool (self#misc#get_property "auto_indent")
111 method set_insert_spaces_instead_of_tabs x =
112 self#misc#set_property "insert_spaces_instead_of_tabs" (bool x)
113 method insert_spaces_instead_of_tabs =
114 get_bool (self#misc#get_property "insert_spaces_instead_of_tabs")
115 method set_show_margin x = self#misc#set_property "show_margin" (bool x)
116 method show_margin = get_bool (self#misc#get_property "show_margin")
117 method set_margin x = self#misc#set_property "margin" (uint x)
118 method margin = get_uint (self#misc#get_property "margin")
119 method set_smart_home_end x = self#misc#set_property "smart_home_end" (bool x)
120 method smart_home_end = get_bool (self#misc#get_property "smart_home_end")
123 let source_view ?source_buffer =
124 SourceView.make_params [] ~cont:(
125 GtkText.View.make_params ~cont:(
126 GContainer.pack_container ~create:(fun pl ->
128 match source_buffer with
129 | None -> source_buffer' ()
130 | Some source_buffer -> source_buffer
132 let obj = SourceView.create pl in
133 GtkText.View.set_buffer obj buf#as_buffer;
134 new source_view obj)))