]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaGui.ml
snapshot, notably:
[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 proof = new proofWin ~file () in
39   let check = new checkWin ~file () in
40   let script = new scriptWin ~file () in
41   let browser = new browserWin ~file () in
42   let keyBindingBoxes = (* event boxes which should receive global key events *)
43     [ toolbar#toolBarEventBox; proof#proofWinEventBox; main#mainWinEventBox;
44       check#checkWinEventBox; script#scriptWinEventBox; main#consoleEventBox;
45       browser#browserWinEventBox
46     ]
47   in
48   let console =
49     MatitaConsole.console ~evbox:main#consoleEventBox
50       ~phrase_sep:BuildTimeConf.phrase_sep
51       ~packing:main#scrolledConsole#add ~paned:main#mainVPanes ()
52   in
53   let script_buf = script#scriptTextView#buffer in
54   object (self)
55     val mutable chosen_file = None
56
57       (** text mark and tag representing locked part of a script *)
58     val locked_mark =
59       script_buf#create_mark ~name:"locked" ~left_gravity:true
60         script_buf#start_iter
61     val locked_tag =
62       script_buf#create_tag [`BACKGROUND "green"; `EDITABLE false]
63
64     initializer
65         (* glade's check widgets *)
66       List.iter (fun w -> w#check_widgets ())
67         (let c w = (w :> <check_widgets: unit -> unit>) in
68          [ c about; c fileSel; c main; c proof; c toolbar; c check; c script;
69            c browser ]);
70         (* key bindings *)
71       List.iter (* global key bindings *)
72         (fun (key, callback) -> self#addKeyBinding key callback)
73         [ GdkKeysyms._F3,
74             toggle_win ~check:main#showProofMenuItem proof#proofWin;
75           GdkKeysyms._F4,
76             toggle_win ~check:main#showCheckMenuItem check#checkWin;
77           GdkKeysyms._F5,
78             toggle_win ~check:main#showScriptMenuItem script#scriptWin;
79           GdkKeysyms._x, (fun () -> console#toggle ());
80         ];
81       add_key_binding GdkKeysyms._Escape console#hide main#consoleEventBox;
82         (* about win *)
83       ignore (about#aboutWin#event#connect#delete (fun _ -> true));
84       ignore (main#aboutMenuItem#connect#activate (fun _ ->
85         about#aboutWin#show ()));
86       connect_button about#aboutDismissButton (fun _ ->
87         about#aboutWin#misc#hide ());
88       about#aboutLabel#set_label (Pcre.replace ~pat:"@VERSION@"
89         ~templ:BuildTimeConf.version about#aboutLabel#label);
90         (* file selection win *)
91       ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true));
92       ignore (fileSel#fileSelectionWin#connect#response (fun event ->
93         let return r =
94           chosen_file <- r;
95           fileSel#fileSelectionWin#misc#hide ();
96           GMain.Main.quit ()
97         in
98         match event with
99         | `OK ->
100             let fname = fileSel#fileSelectionWin#filename in
101             if is_regular fname then return (Some fname)
102         | `CANCEL -> return None
103         | `HELP -> ()
104         | `DELETE_EVENT -> return None));
105         (* script *)
106         (* menus *)
107       toggle_visibility toolbar#toolBarWin main#showToolBarMenuItem;
108       toggle_visibility proof#proofWin main#showProofMenuItem;
109       toggle_visibility check#checkWin main#showCheckMenuItem;
110       toggle_visibility script#scriptWin main#showScriptMenuItem;
111       List.iter (fun w -> w#misc#set_sensitive false)
112         [ main#saveMenuItem; main#saveAsMenuItem ];
113       main#helpMenu#set_right_justified true;
114       ignore (main#showConsoleMenuItem#connect#activate console#toggle);
115         (* main *)
116       connect_button main#hideConsoleButton console#hide;
117 (*
118         (* console *)
119       console#echo_message (sprintf "\tMatita version %s\n"
120         BuildTimeConf.version);
121       console#echo_prompt ();
122       console#misc#grab_focus ();
123 *)
124
125     method about = about
126     method browser = browser
127     method check = check
128     method console = console
129     method fileSel = fileSel
130     method main = main
131     method proof = proof
132     method script = script
133     method toolbar = toolbar
134
135     method newUriDialog () =
136       let dialog = new uriChoiceDialog ~file () in
137       dialog#check_widgets ();
138       dialog
139
140     method newInterpDialog () =
141       let dialog = new interpChoiceDialog ~file () in
142       dialog#check_widgets ();
143       dialog
144
145     method newConfirmationDialog () =
146       let dialog = new confirmationDialog ~file () in
147       dialog#check_widgets ();
148       dialog
149
150     method newEmptyDialog () =
151       let dialog = new emptyDialog ~file () in
152       dialog#check_widgets ();
153       dialog
154
155     method private addKeyBinding key callback =
156       List.iter (fun evbox -> add_key_binding key callback evbox)
157         keyBindingBoxes
158
159     method setQuitCallback callback =
160       ignore (main#toplevel#connect#destroy callback);
161       ignore (main#quitMenuItem#connect#activate callback);
162       self#addKeyBinding GdkKeysyms._q callback
163
164     method setPhraseCallback = console#set_callback
165
166     method chooseFile () =
167       fileSel#fileSelectionWin#show ();
168       GtkThread.main ();
169       chosen_file
170
171     method askText ?(title = "") ?(msg = "") () =
172       let dialog = new textDialog () in
173       dialog#textDialog#set_title title;
174       dialog#textDialogLabel#set_label msg;
175       let text = ref None in
176       let return v =
177         text := v;
178         dialog#textDialog#destroy ();
179         GMain.Main.quit ()
180       in
181       ignore (dialog#textDialog#event#connect#delete (fun _ -> true));
182       connect_button dialog#textDialogCancelButton (fun _ -> return None);
183       connect_button dialog#textDialogOkButton (fun _ ->
184         let text = dialog#textDialogTextView#buffer#get_text () in
185         return (Some text));
186       dialog#textDialog#show ();
187       GtkThread.main ();
188       !text
189
190     method lockScript offset =
191       let mark = `MARK locked_mark in
192       script_buf#move_mark mark ~where:(script_buf#get_iter_at_char offset);
193       script_buf#remove_tag locked_tag ~start:script_buf#start_iter
194         ~stop:script_buf#end_iter;
195       script_buf#apply_tag locked_tag ~start:script_buf#start_iter
196         ~stop:(script_buf#get_iter_at_mark mark)
197
198   end
199
200 let instance =
201   let gui = lazy (new gui (Helm_registry.get "matita.glade_file")) in
202   fun () -> Lazy.force gui
203