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