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