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)
64 let proof_viewer = MatitaMathView.proof_viewer_instance ()
65 let sequent_viewer = MatitaMathView.sequent_viewer ~show:true ()
68 if not (has_proof ()) then assert false;
69 (get_proof ())#set_goal goal
71 MatitaMathView.sequents_viewer ~notebook:gui#main#sequentsNotebook
72 ~sequent_viewer ~set_goal ()
74 let new_proof (proof: MatitaTypes.proof) =
75 let proof_observer _ (status, ()) =
76 let ((uri_opt, _, _, _), _) = status in
77 proof_viewer#load_proof status;
79 let sequents_observer _ (((_, metasenv, _, _), goal_opt), ()) =
80 sequents_viewer#reset;
84 sequents_viewer#load_sequents metasenv;
85 sequents_viewer#goto_sequent goal)
87 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
89 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
92 set_proof (Some proof)
94 let quit () = (* quit program, asking for confirmation if needed *)
95 if not (has_proof ()) ||
96 (ask_confirmation ~gui
97 ~msg:("Proof in progress, are you sure you want to quit?") ())
102 if has_proof () then begin
104 sequents_viewer#reset
108 { MatitaTypes.get_proof = get_proof;
109 MatitaTypes.abort_proof = abort_proof;
110 MatitaTypes.set_proof = set_proof;
111 MatitaTypes.has_proof = has_proof;
112 MatitaTypes.new_proof = new_proof;
113 MatitaTypes.quit = quit;
117 let console = gui#console in
118 new MatitaInterpreter.interpreter
119 ~disambiguator ~proof_handler ~console ~dbd ()
121 (** {2 Script window handling} *)
123 let script_forward _ =
124 let buf = gui#script#scriptTextView#buffer in
125 let locked_iter = buf#get_iter_at_mark (`NAME "locked") in
127 interpreter#evalPhrase
128 (buf#get_text ~start:locked_iter ~stop:buf#end_iter ());
130 gui#lockScript (locked_iter#offset + interpreter#endOffset)
133 let buf = gui#script#scriptTextView#buffer in
134 let locked_iter = buf#get_iter_at_mark (`NAME "locked") in
135 let cursor_iter = buf#get_iter_at_mark (`NAME "insert") in
136 let raw_text = buf#get_text ~start:locked_iter ~stop:cursor_iter () in
137 let len = String.length raw_text in
138 let rec parse offset =
139 if offset < len then begin
141 interpreter#evalPhrase (String.sub raw_text offset (len - offset))
143 let new_offset = interpreter#endOffset + offset in
144 gui#lockScript (new_offset + locked_iter#offset);
154 let script_back _ = not_implemented "script_back"
156 let load_script fname =
157 gui#script#scriptTextView#buffer#set_text (input_file fname);
158 gui#script#scriptWin#show ();
159 gui#main#showScriptMenuItem#set_active true
161 (** {2 GUI callbacks} *)
164 gui#setQuitCallback quit;
165 gui#setPhraseCallback interpreter#evalPhrase;
166 gui#main#debugMenu#misc#hide ();
167 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
168 gui#console#clear ();
169 gui#console#show ~msg:"theorem " ()));
170 ignore (gui#main#openMenuItem#connect#activate (fun _ ->
171 match gui#chooseFile () with
173 | Some f when is_proof_script f -> load_script f
175 gui#console#echo_error (sprintf
176 "Don't know what to do with file: %s\nUnrecognized file format."
178 connect_button gui#script#scriptWinForwardButton script_forward;
179 connect_button gui#script#scriptWinBackButton script_back;
180 connect_button gui#script#scriptWinJumpButton script_jump;
181 let module A = TacticAst in
182 let hole = CicAst.UserInput in
183 let tac ast _ = ignore (interpreter#evalAst (A.Tactic ast)) in
184 let tac_w_term ast _ =
185 gui#console#clear ();
186 gui#console#show ~msg:(TacticAstPp.pp_tactic ast) ();
187 gui#main#mainWin#present ()
189 let tbar = gui#toolbar in
190 connect_button tbar#introsButton (tac (A.Intros (None, [])));
191 connect_button tbar#applyButton (tac_w_term (A.Apply hole));
192 connect_button tbar#exactButton (tac_w_term (A.Exact hole));
193 connect_button tbar#elimButton (tac_w_term (A.Elim (hole, None)));
194 connect_button tbar#elimTypeButton (tac_w_term (A.ElimType hole));
195 connect_button tbar#splitButton (tac A.Split);
196 connect_button tbar#leftButton (tac A.Left);
197 connect_button tbar#rightButton (tac A.Right);
198 connect_button tbar#existsButton (tac A.Exists);
199 connect_button tbar#reflexivityButton (tac A.Reflexivity);
200 connect_button tbar#symmetryButton (tac A.Symmetry);
201 connect_button tbar#transitivityButton (tac_w_term (A.Transitivity hole));
203 (* connect_button tbar#simplifyButton FINQUI; *)
205 connect_button tbar#assumptionButton (tac A.Assumption);
206 connect_button tbar#cutButton (tac_w_term (A.Cut hole));
207 connect_button tbar#autoButton (tac A.Auto)
212 if BuildTimeConf.debug then begin
213 gui#main#debugMenu#misc#show ();
214 let addDebugItem ~label callback =
216 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
218 ignore (item#connect#activate callback)
220 addDebugItem "toggle auto disambiguation" (fun _ ->
221 Helm_registry.set_bool "matita.auto_disambiguation"
222 (not (Helm_registry.get_bool "matita.auto_disambiguation")));
223 addDebugItem "dump proof status to stdout" (fun _ ->
224 print_endline ((get_proof ())#toString));
225 addDebugItem "print selected terms" (fun () ->
228 (fun t -> incr i; debug_print (sprintf "%d: %s" !i (CicPp.ppterm t)))
229 sequent_viewer#get_selected_terms)
236 load_script Sys.argv.(1)
237 with Invalid_argument _ -> ());