1 (* Copyright (C) 2004, 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://helm.cs.unibo.it/
30 (** {2 Internal status} *)
32 let (get_proof, set_proof, has_proof) =
33 let (current_proof: MatitaTypes.proof option ref) = ref None in
34 ((fun () -> (* get_proof *)
35 match !current_proof with
37 | None -> failwith "No current proof"),
38 (fun proof -> (* set_proof *)
39 current_proof := proof),
40 (fun () -> (* has_proof *)
41 !current_proof <> None))
45 let debug_print = MatitaTypes.debug_print
48 let domImpl = lazy (Gdome.domImplementation ()) in
51 ((Lazy.force domImpl)#saveDocumentToFile ~doc ~name:dest ~indent:true ())
53 (** {2 Initialization} *)
56 GtkMain.Rc.add_default_file BuildTimeConf.gtkrc;
58 let _ = Helm_registry.load_from "matita.conf.xml"
59 let _ = GMain.Main.init ()
60 let parserr = new MatitaDisambiguator.parserr ()
61 let mqiconn = MQIConn.init ()
62 let gui = MatitaGui.instance ()
64 new MatitaDisambiguator.disambiguator ~parserr ~mqiconn
65 ~chooseUris:(interactive_user_uri_choice ~gui)
66 ~chooseInterp:(interactive_interp_choice ~gui)
69 let frame = GBin.frame ~packing:(gui#proof#scrolledProof#add) ~show:true () in
70 MatitaMathView.proof_viewer ~show:true ~packing:(frame#add) ()
71 let sequent_viewer = MatitaMathView.sequent_viewer ~show:true ()
73 MatitaMathView.sequents_viewer ~notebook:gui#main#sequentsNotebook
76 let new_proof (proof: MatitaTypes.proof) =
77 let xmldump_observer _ _ = print_endline proof#toString in
78 let proof_observer _ (status, (proof_metadata, _)) =
79 debug_print "proof_observer";
80 let (acic, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts,
81 ids_to_inner_types, ids_to_conjectures, ids_to_hypotheses) =
84 let ((uri_opt, _, _, _), _) = status in
85 let uri = MatitaTypes.unopt_uri uri_opt in
86 debug_print "apply transformation";
88 ApplyTransformation.mml_of_cic_object
89 ~explode_all:true uri acic ids_to_inner_sorts ids_to_inner_types
91 if BuildTimeConf.debug then save_dom ~doc:mathml ~dest:"/tmp/matita.xml";
92 proof_viewer#load_proof mathml proof_metadata;
93 debug_print "/proof_observer"
95 let sequents_observer _ ((proof, goal_opt), (_, sequents_metadata)) =
96 sequents_viewer#reset;
100 sequents_viewer#load_sequents sequents_metadata;
101 sequents_viewer#goto_sequent goal)
103 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
105 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
107 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
110 set_proof (Some proof)
112 let quit () = (* quit program, asking for confirmation if needed *)
113 if not (has_proof ()) ||
114 (ask_confirmation ~gui
115 ~msg:("Proof in progress, are you sure you want to quit?") ())
120 if has_proof () then begin
122 sequents_viewer#reset
126 { MatitaTypes.get_proof = get_proof;
127 MatitaTypes.abort_proof = abort_proof;
128 MatitaTypes.has_proof = has_proof;
129 MatitaTypes.new_proof = new_proof;
130 MatitaTypes.quit = quit;
134 let console = gui#console in
135 new MatitaInterpreter.interpreter ~disambiguator ~proof_handler ~console ()
138 gui#setQuitCallback quit;
139 gui#setPhraseCallback interpreter#evalPhrase;
140 gui#main#debugMenu#misc#hide ();
141 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
143 not (ask_confirmation ~gui
144 ~msg:("Proof in progress, are you sure you want to start a new one?")
147 () (* abort new proof process *)
149 let input = ask_text ~gui ~msg:"Insert proof goal" ~multiline:true () in
150 let (env, metasenv, expr) =
151 disambiguator#disambiguateTerm (Stream.of_string input)
153 let proof = MatitaProof.proof ~typ:expr ~metasenv () in
158 if BuildTimeConf.debug then begin
159 gui#main#debugMenu#misc#show ();
160 let addDebugItem ~label callback =
162 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
164 ignore (item#connect#activate callback)
166 addDebugItem "interactive user uri choice" (fun _ ->
169 interactive_user_uri_choice ~gui ~selection_mode:`MULTIPLE
170 ~msg:"messaggio" ~nonvars_button:true
171 ["cic:/uno.con"; "cic:/due.var"; "cic:/tre.con"; "cic:/quattro.con";
174 List.iter prerr_endline uris
175 with MatitaGtkMisc.Cancel -> MatitaTypes.error "no choice");
176 addDebugItem "toggle auto disambiguation" (fun _ ->
177 Helm_registry.set_bool "matita.auto_disambiguation"
178 (not (Helm_registry.get_bool "matita.auto_disambiguation")));
179 addDebugItem "mono line text input" (fun _ ->
180 prerr_endline (ask_text ~gui ~title:"title" ~msg:"message" ()));
181 addDebugItem "multi line text input" (fun _ ->
183 (ask_text ~gui ~title:"title" ~multiline:true ~msg:"message" ()));
184 addDebugItem "dump proof status to stdout" (fun _ ->
185 print_endline ((get_proof ())#toString));
189 let _ = GtkThread.main ()