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 method get_as_string : string
42 method get_metasenv_and_term :
43 context:Cic.context ->
44 metasenv:Cic.metasenv -> Cic.metasenv * Cic.term
46 method set_term : string -> unit
47 method id_to_uris : Disambiguate.domain_and_interpretation ref
51 let empty_id_to_uris = ([],function _ -> None);;
53 module Make(C:Disambiguate.Callbacks) =
56 module Disambiguate' = Disambiguate.Make(C);;
58 class term_editor_impl ?packing ?width ?height ?isnotempty_callback
59 ?share_id_to_uris_with () : term_editor
62 match share_id_to_uris_with with
63 None -> ref empty_id_to_uris
64 | Some obj -> obj#id_to_uris
66 let input = GEdit.text ~editable:true ?width ?height ?packing () in
68 match isnotempty_callback with
71 ignore(input#connect#changed
72 (function () -> callback (input#length > 0)))
75 method coerce = input#coerce
77 input#delete_text 0 input#length
78 (* CSC: txt is now a string, but should be of type Cic.term *)
81 ignore ((input#insert_text txt) ~pos:0)
82 (* CSC: this method should disappear *)
83 method get_as_string =
84 input#get_chars 0 input#length
85 method get_metasenv_and_term ~context ~metasenv =
93 let lexbuf = Lexing.from_string (input#get_chars 0 input#length) in
94 let dom,mk_metasenv_and_expr =
95 CicTextualParserContext.main
96 ~context:name_context ~metasenv CicTextualLexer.token lexbuf
98 let id_to_uris',metasenv,expr =
99 Disambiguate'.disambiguate_input
100 context metasenv dom mk_metasenv_and_expr ~id_to_uris:!id_to_uris
102 id_to_uris := id_to_uris' ;
104 method id_to_uris = id_to_uris
107 let term_editor = new term_editor_impl