]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaGui.ml
moved lockScript to MatitaScript module
[helm.git] / helm / matita / matitaGui.ml
1 (* Copyright (C) 2004, 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 open Printf
27
28 open MatitaGeneratedGui
29 open MatitaGtkMisc
30 open MatitaMisc
31
32 class gui file =
33     (* creation order _is_ relevant for windows placement *)
34   let toolbar = new toolBarWin ~file () in
35   let main = new mainWin ~file () in
36   let about = new aboutWin ~file () in
37   let fileSel = new fileSelectionWin ~file () in
38   let script = new scriptWin ~file () in
39   let keyBindingBoxes = (* event boxes which should receive global key events *)
40     [ toolbar#toolBarEventBox; main#mainWinEventBox;
41       script#scriptWinEventBox; main#consoleEventBox ]
42   in
43   let console =
44     MatitaConsole.console ~evbox:main#consoleEventBox
45       ~phrase_sep:BuildTimeConf.phrase_sep
46       ~packing:main#scrolledConsole#add ~paned:main#mainVPanes ()
47   in
48   object (self)
49     val mutable chosen_file = None
50
51     initializer
52         (* glade's check widgets *)
53       List.iter (fun w -> w#check_widgets ())
54         (let c w = (w :> <check_widgets: unit -> unit>) in
55          [ c about; c fileSel; c main; c toolbar; c script ]);
56         (* key bindings *)
57       List.iter (* global key bindings *)
58         (fun (key, callback) -> self#addKeyBinding key callback)
59 (*
60         [ GdkKeysyms._F3,
61             toggle_win ~check:main#showProofMenuItem proof#proofWin;
62           GdkKeysyms._F4,
63             toggle_win ~check:main#showCheckMenuItem check#checkWin;
64 *)
65         [ GdkKeysyms._F5,
66             toggle_win ~check:main#showScriptMenuItem script#scriptWin;
67           GdkKeysyms._x, (fun () -> console#toggle ());
68         ];
69       add_key_binding GdkKeysyms._Escape console#hide main#consoleEventBox;
70         (* about win *)
71       ignore (about#aboutWin#event#connect#delete (fun _ -> true));
72       ignore (main#aboutMenuItem#connect#activate (fun _ ->
73         about#aboutWin#show ()));
74       connect_button about#aboutDismissButton (fun _ ->
75         about#aboutWin#misc#hide ());
76       about#aboutLabel#set_label (Pcre.replace ~pat:"@VERSION@"
77         ~templ:BuildTimeConf.version about#aboutLabel#label);
78         (* file selection win *)
79       ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true));
80       ignore (fileSel#fileSelectionWin#connect#response (fun event ->
81         let return r =
82           chosen_file <- r;
83           fileSel#fileSelectionWin#misc#hide ();
84           GMain.Main.quit ()
85         in
86         match event with
87         | `OK ->
88             let fname = fileSel#fileSelectionWin#filename in
89             if is_regular fname then return (Some fname)
90         | `CANCEL -> return None
91         | `HELP -> ()
92         | `DELETE_EVENT -> return None));
93         (* script *)
94         (* menus *)
95       toggle_visibility toolbar#toolBarWin main#showToolBarMenuItem;
96 (*
97       toggle_visibility proof#proofWin main#showProofMenuItem;
98       toggle_visibility check#checkWin main#showCheckMenuItem;
99 *)
100       toggle_visibility script#scriptWin main#showScriptMenuItem;
101       List.iter (fun w -> w#misc#set_sensitive false)
102         [ main#saveMenuItem; main#saveAsMenuItem ];
103       main#helpMenu#set_right_justified true;
104       ignore (main#showConsoleMenuItem#connect#activate console#toggle);
105         (* main *)
106       connect_button main#hideConsoleButton console#hide;
107         (* console *)
108       console#echo_message (sprintf "\tMatita version %s\n"
109         BuildTimeConf.version);
110       console#echo_prompt ();
111       console#misc#grab_focus ();
112
113     method about = about
114     method console = console
115     method fileSel = fileSel
116     method main = main
117     method script = script
118     method toolbar = toolbar
119
120     method newBrowserWin () =
121       let win = new browserWin ~file () in
122       win#check_widgets ();
123       win
124
125     method newUriDialog () =
126       let dialog = new uriChoiceDialog ~file () in
127       dialog#check_widgets ();
128       dialog
129
130     method newInterpDialog () =
131       let dialog = new interpChoiceDialog ~file () in
132       dialog#check_widgets ();
133       dialog
134
135     method newConfirmationDialog () =
136       let dialog = new confirmationDialog ~file () in
137       dialog#check_widgets ();
138       dialog
139
140     method newEmptyDialog () =
141       let dialog = new emptyDialog ~file () in
142       dialog#check_widgets ();
143       dialog
144
145     method private addKeyBinding key callback =
146       List.iter (fun evbox -> add_key_binding key callback evbox)
147         keyBindingBoxes
148
149     method setQuitCallback callback =
150       ignore (main#toplevel#connect#destroy callback);
151       ignore (main#quitMenuItem#connect#activate callback);
152       self#addKeyBinding GdkKeysyms._q callback
153
154     method setPhraseCallback = console#set_callback
155
156     method chooseFile () =
157       fileSel#fileSelectionWin#show ();
158       GtkThread.main ();
159       chosen_file
160
161     method askText ?(title = "") ?(msg = "") () =
162       let dialog = new textDialog () in
163       dialog#textDialog#set_title title;
164       dialog#textDialogLabel#set_label msg;
165       let text = ref None in
166       let return v =
167         text := v;
168         dialog#textDialog#destroy ();
169         GMain.Main.quit ()
170       in
171       ignore (dialog#textDialog#event#connect#delete (fun _ -> true));
172       connect_button dialog#textDialogCancelButton (fun _ -> return None);
173       connect_button dialog#textDialogOkButton (fun _ ->
174         let text = dialog#textDialogTextView#buffer#get_text () in
175         return (Some text));
176       dialog#textDialog#show ();
177       GtkThread.main ();
178       !text
179
180   end
181
182 let gui () = new gui (Helm_registry.get "matita.glade_file")
183 let instance = singleton gui
184