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 x -> x | _ -> assert false
37 let get_uint = function `INT x -> x | _ -> assert false
39 let get_int = function `INT x -> x | _ -> assert false
41 let get_gobject = function `OBJECT x -> x | _ -> assert false
42 let gobject x = `OBJECT (Some x)
44 (** {2 GtkSourceLanguage} *)
46 class source_language_signals obj' =
48 inherit ['a] gobject_signals (obj' : [> Gtk_sourceview.source_language] obj)
49 inherit source_language_sigs
52 class source_language (obj: Gtk_sourceview.source_language obj) =
54 method as_source_language = obj
55 method connect = new source_language_signals obj
56 method misc = new gobject_ops obj
57 method get_name = SourceLanguage.get_name obj
58 method get_section = SourceLanguage.get_section obj
59 method get_escape_char = SourceLanguage.get_escape_char obj
62 (** {2 GtkSourceBuffer} *)
64 class source_buffer_signals obj' =
66 inherit ['a] gobject_signals (obj' : [> Gtk_sourceview.source_buffer] obj)
67 inherit GText.buffer_signals obj'
68 inherit source_buffer_sigs
71 class source_buffer (obj: Gtk_sourceview.source_buffer obj) =
73 inherit GText.buffer_skel obj
74 method connect = new source_buffer_signals obj
75 method misc = new gobject_ops obj
76 method check_brackets = get_bool (self#misc#get_property "check-brackets")
77 method set_check_brackets x = self#misc#set_property "check-brackets" (bool x)
78 method highlight = get_bool (self#misc#get_property "highlight")
79 method set_highlight x = self#misc#set_property "highlight" (bool x)
80 method max_undo_levels = get_int (self#misc#get_property "max-undo-levels")
81 method set_max_undo_levels x =
82 self#misc#set_property "max-undo-levels" (int x)
84 match get_gobject (self#misc#get_property "language") with
87 Some (new source_language (Gobject.try_cast obj "GtkSourceLanguage"))
88 method set_language (x: source_language) =
89 self#misc#set_property "language" (gobject x#as_source_language)
90 method escape_char = get_uint (self#misc#get_property "escape-char")
91 method set_escape_char x = self#misc#set_property "escape-char" (uint x)
92 method can_undo = SourceBuffer.can_undo obj
93 method can_redo = SourceBuffer.can_redo obj
94 method undo () = SourceBuffer.undo obj
95 method redo () = SourceBuffer.redo obj
96 method begin_not_undoable_action () =
97 SourceBuffer.begin_not_undoable_action obj
98 method end_not_undoable_action () =
99 SourceBuffer.end_not_undoable_action obj
102 let source_buffer ?language ?text (* ?tag_table *) =
106 | Some source_language -> Some (source_language#as_source_language)
108 SourceBuffer.make_params [] ?language ~cont:(fun pl () ->
109 let buf = new source_buffer (SourceBuffer.create pl) in
112 | Some text -> buf#set_text text);
115 (* alias used below, needed because "source_buffer" is a name in scope *)
116 let source_buffer' = source_buffer
118 (** {2 GtkSourceView} *)
120 class source_view_signals obj' =
122 inherit widget_signals_impl (obj' : [> Gtk_sourceview.source_view] obj)
123 inherit GText.view_signals obj'
124 inherit source_view_sigs
127 class source_view (obj': Gtk_sourceview.source_view obj) =
129 inherit GText.view_skel obj'
132 Gobject.try_cast (GtkText.View.get_buffer obj') "GtkSourceBuffer"
134 new source_buffer buf_obj
135 method source_buffer = source_buf
136 method connect = new source_view_signals obj'
137 method set_show_line_numbers x =
138 self#misc#set_property "show_line_numbers" (bool x)
139 method show_line_numbers =
140 get_bool (self#misc#get_property "show_line_numbers")
141 method set_show_line_markers x =
142 self#misc#set_property "show_line_markers" (bool x)
143 method show_line_markers =
144 get_bool (self#misc#get_property "show_line_markers")
145 method set_tabs_width x = self#misc#set_property "tabs_width" (uint x)
146 method tabs_width = get_uint (self#misc#get_property "tabs_width")
147 method set_auto_indent x = self#misc#set_property "auto_indent" (bool x)
148 method auto_indent = get_bool (self#misc#get_property "auto_indent")
149 method set_insert_spaces_instead_of_tabs x =
150 self#misc#set_property "insert_spaces_instead_of_tabs" (bool x)
151 method insert_spaces_instead_of_tabs =
152 get_bool (self#misc#get_property "insert_spaces_instead_of_tabs")
153 method set_show_margin x = self#misc#set_property "show_margin" (bool x)
154 method show_margin = get_bool (self#misc#get_property "show_margin")
155 method set_margin x = self#misc#set_property "margin" (uint x)
156 method margin = get_uint (self#misc#get_property "margin")
157 method set_smart_home_end x = self#misc#set_property "smart_home_end" (bool x)
158 method smart_home_end = get_bool (self#misc#get_property "smart_home_end")
161 let source_view ?source_buffer =
162 SourceView.make_params [] ~cont:(
163 GtkText.View.make_params ~cont:(
164 GContainer.pack_container ~create:(fun pl ->
166 match source_buffer with
168 SourceView.new_with_buffer
169 (Gobject.try_cast buf#as_buffer "GtkSourceBuffer")
170 | None -> SourceView.new_ ()
172 Gobject.set_params (Gobject.try_cast obj "GtkSourceView") pl;
173 new source_view obj)))