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 ()
74 debug_print (sprintf "Setting goal %d" goal);
75 if not (has_proof ()) then assert false;
76 (get_proof ())#set_goal goal
78 MatitaMathView.sequents_viewer ~notebook:gui#main#sequentsNotebook
79 ~sequent_viewer ~set_goal ()
81 let new_proof (proof: MatitaTypes.proof) =
82 let xmldump_observer _ _ = print_endline proof#toString in
83 let proof_observer _ (status, ()) =
84 debug_print "proof_observer";
85 let ((uri_opt, _, _, _), _) = status in
86 let uri = MatitaTypes.unopt_uri uri_opt in
87 debug_print "apply transformation";
88 proof_viewer#load_proof status;
89 debug_print "/proof_observer"
91 let sequents_observer _ (((_, metasenv, _, _), goal_opt), ()) =
92 sequents_viewer#reset;
96 sequents_viewer#load_sequents metasenv;
97 sequents_viewer#goto_sequent goal)
99 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
101 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
103 ignore (proof#attach_observer ~interested_in:StatefulProofEngine.all_events
106 set_proof (Some proof)
108 let quit () = (* quit program, asking for confirmation if needed *)
109 if not (has_proof ()) ||
110 (ask_confirmation ~gui
111 ~msg:("Proof in progress, are you sure you want to quit?") ())
116 if has_proof () then begin
118 sequents_viewer#reset
122 { MatitaTypes.get_proof = get_proof;
123 MatitaTypes.abort_proof = abort_proof;
124 MatitaTypes.set_proof = set_proof;
125 MatitaTypes.has_proof = has_proof;
126 MatitaTypes.new_proof = new_proof;
127 MatitaTypes.quit = quit;
131 let console = gui#console in
132 new MatitaInterpreter.interpreter ~disambiguator ~proof_handler ~console ()
135 gui#setQuitCallback quit;
136 gui#setPhraseCallback interpreter#evalPhrase;
137 gui#main#debugMenu#misc#hide ();
138 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
140 not (ask_confirmation ~gui
141 ~msg:("Proof in progress, are you sure you want to start a new one?")
144 () (* abort new proof process *)
146 let input = ask_text ~gui ~msg:"Insert proof goal" ~multiline:true () in
147 let (env, metasenv, expr) =
148 disambiguator#disambiguateTerm (Stream.of_string input)
150 let proof = MatitaProof.proof ~typ:expr ~metasenv () in
155 if BuildTimeConf.debug then begin
156 gui#main#debugMenu#misc#show ();
157 let addDebugItem ~label callback =
159 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
161 ignore (item#connect#activate callback)
163 addDebugItem "interactive user uri choice" (fun _ ->
166 interactive_user_uri_choice ~gui ~selection_mode:`MULTIPLE
167 ~msg:"messaggio" ~nonvars_button:true
168 ["cic:/uno.con"; "cic:/due.var"; "cic:/tre.con"; "cic:/quattro.con";
171 List.iter prerr_endline uris
172 with MatitaGtkMisc.Cancel -> MatitaTypes.error "no choice");
173 addDebugItem "toggle auto disambiguation" (fun _ ->
174 Helm_registry.set_bool "matita.auto_disambiguation"
175 (not (Helm_registry.get_bool "matita.auto_disambiguation")));
176 addDebugItem "mono line text input" (fun _ ->
177 prerr_endline (ask_text ~gui ~title:"title" ~msg:"message" ()));
178 addDebugItem "multi line text input" (fun _ ->
180 (ask_text ~gui ~title:"title" ~multiline:true ~msg:"message" ()));
181 addDebugItem "dump proof status to stdout" (fun _ ->
182 print_endline ((get_proof ())#toString));
186 let _ = GtkThread.main ()