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 Initialization} *)
35 Helm_registry.load_from "matita.conf.xml"; (* read conf *)
37 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
38 MatitaDb.clean_owner_environment ();
39 MatitaDb.create_owner_environment ();
40 GtkMain.Rc.add_default_file BuildTimeConf.gtkrc; (* loads gtk rc files *)
41 ignore (GMain.Main.init ())
43 let gui = MatitaGui.instance ()
44 let _ = (* set disambiguator callbacks *)
45 let disambiguator = MatitaDisambiguator.instance () in
46 disambiguator#setChooseUris (interactive_user_uri_choice ~gui);
47 disambiguator#setChooseInterp (interactive_interp_choice ~gui)
48 let _ = (* environment trust *)
49 CicEnvironment.set_trust
50 (let trust = Helm_registry.get_bool "matita.environment_trust" in
53 let currentProof = MatitaProof.instance ()
56 let sequent_viewer = MatitaMathView.sequent_viewer ~show:true ()
59 if not (currentProof#onGoing ()) then assert false;
60 currentProof#proof#set_goal goal
62 MatitaMathView.sequents_viewer ~notebook:gui#main#sequentsNotebook
63 ~sequent_viewer ~set_goal ()
64 let _ = (* attach observers to proof status *)
65 let browser_observer _ _ = MatitaMathView.refresh_all_browsers () in
66 let sequents_observer _ (((_, metasenv, _, _), goal_opt), ()) =
67 sequents_viewer#reset;
71 sequents_viewer#load_sequents metasenv;
72 sequents_viewer#goto_sequent goal)
74 currentProof#addObserver sequents_observer;
75 currentProof#addObserver browser_observer;
76 currentProof#connect `Quit (fun () ->
77 (* quit program, asking for confirmation if needed *)
78 if not (currentProof#onGoing ()) ||
79 (ask_confirmation ~gui
80 ~msg:("Proof in progress, are you sure you want to quit?") ())
84 currentProof#connect `Abort (fun () -> sequents_viewer#reset; false)
87 let mathViewer = MatitaMathView.mathViewer () in
88 MatitaInterpreter.interpreter ~console:gui#console ~mathViewer ()
90 let href_callback uri =
91 let term = CicAst.Uri (uri, None) in
92 ignore (interpreter#evalAst (TacticAst.Command (TacticAst.Check term)))
94 sequent_viewer#set_href_callback (Some href_callback)
96 (** {2 Script window handling} *)
98 let script_forward _ =
99 let buf = gui#script#scriptTextView#buffer in
100 let locked_iter = buf#get_iter_at_mark (`NAME "locked") in
101 let (success, hide) =
102 interpreter#evalPhrase
103 (buf#get_text ~start:locked_iter ~stop:buf#end_iter ())
106 gui#lockScript (locked_iter#offset + interpreter#endOffset)
109 let buf = gui#script#scriptTextView#buffer in
110 let locked_iter = buf#get_iter_at_mark (`NAME "locked") in
111 let cursor_iter = buf#get_iter_at_mark (`NAME "insert") in
112 let raw_text = buf#get_text ~start:locked_iter ~stop:cursor_iter () in
113 let len = String.length raw_text in
114 let rec parse offset =
115 if offset < len then begin
116 let (success, hide) =
117 interpreter#evalPhrase (String.sub raw_text offset (len - offset))
119 if success then begin
120 let new_offset = interpreter#endOffset + offset in
121 gui#lockScript (new_offset + locked_iter#offset);
131 let script_back _ = not_implemented "script_back"
133 let load_script fname =
134 gui#script#scriptTextView#buffer#set_text (input_file fname);
135 gui#script#scriptWin#show ();
136 gui#main#showScriptMenuItem#set_active true
138 (** {2 GUI callbacks} *)
141 gui#setQuitCallback currentProof#quit;
142 gui#setPhraseCallback interpreter#evalPhrase;
143 gui#main#debugMenu#misc#hide ();
144 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
145 gui#console#clear ();
146 gui#console#show ~msg:"theorem " ()));
147 ignore (gui#main#openMenuItem#connect#activate (fun _ ->
148 match gui#chooseFile () with
150 | Some f when is_proof_script f -> load_script f
152 gui#console#echo_error (sprintf
153 "Don't know what to do with file: %s\nUnrecognized file format."
155 ignore (gui#main#newCicBrowserMenuItem#connect#activate (fun _ ->
156 ignore (MatitaMathView.cicBrowser ())));
157 connect_button gui#script#scriptWinForwardButton script_forward;
158 connect_button gui#script#scriptWinBackButton script_back;
159 connect_button gui#script#scriptWinJumpButton script_jump;
160 let module A = TacticAst in
161 let hole = CicAst.UserInput in
162 let tac ast _ = ignore (interpreter#evalAst (A.Tactic ast)) in
163 let tac_w_term ast _ =
164 (* gui#console#clear (); *)
165 gui#console#show ~msg:(TacticAstPp.pp_tactic ast) ();
166 gui#main#mainWin#present ()
168 let tbar = gui#toolbar in
169 connect_button tbar#introsButton (tac (A.Intros (None, [])));
170 connect_button tbar#applyButton (tac_w_term (A.Apply hole));
171 connect_button tbar#exactButton (tac_w_term (A.Exact hole));
172 connect_button tbar#elimButton (tac_w_term (A.Elim (hole, None)));
173 connect_button tbar#elimTypeButton (tac_w_term (A.ElimType hole));
174 connect_button tbar#splitButton (tac A.Split);
175 connect_button tbar#leftButton (tac A.Left);
176 connect_button tbar#rightButton (tac A.Right);
177 connect_button tbar#existsButton (tac A.Exists);
178 connect_button tbar#reflexivityButton (tac A.Reflexivity);
179 connect_button tbar#symmetryButton (tac A.Symmetry);
180 connect_button tbar#transitivityButton (tac_w_term (A.Transitivity hole));
181 connect_button tbar#assumptionButton (tac A.Assumption);
182 connect_button tbar#cutButton (tac_w_term (A.Cut hole));
183 connect_button tbar#autoButton (tac A.Auto)
188 if BuildTimeConf.debug then begin
189 gui#main#debugMenu#misc#show ();
190 let addDebugItem ~label callback =
192 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
194 ignore (item#connect#activate callback)
196 addDebugItem "dump environment to \"env.dump\"" (fun _ ->
197 let oc = open_out "env.dump" in
198 CicEnvironment.dump_to_channel oc;
200 addDebugItem "print selected terms" (fun () ->
203 (fun t -> incr i; debug_print (sprintf "%d: %s" !i (CicPp.ppterm t)))
204 sequent_viewer#get_selected_terms);
205 addDebugItem "dump getter settings" (fun _ ->
206 prerr_endline (Http_getter_env.env_to_string ()));
207 addDebugItem "getter: update" Http_getter.update;
208 addDebugItem "getter: getalluris" (fun _ ->
209 List.iter prerr_endline (Http_getter.getalluris ()));
217 load_script Sys.argv.(1)
218 with Invalid_argument _ -> ());
220 if Filename.basename Sys.argv.(0) = "cicbrowser" then begin (* cicbrowser *)
221 Helm_registry.set "matita.mode" "cicbrowser";
222 let browser = MatitaMathView.cicBrowser () in
224 browser#loadUri Sys.argv.(1)
225 with Invalid_argument _ -> ()
226 end else begin (* matita *)
227 Helm_registry.set "matita.mode" "matita";
228 gui#main#mainWin#show ();
229 gui#toolbar#toolBarWin#show ();