1 (* Copyright (C) 2000-2002, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
36 (* A WIDGET TO ENTER CIC TERMS *)
38 class type term_editor =
40 method coerce : GObj.widget
41 (* get_as_string returns the unquoted string *)
42 method get_as_string : string
43 method get_metasenv_and_term :
44 context:Cic.context ->
45 metasenv:Cic.metasenv -> Cic.metasenv * Cic.term
47 (* The input of set_term is unquoted *)
48 method set_term : string -> unit
49 method id_to_uris : Disambiguate.domain_and_interpretation ref
53 let empty_id_to_uris = ([],function _ -> None);;
55 module Make(C:Disambiguate.Callbacks) =
58 module Disambiguate' = Disambiguate.Make(C);;
60 class term_editor_impl mqi_handle ?packing ?width ?height ?isnotempty_callback
61 ?share_id_to_uris_with () : term_editor
64 match share_id_to_uris_with with
65 None -> ref empty_id_to_uris
66 | Some obj -> obj#id_to_uris
68 let input = GText.view ~editable:true ?width ?height ?packing () in
70 match isnotempty_callback with
73 ignore(input#buffer#connect#changed
74 (function () -> callback (input#buffer#char_count > 0)))
77 method coerce = input#coerce
79 input#buffer#delete input#buffer#start_iter input#buffer#end_iter
80 (* CSC: txt is now a string, but should be of type Cic.term *)
83 ignore (input#buffer#insert txt)
84 (* CSC: this method should disappear *)
85 (* get_as_string returns the unquoted string *)
86 method get_as_string =
87 input#buffer#get_text ()
88 method get_metasenv_and_term ~context ~metasenv =
96 let lexbuf = Lexing.from_string (input#buffer#get_text ()) in
97 let dom,mk_metasenv_and_expr =
98 CicTextualParserContext.main
99 ~context:name_context ~metasenv CicTextualLexer.token lexbuf
101 let id_to_uris',metasenv,expr =
102 Disambiguate'.disambiguate_input mqi_handle
103 context metasenv dom mk_metasenv_and_expr ~id_to_uris:!id_to_uris
105 id_to_uris := id_to_uris' ;
107 method id_to_uris = id_to_uris
110 let term_editor = new term_editor_impl