]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/matita.ml
First steps towards a multi-document 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       ~source_view:gui#sourceView
53       ~urichooser:(fun uris ->
54         try
55           MatitaGui.interactive_uri_choice ~selection_mode:`SINGLE
56           ~title:"Matita: URI chooser" 
57           ~msg:"Select the URI" ~hide_uri_entry:true
58           ~hide_try:true ~ok_label:"_Apply" ~ok_action:`SELECT
59           ~copy_cb:(fun s -> gui#sourceView#buffer#insert ("\n"^s^"\n"))
60           () ~id:"boh?" uris
61         with MatitaTypes.Cancel -> [])
62       ~ask_confirmation:
63         (fun ~title ~message -> 
64             MatitaGtkMisc.ask_confirmation ~title ~message 
65             ~parent:gui#main#toplevel ())
66       ()
67   in
68   Predefined_virtuals.load_predefined_virtuals ();
69   Predefined_virtuals.load_predefined_classes ();
70   gui#sourceView#source_buffer#begin_not_undoable_action ();
71   s#reset (); 
72   s#template (); 
73   gui#sourceView#source_buffer#end_not_undoable_action ();
74   s
75   
76   (* math viewers *)
77 let _ =
78   let sequents_viewer = MatitaMathView.sequentsViewer_instance () in
79   sequents_viewer#load_logo;
80   let browser_observer _ = MatitaMathView.refresh_all_browsers () in
81   let sequents_observer grafite_status =
82     sequents_viewer#reset;
83     match grafite_status#ng_mode with
84        `ProofMode ->
85         sequents_viewer#nload_sequents grafite_status;
86         (try
87           script#setGoal
88            (Some (Continuationals.Stack.find_goal grafite_status#stack));
89           let goal =
90            match script#goal with
91               None -> assert false
92             | Some n -> n
93           in
94            sequents_viewer#goto_sequent grafite_status goal
95         with Failure _ -> script#setGoal None);
96      | `CommandMode -> sequents_viewer#load_logo
97   in
98   script#addObserver sequents_observer;
99   script#addObserver browser_observer
100
101   (** {{{ Debugging *)
102 let _ =
103   if BuildTimeConf.debug ||
104      Helm_registry.get_bool "matita.debug_menu" 
105   then begin
106     gui#main#debugMenu#misc#show ();
107     let addDebugItem label callback =
108       let item =
109         GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
110       ignore (item#connect#activate callback) 
111     in
112     let addDebugCheckbox label ?(init=false) callback =
113       let item =
114         GMenu.check_menu_item 
115           ~packing:gui#main#debugMenu_menu#append ~label () in
116       item#set_active init;
117       ignore (item#connect#toggled (callback item)) 
118     in
119     let addDebugSeparator () =
120       ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
121     in
122     addDebugItem "dump aliases" (fun _ ->
123       let status = script#grafite_status in
124       GrafiteDisambiguate.dump_aliases prerr_endline "" status);
125 (* FG: DEBUGGING   
126     addDebugItem "dump interpretations" (fun _ ->
127       let status = script#lexicon_status in
128       let filter = 
129        List.filter (function LexiconAst.Interpretation _ -> true | _ -> false)
130       in
131       HLog.debug (String.concat "\n"
132        (List.fold_right
133          (fun x l -> (LexiconAstPp.pp_command x)::l)
134          (filter status.LexiconEngine.lexicon_content_rev) [])));
135 *)
136     addDebugSeparator ();
137     addDebugCheckbox "high level pretty printer" ~init:true
138       (fun mi () -> assert false (* MATITA 1.0 *));
139     addDebugSeparator ();
140     addDebugItem "always show all disambiguation errors"
141       (fun _ -> MatitaGui.all_disambiguation_passes := true);
142     addDebugItem "prune disambiguation errors"
143       (fun _ -> MatitaGui.all_disambiguation_passes := false);
144     addDebugSeparator ();
145     addDebugCheckbox "multiple disambiguation passes" ~init:true
146       (fun mi () -> MultiPassDisambiguator.only_one_pass := mi#active);
147     addDebugCheckbox "tactics logging" 
148       (fun mi () -> NTacStatus.debug := mi#active);
149     addDebugCheckbox "disambiguation/refiner/unification/metasubst logging"
150       (fun mi () -> NCicRefiner.debug := mi#active; NCicUnification.debug :=
151               mi#active; MultiPassDisambiguator.debug := mi#active; NCicMetaSubst.debug := mi#active);
152     addDebugCheckbox "reduction logging"
153       (fun mi () -> NCicReduction.debug := mi#active);
154     addDebugSeparator ();
155     addDebugItem "Expand virtuals"
156     (fun _ -> (MatitaScript.current ())#expandAllVirtuals);
157   end
158   (** Debugging }}} *)
159
160   (** {2 Main} *)
161
162 let _ =
163   at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
164   Sys.catch_break true;
165   let args = Helm_registry.get_list Helm_registry.string "matita.args" in
166   (try gui#loadScript (List.hd args) with Failure _ -> ());
167   gui#main#mainWin#show ();
168   try
169    GtkThread.main ()
170   with Sys.Break ->
171    Sys.set_signal Sys.sigint
172     (Sys.Signal_handle
173       (fun _ ->
174         prerr_endline "Still cleaning the library: don't be impatient!"));
175    prerr_endline "Matita is cleaning up. Please wait.";
176    let baseuri = 
177     (MatitaScript.current ())#grafite_status#baseuri
178    in
179      LibraryClean.clean_baseuris [baseuri]
180
181 (* vim:set foldmethod=marker: *)