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 (** {2 Internal status} *)
34 let (get_proof, set_proof, has_proof) =
35 let (current_proof: MatitaTypes.proof option ref) = ref None in
36 ((fun () -> (* get_proof *)
37 match !current_proof with
39 | None -> failwith "No current proof"),
40 (fun proof -> (* set_proof *)
41 current_proof := proof),
42 (fun () -> (* has_proof *)
43 !current_proof <> None))
45 (** {2 Initialization} *)
48 Helm_registry.load_from "matita.conf.xml";
49 GtkMain.Rc.add_default_file BuildTimeConf.gtkrc;
51 let parserr = new MatitaDisambiguator.parserr ()
54 ~host:(Helm_registry.get "db.host")
55 ~user:(Helm_registry.get "db.user")
56 ~database:(Helm_registry.get "db.database")
58 let gui = MatitaGui.instance ()
60 new MatitaDisambiguator.disambiguator ~parserr ~dbd
61 ~chooseUris:(interactive_user_uri_choice ~gui)
62 ~chooseInterp:(interactive_interp_choice ~gui)
65 let frame = GBin.frame ~packing:(gui#proof#scrolledProof#add) ~show:true () in
66 MatitaMathView.proof_viewer ~show:true ~packing:(frame#add) ()
67 let sequent_viewer = MatitaMathView.sequent_viewer ~show:true ()
70 debug_print (sprintf "Setting goal %d" goal);
71 if not (has_proof ()) then assert false;
72 (get_proof ())#set_goal goal
74 MatitaMathView.sequents_viewer ~notebook:gui#main#sequentsNotebook
75 ~sequent_viewer ~set_goal ()
77 let new_proof (proof: MatitaTypes.proof) =
78 let xmldump_observer _ _ = print_endline proof#toString in
79 let proof_observer _ (status, ()) =
80 debug_print "proof_observer";
81 let ((uri_opt, _, _, _), _) = status in
82 let uri = MatitaTypes.unopt_uri uri_opt in
83 debug_print "apply transformation";
84 proof_viewer#load_proof status;
85 debug_print "/proof_observer"
87 let sequents_observer _ (((_, metasenv, _, _), goal_opt), ()) =
88 sequents_viewer#reset;
92 sequents_viewer#load_sequents metasenv;
93 sequents_viewer#goto_sequent goal)
95 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
97 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
99 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
102 set_proof (Some proof)
104 let quit () = (* quit program, asking for confirmation if needed *)
105 if not (has_proof ()) ||
106 (ask_confirmation ~gui
107 ~msg:("Proof in progress, are you sure you want to quit?") ())
112 if has_proof () then begin
114 sequents_viewer#reset
118 { MatitaTypes.get_proof = get_proof;
119 MatitaTypes.abort_proof = abort_proof;
120 MatitaTypes.set_proof = set_proof;
121 MatitaTypes.has_proof = has_proof;
122 MatitaTypes.new_proof = new_proof;
123 MatitaTypes.quit = quit;
127 let console = gui#console in
128 new MatitaInterpreter.interpreter ~disambiguator ~proof_handler ~console ()
130 (** prompt the user for the textual input of a term and disambiguate it *)
131 let ask_term ?(title = "term input") ?(msg = "insert term") () =
132 match gui#askText ~title ~msg () with
134 let (_, _, term) = disambiguator#disambiguateTerm (Stream.of_string t) in
139 gui#setQuitCallback quit;
140 gui#setPhraseCallback interpreter#evalPhrase;
141 gui#main#debugMenu#misc#hide ();
142 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
144 not (ask_confirmation ~gui
145 ~msg:("Proof in progress, are you sure you want to start a new one?")
148 () (* abort new proof process *)
150 let input = ask_text ~gui ~msg:"Insert proof goal" ~multiline:true () in
151 let (env, metasenv, expr) =
152 disambiguator#disambiguateTerm (Stream.of_string input)
154 let proof = MatitaProof.proof ~typ:expr ~metasenv () in
156 ignore (gui#main#openMenuItem#connect#activate (fun _ ->
157 match gui#chooseFile () with
159 | Some f when is_proof_script f ->
160 gui#script#scriptTextView#buffer#set_text (input_file f);
161 gui#script#scriptWin#show ();
162 gui#main#showScriptMenuItem#set_active true
164 gui#console#echo_error (sprintf
165 "Don't know what to do with file: %s\nUnrecognized file format."
167 let tac_w_term name tac _ =
168 match ask_term ~title:name ~msg:("term for " ^ name) () with
169 | Some term -> (get_proof ())#apply_tactic (tac ~term)
172 let tac _ tac _ = (get_proof ())#apply_tactic tac in
173 let tbar = gui#toolbar in
174 ignore (tbar#introsButton#connect#clicked (tac "intros" (Tactics.intros ())));
175 ignore (tbar#applyButton#connect#clicked (tac_w_term "apply" Tactics.apply));
176 ignore (tbar#exactButton#connect#clicked (tac_w_term "exact" Tactics.exact));
177 ignore (tbar#elimButton#connect#clicked (tac_w_term "elim"
178 Tactics.elim_intros_simpl));
179 ignore (tbar#elimTypeButton#connect#clicked (tac_w_term "elim type"
181 ignore (tbar#splitButton#connect#clicked (tac "split" Tactics.split));
182 ignore (tbar#leftButton#connect#clicked (tac "left" Tactics.left));
183 ignore (tbar#rightButton#connect#clicked (tac "right" Tactics.right));
184 ignore (tbar#existsButton#connect#clicked (tac "exists" Tactics.exists));
185 ignore (tbar#reflexivityButton#connect#clicked (tac "reflexivity"
186 Tactics.reflexivity));
187 ignore (tbar#symmetryButton#connect#clicked (tac "symmetry"
189 ignore (tbar#transitivityButton#connect#clicked (tac_w_term "transitivity"
190 Tactics.transitivity));
191 ignore (tbar#assumptionButton#connect#clicked (tac "assumption"
192 Tactics.assumption));
193 ignore (tbar#cutButton#connect#clicked (tac_w_term "cut"
194 (Tactics.cut ?mk_fresh_name_callback:None)));
195 ignore (tbar#autoButton#connect#clicked (tac "auto" (Tactics.auto ~dbd)))
200 let domImpl = lazy (Gdome.domImplementation ()) in
203 ((Lazy.force domImpl)#saveDocumentToFile ~doc ~name:dest ~indent:true ())
206 if BuildTimeConf.debug then begin
207 gui#main#debugMenu#misc#show ();
208 let addDebugItem ~label callback =
210 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
212 ignore (item#connect#activate callback)
214 addDebugItem "interactive user uri choice" (fun _ ->
217 interactive_user_uri_choice ~gui ~selection_mode:`MULTIPLE
218 ~msg:"messaggio" ~nonvars_button:true
219 ["cic:/uno.con"; "cic:/due.var"; "cic:/tre.con"; "cic:/quattro.con";
222 List.iter prerr_endline uris
223 with MatitaGtkMisc.Cancel -> MatitaTypes.error "no choice");
224 addDebugItem "toggle auto disambiguation" (fun _ ->
225 Helm_registry.set_bool "matita.auto_disambiguation"
226 (not (Helm_registry.get_bool "matita.auto_disambiguation")));
227 addDebugItem "mono line text input" (fun _ ->
228 prerr_endline (ask_text ~gui ~title:"title" ~msg:"message" ()));
229 addDebugItem "multi line text input" (fun _ ->
231 (ask_text ~gui ~title:"title" ~multiline:true ~msg:"message" ()));
232 addDebugItem "dump proof status to stdout" (fun _ ->
233 print_endline ((get_proof ())#toString));
238 let _ = GtkThread.main ()