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/
32 module DB = BuildTimeConf.DB
34 (** {2 Internal status} *)
36 let (get_proof, set_proof, has_proof) =
37 let (current_proof: MatitaTypes.proof option ref) = ref None in
38 ((fun () -> (* get_proof *)
39 match !current_proof with
41 | None -> failwith "No current proof"),
42 (fun proof -> (* set_proof *)
43 current_proof := proof),
44 (fun () -> (* has_proof *)
45 !current_proof <> None))
47 (** {2 Initialization} *)
50 Helm_registry.load_from "matita.conf.xml";
51 GtkMain.Rc.add_default_file BuildTimeConf.gtkrc;
53 let parserr = new MatitaDisambiguator.parserr ()
55 new DB.connection ~host:(Helm_registry.get "db.host")
56 ~user:(Helm_registry.get "db.user") (Helm_registry.get "db.database")
57 let gui = MatitaGui.instance ()
59 new MatitaDisambiguator.disambiguator ~parserr ~dbh
60 ~chooseUris:(interactive_user_uri_choice ~gui)
61 ~chooseInterp:(interactive_interp_choice ~gui)
64 let frame = GBin.frame ~packing:(gui#proof#scrolledProof#add) ~show:true () in
65 MatitaMathView.proof_viewer ~show:true ~packing:(frame#add) ()
66 let sequent_viewer = MatitaMathView.sequent_viewer ~show:true ()
69 debug_print (sprintf "Setting goal %d" goal);
70 if not (has_proof ()) then assert false;
71 (get_proof ())#set_goal goal
73 MatitaMathView.sequents_viewer ~notebook:gui#main#sequentsNotebook
74 ~sequent_viewer ~set_goal ()
76 let new_proof (proof: MatitaTypes.proof) =
77 let xmldump_observer _ _ = print_endline proof#toString in
78 let proof_observer _ (status, ()) =
79 debug_print "proof_observer";
80 let ((uri_opt, _, _, _), _) = status in
81 let uri = MatitaTypes.unopt_uri uri_opt in
82 debug_print "apply transformation";
83 proof_viewer#load_proof status;
84 debug_print "/proof_observer"
86 let sequents_observer _ (((_, metasenv, _, _), goal_opt), ()) =
87 sequents_viewer#reset;
91 sequents_viewer#load_sequents metasenv;
92 sequents_viewer#goto_sequent goal)
94 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
96 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
98 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
101 set_proof (Some proof)
103 let quit () = (* quit program, asking for confirmation if needed *)
104 if not (has_proof ()) ||
105 (ask_confirmation ~gui
106 ~msg:("Proof in progress, are you sure you want to quit?") ())
111 if has_proof () then begin
113 sequents_viewer#reset
117 { MatitaTypes.get_proof = get_proof;
118 MatitaTypes.abort_proof = abort_proof;
119 MatitaTypes.set_proof = set_proof;
120 MatitaTypes.has_proof = has_proof;
121 MatitaTypes.new_proof = new_proof;
122 MatitaTypes.quit = quit;
126 let console = gui#console in
127 new MatitaInterpreter.interpreter ~disambiguator ~proof_handler ~console ()
130 gui#setQuitCallback quit;
131 gui#setPhraseCallback interpreter#evalPhrase;
132 gui#main#debugMenu#misc#hide ();
133 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
135 not (ask_confirmation ~gui
136 ~msg:("Proof in progress, are you sure you want to start a new one?")
139 () (* abort new proof process *)
141 let input = ask_text ~gui ~msg:"Insert proof goal" ~multiline:true () in
142 let (env, metasenv, expr) =
143 disambiguator#disambiguateTerm (Stream.of_string input)
145 let proof = MatitaProof.proof ~typ:expr ~metasenv () in
147 ignore (gui#main#openMenuItem#connect#activate (fun _ ->
148 match gui#chooseFile () with
150 | Some f when is_proof_script f ->
151 gui#script#scriptTextView#buffer#set_text (input_file f)
153 gui#console#echo_error (sprintf
154 "Don't know what to do with file: %s\nUnrecognized file format." f)))
159 let domImpl = lazy (Gdome.domImplementation ()) in
162 ((Lazy.force domImpl)#saveDocumentToFile ~doc ~name:dest ~indent:true ())
165 if BuildTimeConf.debug then begin
166 gui#main#debugMenu#misc#show ();
167 let addDebugItem ~label callback =
169 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
171 ignore (item#connect#activate callback)
173 addDebugItem "interactive user uri choice" (fun _ ->
176 interactive_user_uri_choice ~gui ~selection_mode:`MULTIPLE
177 ~msg:"messaggio" ~nonvars_button:true
178 ["cic:/uno.con"; "cic:/due.var"; "cic:/tre.con"; "cic:/quattro.con";
181 List.iter prerr_endline uris
182 with MatitaGtkMisc.Cancel -> MatitaTypes.error "no choice");
183 addDebugItem "toggle auto disambiguation" (fun _ ->
184 Helm_registry.set_bool "matita.auto_disambiguation"
185 (not (Helm_registry.get_bool "matita.auto_disambiguation")));
186 addDebugItem "mono line text input" (fun _ ->
187 prerr_endline (ask_text ~gui ~title:"title" ~msg:"message" ()));
188 addDebugItem "multi line text input" (fun _ ->
190 (ask_text ~gui ~title:"title" ~multiline:true ~msg:"message" ()));
191 addDebugItem "dump proof status to stdout" (fun _ ->
192 print_endline ((get_proof ())#toString));
197 let _ = GtkThread.main ()