]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/matita.ml
Large commit: refactoring of the code of the interface.
[helm.git] / matita / matita / matita.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 open MatitaGtkMisc
31 open GrafiteTypes
32
33 (** {2 Initialization} *)
34
35 let _ = 
36   MatitaInit.add_cmdline_spec
37     ["-tptppath",Arg.String 
38       (fun s -> Helm_registry.set_string "matita.tptppath" s),
39       "Where to find the Axioms/ and Problems/ directory"];
40   MatitaInit.initialize_all ()
41 ;;
42
43 (* let _ = Saturation.init () (* ALB to link paramodulation *) *)
44
45 (** {2 GUI callbacks} *)
46
47 let gui = MatitaGui.instance ()
48
49 let script =
50   let s = 
51     MatitaScript.script 
52       ~urichooser:(fun source_view uris ->
53         try
54           MatitaGui.interactive_uri_choice ~selection_mode:`SINGLE
55           ~title:"Matita: URI chooser" 
56           ~msg:"Select the URI" ~hide_uri_entry:true
57           ~hide_try:true ~ok_label:"_Apply" ~ok_action:`SELECT
58           ~copy_cb:(fun s -> source_view#buffer#insert ("\n"^s^"\n"))
59           () ~id:"boh?" uris
60         with MatitaTypes.Cancel -> [])
61       ~ask_confirmation:
62         (fun ~title ~message -> 
63             MatitaGtkMisc.ask_confirmation ~title ~message 
64             ~parent:gui#main#toplevel ())
65       ()
66   in
67   Predefined_virtuals.load_predefined_virtuals ();
68   Predefined_virtuals.load_predefined_classes ();
69   s
70   
71   (* math viewers *)
72 let _ =
73   let sequents_viewer = MatitaMathView.sequentsViewer_instance () in
74   sequents_viewer#load_logo;
75   let browser_observer _ = MatitaMathView.refresh_all_browsers () in
76   let sequents_observer grafite_status =
77     sequents_viewer#reset;
78     match grafite_status#ng_mode with
79        `ProofMode ->
80         sequents_viewer#nload_sequents grafite_status;
81         (try
82           script#setGoal
83            (Some (Continuationals.Stack.find_goal grafite_status#stack));
84           let goal =
85            match script#goal with
86               None -> assert false
87             | Some n -> n
88           in
89            sequents_viewer#goto_sequent grafite_status goal
90         with Failure _ -> script#setGoal None);
91      | `CommandMode -> sequents_viewer#load_logo
92   in
93   script#addObserver sequents_observer;
94   script#addObserver browser_observer
95
96   (** {{{ Debugging *)
97 let _ =
98   if BuildTimeConf.debug ||
99      Helm_registry.get_bool "matita.debug_menu" 
100   then begin
101     gui#main#debugMenu#misc#show ();
102     let addDebugItem label callback =
103       let item =
104         GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
105       ignore (item#connect#activate callback) 
106     in
107     let addDebugCheckbox label ?(init=false) callback =
108       let item =
109         GMenu.check_menu_item 
110           ~packing:gui#main#debugMenu_menu#append ~label () in
111       item#set_active init;
112       ignore (item#connect#toggled (callback item)) 
113     in
114     let addDebugSeparator () =
115       ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
116     in
117     addDebugItem "dump aliases" (fun _ ->
118       let status = script#grafite_status in
119       GrafiteDisambiguate.dump_aliases prerr_endline "" status);
120 (* FG: DEBUGGING   
121     addDebugItem "dump interpretations" (fun _ ->
122       let status = script#lexicon_status in
123       let filter = 
124        List.filter (function LexiconAst.Interpretation _ -> true | _ -> false)
125       in
126       HLog.debug (String.concat "\n"
127        (List.fold_right
128          (fun x l -> (LexiconAstPp.pp_command x)::l)
129          (filter status.LexiconEngine.lexicon_content_rev) [])));
130 *)
131     addDebugSeparator ();
132     addDebugCheckbox "high level pretty printer" ~init:true
133       (fun mi () -> assert false (* MATITA 1.0 *));
134     addDebugSeparator ();
135     addDebugItem "always show all disambiguation errors"
136       (fun _ -> MatitaGui.all_disambiguation_passes := true);
137     addDebugItem "prune disambiguation errors"
138       (fun _ -> MatitaGui.all_disambiguation_passes := false);
139     addDebugSeparator ();
140     addDebugCheckbox "multiple disambiguation passes" ~init:true
141       (fun mi () -> MultiPassDisambiguator.only_one_pass := mi#active);
142     addDebugCheckbox "tactics logging" 
143       (fun mi () -> NTacStatus.debug := mi#active);
144     addDebugCheckbox "disambiguation/refiner/unification/metasubst logging"
145       (fun mi () -> NCicRefiner.debug := mi#active; NCicUnification.debug :=
146               mi#active; MultiPassDisambiguator.debug := mi#active; NCicMetaSubst.debug := mi#active);
147     addDebugCheckbox "reduction logging"
148       (fun mi () -> NCicReduction.debug := mi#active);
149     addDebugSeparator ();
150     addDebugItem "Expand virtuals"
151     (fun _ -> (MatitaScript.current ())#expandAllVirtuals);
152   end
153   (** Debugging }}} *)
154
155   (** {2 Main} *)
156
157 let _ =
158   at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
159   Sys.catch_break true;
160   let args = Helm_registry.get_list Helm_registry.string "matita.args" in
161   (try gui#loadScript (List.hd args) with Failure _ -> ());
162   gui#main#mainWin#show ();
163   try
164    GtkThread.main ()
165   with Sys.Break ->
166    Sys.set_signal Sys.sigint
167     (Sys.Signal_handle
168       (fun _ ->
169         prerr_endline "Still cleaning the library: don't be impatient!"));
170    prerr_endline "Matita is cleaning up. Please wait.";
171    let baseuri = 
172     (MatitaScript.current ())#grafite_status#baseuri
173    in
174      LibraryClean.clean_baseuris [baseuri]
175
176 (* vim:set foldmethod=marker: *)