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