]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matita.ml
8f34f5bf728c141b88fe12cc8f97c3303cc45756
[helm.git] / helm / matita / matita.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open MatitaGtkMisc
27
28 (** {2 Internal status} *)
29
30 let (get_proof, set_proof, has_proof) =
31   let (current_proof: MatitaTypes.proof option ref) = ref None in
32   ((fun () ->
33     match !current_proof with
34     | Some proof -> proof
35     | None -> failwith "No current proof"),
36    (fun proof -> current_proof := proof),
37    (fun () -> !current_proof <> None))
38
39 (** {2 Settings} *)
40
41 let debug_print = MatitaTypes.debug_print
42
43 (** {2 Initialization} *)
44
45 let _ = Helm_registry.load_from "matita.conf.xml"
46 let _ = GMain.Main.init ()
47 let gui = new MatitaGui.gui (Helm_registry.get "matita.glade_file")
48 let parserr = new MatitaDisambiguator.parserr ()
49 let mqiconn = MQIConn.init ()
50 let disambiguator =
51   new MatitaDisambiguator.disambiguator ~parserr ~mqiconn
52     ~chooseUris:(interactive_user_uri_choice ~gui)
53     ~chooseInterp:(interactive_interp_choice ~gui)
54     ()
55
56 let new_proof proof =
57   (* TODO Zack: high level function which create a new proof object and register
58   * to it the widgets which must be refreshed upon status changes *)
59 (*       proof#status#attach ... *)
60   proof#status#notify ();
61   set_proof (Some proof)
62
63 let quit () = (* quit program, asking for confirmation if needed *)
64   if not (has_proof ()) ||
65     (ask_confirmation ~gui
66       ~msg:("Proof in progress, are you sure you want to quit?") ())
67   then
68     GMain.Main.quit ()
69
70 let proof_handler =
71   { MatitaTypes.get_proof = get_proof;
72     MatitaTypes.set_proof = set_proof;
73     MatitaTypes.has_proof = has_proof;
74     MatitaTypes.new_proof = new_proof;
75     MatitaTypes.quit = quit;
76   }
77
78 let interpreter =
79   let console = gui#console in
80   new MatitaInterpreter.interpreter ~disambiguator ~proof_handler ~console ()
81
82 let _ =
83   gui#setQuitCallback quit;
84   gui#setPhraseCallback interpreter#evalPhrase;
85   gui#main#debugMenu#misc#hide ();
86   ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
87    if has_proof () &&
88       not (ask_confirmation ~gui
89         ~msg:("Proof in progress, are you sure you want to start a new one?")
90         ())
91     then
92       ()  (* abort new proof process *)
93     else
94       let input = ask_text ~gui ~msg:"Insert proof goal" ~multiline:true () in
95       let (env, metasenv, term) =
96         disambiguator#disambiguateTerm (Stream.of_string input)
97       in
98       let proof = MatitaProof.proof ~typ:term ~metasenv () in
99       new_proof proof))
100
101   (** <DEBUGGING> *)
102 let _ =
103   if BuildTimeConf.debug then begin
104     gui#main#debugMenu#misc#show ();
105     let addDebugItem ~label callback =
106       let item =
107         GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
108       in
109       ignore (item#connect#activate callback)
110     in
111     addDebugItem "interactive user uri choice" (fun _ ->
112       try
113         let uris =
114           interactive_user_uri_choice ~gui ~selection_mode:`MULTIPLE
115             ~msg:"messaggio" ~nonvars_button:true
116             ["cic:/uno.con"; "cic:/due.var"; "cic:/tre.con"; "cic:/quattro.con";
117             "cic:/cinque.var"]
118         in
119         List.iter prerr_endline uris
120       with MatitaGtkMisc.Cancel -> MatitaTypes.error "no choice");
121     addDebugItem "toggle auto disambiguation" (fun _ ->
122       Helm_registry.set_bool "matita.auto_disambiguation"
123         (not (Helm_registry.get_bool "matita.auto_disambiguation")));
124     addDebugItem "mono line text input" (fun _ ->
125       prerr_endline (ask_text ~gui ~title:"title" ~msg:"message" ()));
126     addDebugItem "multi line text input" (fun _ ->
127       prerr_endline
128         (ask_text ~gui ~title:"title" ~multiline:true ~msg:"message" ()));
129     addDebugItem "dump proof status to stdout" (fun _ ->
130       print_endline ((get_proof ())#status#toString));
131   end
132   (** </DEBUGGING> *)
133
134 let _ = GtkThread.main ()
135