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