(* Copyright (C) 2005: * Stefano Zacchiroli * Claudio Sacerdoti Coen * * This file is part of lablgtksourceview, the OCaml binding for the * GtkSourceView widget. * * lablgtksourceview is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * lablgtksourceview is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with lablgtksourceview; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * For details, send a mail to the authors. *) open Gaux open Gtk_sourceview open Gobject open Gtk open GtkBase open GtkSourceView open OgtkSourceViewProps open GObj let get_bool = function `BOOL b -> b | _ -> assert false let bool b = `BOOL b let get_uint = function `INT i -> i | _ -> assert false let uint i = `INT i let get_int = function `INT i -> i | _ -> assert false let int i = `INT i (** {2 GtkSourceBuffer} *) class source_buffer_signals obj_arg = object inherit ['a] gobject_signals (obj_arg : [> Gtk_sourceview.source_buffer] obj) inherit GText.buffer_signals obj_arg inherit source_buffer_sigs end class source_buffer (obj: Gtk_sourceview.source_buffer obj) = object (self) inherit GText.buffer_skel obj method connect = new source_buffer_signals obj method misc = new gobject_ops obj method check_brackets = get_bool (self#misc#get_property "check-brackets") method set_check_brackets x = self#misc#set_property "check-brackets" (bool x) method highlight = get_bool (self#misc#get_property "highlight") method set_highlight x = self#misc#set_property "highlight" (bool x) method max_undo_levels = get_int (self#misc#get_property "max-undo-levels") method set_max_undo_levels x = self#misc#set_property "max-undo-levels" (int x) method escape_char = get_uint (self#misc#get_property "escape-char") method set_escape_char x = self#misc#set_property "escape-char" (uint x) method can_undo = SourceBuffer.can_undo obj method can_redo = SourceBuffer.can_redo obj method undo () = SourceBuffer.undo obj method redo () = SourceBuffer.redo obj method begin_not_undoable_action () = SourceBuffer.begin_not_undoable_action obj method end_not_undoable_action () = SourceBuffer.end_not_undoable_action obj end let source_buffer = SourceBuffer.make_params [] ~cont:(fun pl () -> new source_buffer (SourceBuffer.create pl)) (* alias used below, needed because "source_buffer" is a name in scope *) let source_buffer' = source_buffer (** {2 GtkSourceView} *) class source_view_signals obj_arg = object inherit widget_signals_impl (obj_arg : [> Gtk_sourceview.source_view] obj) inherit GText.view_signals obj_arg inherit source_view_sigs end class source_view (obj: Gtk_sourceview.source_view obj) = object (self) inherit GText.view_skel obj method connect = new source_view_signals obj method set_show_line_numbers x = self#misc#set_property "show_line_numbers" (bool x) method show_line_numbers = get_bool (self#misc#get_property "show_line_numbers") method set_show_line_markers x = self#misc#set_property "show_line_markers" (bool x) method show_line_markers = get_bool (self#misc#get_property "show_line_markers") method set_tabs_width x = self#misc#set_property "tabs_width" (uint x) method tabs_width = get_uint (self#misc#get_property "tabs_width") method set_auto_indent x = self#misc#set_property "auto_indent" (bool x) method auto_indent = get_bool (self#misc#get_property "auto_indent") method set_insert_spaces_instead_of_tabs x = self#misc#set_property "insert_spaces_instead_of_tabs" (bool x) method insert_spaces_instead_of_tabs = get_bool (self#misc#get_property "insert_spaces_instead_of_tabs") method set_show_margin x = self#misc#set_property "show_margin" (bool x) method show_margin = get_bool (self#misc#get_property "show_margin") method set_margin x = self#misc#set_property "margin" (uint x) method margin = get_uint (self#misc#get_property "margin") method set_smart_home_end x = self#misc#set_property "smart_home_end" (bool x) method smart_home_end = get_bool (self#misc#get_property "smart_home_end") end let source_view ?source_buffer = SourceView.make_params [] ~cont:( GtkText.View.make_params ~cont:( GContainer.pack_container ~create:(fun pl -> let buf = match source_buffer with | None -> source_buffer' () | Some source_buffer -> source_buffer in let obj = SourceView.create pl in GtkText.View.set_buffer obj buf#as_buffer; new source_view obj)))