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