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