]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaGui.ml
1. matitaEngine splitted into disambiguation (now in grafite_parser) and
[helm.git] / helm / matita / matitaGui.ml
1 (* Copyright (C) 2004-2005, 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 exception Found of int
33
34 let gui_instance = ref None
35
36 class type browserWin =
37   (* this class exists only because GEdit.combo_box_entry is not supported by
38    * lablgladecc :-(((( *)
39 object
40   inherit MatitaGeneratedGui.browserWin
41   method browserUri: GEdit.combo_box_entry
42 end
43
44 class console ~(buffer: GText.buffer) () =
45   object (self)
46     val error_tag   = buffer#create_tag [ `FOREGROUND "red" ]
47     val warning_tag = buffer#create_tag [ `FOREGROUND "orange" ]
48     val message_tag = buffer#create_tag []
49     val debug_tag   = buffer#create_tag [ `FOREGROUND "#888888" ]
50     method message s = buffer#insert ~iter:buffer#end_iter ~tags:[message_tag] s
51     method error s   = buffer#insert ~iter:buffer#end_iter ~tags:[error_tag] s
52     method warning s = buffer#insert ~iter:buffer#end_iter ~tags:[warning_tag] s
53     method debug s   = buffer#insert ~iter:buffer#end_iter ~tags:[debug_tag] s
54     method clear () =
55       buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter
56     method log_callback (tag: HLog.log_tag) s =
57       match tag with
58       | `Debug -> self#debug (s ^ "\n")
59       | `Error -> self#error (s ^ "\n")
60       | `Message -> self#message (s ^ "\n")
61       | `Warning -> self#warning (s ^ "\n")
62   end
63         
64 let clean_current_baseuri status = 
65     try  
66       let baseuri = GrafiteTypes.get_string_option status "baseuri" in
67       let basedir = Helm_registry.get "matita.basedir" in
68       LibraryClean.clean_baseuris ~basedir [baseuri]
69     with GrafiteTypes.Option_error _ -> ()
70
71 let ask_and_save_moo_if_needed parent fname status = 
72   let basedir = Helm_registry.get "matita.basedir" in
73   let save () =
74     let moo_fname = GrafiteMisc.obj_file_of_script ~basedir fname in
75      GrafiteMarshal.save_moo moo_fname
76       status.GrafiteTypes.moo_content_rev in
77   if (MatitaScript.current ())#eos &&
78      status.GrafiteTypes.proof_status = GrafiteTypes.No_proof
79   then
80     begin
81       let mooname = GrafiteMisc.obj_file_of_script ~basedir fname in
82       let rc = 
83         MatitaGtkMisc.ask_confirmation
84         ~title:"A .moo can be generated"
85         ~message:(Printf.sprintf 
86           "%s can be generated for %s.\n<i>Should I generate it?</i>"
87           (Filename.basename mooname) (Filename.basename fname))
88         ~parent ()
89       in
90       let b = 
91         match rc with 
92         | `YES -> true 
93         | `NO -> false 
94         | `CANCEL -> raise MatitaTypes.Cancel 
95       in
96       if b then
97         save ()
98       else
99         clean_current_baseuri status
100     end
101   else
102     clean_current_baseuri status 
103     
104 let ask_unsaved parent =
105   MatitaGtkMisc.ask_confirmation 
106     ~parent ~title:"Unsaved work!" 
107     ~message:("Your work is <b>unsaved</b>!\n\n"^
108          "<i>Do you want to save the script before continuing?</i>")
109     ()
110
111 class gui () =
112     (* creation order _is_ relevant for windows placement *)
113   let main = new mainWin () in
114   let fileSel = new fileSelectionWin () in
115   let findRepl = new findReplWin () in
116   let develList = new develListWin () in
117   let newDevel = new newDevelWin () in
118   let keyBindingBoxes = (* event boxes which should receive global key events *)
119     [ main#mainWinEventBox ]
120   in
121   let console = new console ~buffer:main#logTextView#buffer () in
122   let (source_view: GSourceView.source_view) =
123     GSourceView.source_view
124       ~auto_indent:true
125       ~insert_spaces_instead_of_tabs:true ~tabs_width:2
126       ~margin:80 ~show_margin:true
127       ~smart_home_end:true
128       ~packing:main#scriptScrolledWin#add
129       ()
130   in
131   let default_font_size =
132     Helm_registry.get_opt_default Helm_registry.int
133       ~default:BuildTimeConf.default_font_size "matita.font_size"
134   in
135   let source_buffer = source_view#source_buffer in
136   object (self)
137     val mutable chosen_file = None
138     val mutable _ok_not_exists = false
139     val mutable _only_directory = false
140     val mutable script_fname = None
141     val mutable font_size = default_font_size
142     val mutable next_devel_must_contain = None
143     val mutable next_ligatures = []
144    
145     initializer
146         (* glade's check widgets *)
147       List.iter (fun w -> w#check_widgets ())
148         (let c w = (w :> <check_widgets: unit -> unit>) in
149         [ c fileSel; c main; c findRepl]);
150         (* key bindings *)
151       List.iter (* global key bindings *)
152         (fun (key, callback) -> self#addKeyBinding key callback)
153 (*
154         [ GdkKeysyms._F3,
155             toggle_win ~check:main#showProofMenuItem proof#proofWin;
156           GdkKeysyms._F4,
157             toggle_win ~check:main#showCheckMenuItem check#checkWin;
158 *)
159         [ ];
160         (* about win *)
161       let parse_txt_file file =
162        let ch = open_in (BuildTimeConf.runtime_base_dir ^ "/" ^ file) in
163        let l_rev = ref [] in
164        try
165         while true do
166          l_rev := input_line ch :: !l_rev;
167         done;
168         assert false
169        with
170         End_of_file ->
171          close_in ch;
172          List.rev !l_rev in 
173       let about_dialog =
174        GWindow.about_dialog
175         ~authors:(parse_txt_file "AUTHORS")
176         (*~comments:"comments"*)
177         ~copyright:"Copyright (C) 2005, the HELM team"
178         ~license:(String.concat "\n" (parse_txt_file "LICENSE"))
179         ~logo:(GdkPixbuf.from_file (MatitaMisc.image_path "/matita_medium.png"))
180         ~name:"Matita"
181         ~version:BuildTimeConf.version
182         ~website:"http://helm.cs.unibo.it"
183         ()
184       in
185       connect_menu_item main#aboutMenuItem about_dialog#present;
186         (* findRepl win *)
187       let show_find_Repl () = 
188         findRepl#toplevel#misc#show ();
189         findRepl#toplevel#misc#grab_focus ()
190       in
191       let hide_find_Repl () = findRepl#toplevel#misc#hide () in
192       let find_forward _ = 
193           let highlight start end_ =
194             source_buffer#move_mark `INSERT ~where:start;
195             source_buffer#move_mark `SEL_BOUND ~where:end_;
196             source_view#scroll_mark_onscreen `INSERT
197           in
198           let text = findRepl#findEntry#text in
199           let iter = source_buffer#get_iter `SEL_BOUND in
200           match iter#forward_search text with
201           | None -> 
202               (match source_buffer#start_iter#forward_search text with
203               | None -> ()
204               | Some (start,end_) -> highlight start end_)
205           | Some (start,end_) -> highlight start end_ 
206       in
207       let replace _ =
208         let text = findRepl#replaceEntry#text in
209         let ins = source_buffer#get_iter `INSERT in
210         let sel = source_buffer#get_iter `SEL_BOUND in
211         if ins#compare sel < 0 then 
212           begin
213             ignore(source_buffer#delete_selection ());
214             source_buffer#insert text
215           end
216       in
217       connect_button findRepl#findButton find_forward;
218       connect_button findRepl#findReplButton replace;
219       connect_button findRepl#cancelButton (fun _ -> hide_find_Repl ());
220       ignore(findRepl#toplevel#event#connect#delete 
221         ~callback:(fun _ -> hide_find_Repl ();true));
222       let safe_undo =
223        fun () ->
224         (* phase 1: we save the actual status of the marks and we undo *)
225         let locked_mark = `MARK ((MatitaScript.current ())#locked_mark) in
226         let locked_iter = source_view#buffer#get_iter_at_mark locked_mark in
227         let locked_iter_offset = locked_iter#offset in
228         let mark2 =
229          `MARK
230            (source_view#buffer#create_mark ~name:"lock_point"
231              ~left_gravity:true locked_iter) in
232         source_view#source_buffer#undo ();
233         (* phase 2: we save the cursor position and we redo, restoring
234            the previous status of all the marks *)
235         let cursor_iter = source_view#buffer#get_iter_at_mark `INSERT in
236         let mark =
237          `MARK
238            (source_view#buffer#create_mark ~name:"undo_point"
239              ~left_gravity:true cursor_iter)
240         in
241          source_view#source_buffer#redo ();
242          let mark_iter = source_view#buffer#get_iter_at_mark mark in
243          let mark2_iter = source_view#buffer#get_iter_at_mark mark2 in
244          let mark2_iter = mark2_iter#set_offset locked_iter_offset in
245           source_view#buffer#move_mark locked_mark ~where:mark2_iter;
246           source_view#buffer#delete_mark mark;
247           source_view#buffer#delete_mark mark2;
248           (* phase 3: if after the undo the cursor was in the locked area,
249              then we move it there again and we perform a goto *)
250           if mark_iter#offset < locked_iter_offset then
251            begin
252             source_view#buffer#move_mark `INSERT ~where:mark_iter;
253             (MatitaScript.current ())#goto `Cursor ();
254            end;
255           (* phase 4: we perform again the undo. This time we are sure that
256              the text to undo is not locked *)
257           source_view#source_buffer#undo ();
258           source_view#misc#grab_focus () in
259       let safe_redo =
260        fun () ->
261         (* phase 1: we save the actual status of the marks, we redo and
262            we undo *)
263         let locked_mark = `MARK ((MatitaScript.current ())#locked_mark) in
264         let locked_iter = source_view#buffer#get_iter_at_mark locked_mark in
265         let locked_iter_offset = locked_iter#offset in
266         let mark2 =
267          `MARK
268            (source_view#buffer#create_mark ~name:"lock_point"
269              ~left_gravity:true locked_iter) in
270         source_view#source_buffer#redo ();
271         source_view#source_buffer#undo ();
272         (* phase 2: we save the cursor position and we restore
273            the previous status of all the marks *)
274         let cursor_iter = source_view#buffer#get_iter_at_mark `INSERT in
275         let mark =
276          `MARK
277            (source_view#buffer#create_mark ~name:"undo_point"
278              ~left_gravity:true cursor_iter)
279         in
280          let mark_iter = source_view#buffer#get_iter_at_mark mark in
281          let mark2_iter = source_view#buffer#get_iter_at_mark mark2 in
282          let mark2_iter = mark2_iter#set_offset locked_iter_offset in
283           source_view#buffer#move_mark locked_mark ~where:mark2_iter;
284           source_view#buffer#delete_mark mark;
285           source_view#buffer#delete_mark mark2;
286           (* phase 3: if after the undo the cursor is in the locked area,
287              then we move it there again and we perform a goto *)
288           if mark_iter#offset < locked_iter_offset then
289            begin
290             source_view#buffer#move_mark `INSERT ~where:mark_iter;
291             (MatitaScript.current ())#goto `Cursor ();
292            end;
293           (* phase 4: we perform again the redo. This time we are sure that
294              the text to redo is not locked *)
295           source_view#source_buffer#redo ();
296           source_view#misc#grab_focus ()
297       in
298       connect_menu_item main#undoMenuItem safe_undo;
299       ignore(source_view#source_buffer#connect#can_undo
300         ~callback:main#undoMenuItem#misc#set_sensitive);
301       connect_menu_item main#redoMenuItem safe_redo;
302       ignore(source_view#source_buffer#connect#can_redo
303         ~callback:main#redoMenuItem#misc#set_sensitive);
304       ignore(source_view#connect#after#populate_popup
305        ~callback:(fun pre_menu ->
306          let menu = new GMenu.menu pre_menu in
307          let menuItems = menu#children in
308          let undoMenuItem, redoMenuItem =
309           match menuItems with
310              [undo;redo;sep1;cut;copy;paste;delete;sep2;
311               selectall;sep3;inputmethod;insertunicodecharacter] -> undo,redo
312            | _ -> assert false in
313          let new_undoMenuItem =
314           GMenu.image_menu_item
315            ~image:(GMisc.image ~stock:`UNDO ())
316            ~use_mnemonic:true
317            ~label:"_Undo"
318            ~packing:(menu#insert ~pos:0) () in
319          new_undoMenuItem#misc#set_sensitive
320           (undoMenuItem#misc#get_flag `SENSITIVE);
321          menu#remove (undoMenuItem :> GMenu.menu_item);
322          connect_menu_item new_undoMenuItem safe_undo;
323          let new_redoMenuItem =
324           GMenu.image_menu_item
325            ~image:(GMisc.image ~stock:`REDO ())
326            ~use_mnemonic:true
327            ~label:"_Redo"
328            ~packing:(menu#insert ~pos:1) () in
329          new_redoMenuItem#misc#set_sensitive
330           (redoMenuItem#misc#get_flag `SENSITIVE);
331           menu#remove (redoMenuItem :> GMenu.menu_item);
332           connect_menu_item new_redoMenuItem safe_redo));
333       let clipboard = GData.clipboard Gdk.Atom.clipboard in
334       let text_selected () =
335         (source_buffer#get_iter_at_mark `INSERT)#compare
336           (source_buffer#get_iter_at_mark `SEL_BOUND) <> 0
337       in
338       let markup_selected () = MatitaMathView.get_selections () <> None in
339       connect_menu_item main#editMenu (fun () ->
340         let text_selected = text_selected () in
341         let markup_selected = markup_selected () in
342         let something_selected = text_selected || markup_selected in
343         main#cutMenuItem#misc#set_sensitive text_selected;
344         main#copyMenuItem#misc#set_sensitive something_selected;
345         main#deleteMenuItem#misc#set_sensitive text_selected;
346         main#pasteMenuItem#misc#set_sensitive (clipboard#text <> None));
347       connect_menu_item main#cutMenuItem (fun () ->
348         source_view#buffer#cut_clipboard clipboard);
349       connect_menu_item main#copyMenuItem (fun () ->
350         if text_selected () then
351           source_view#buffer#copy_clipboard clipboard
352         else if markup_selected () then
353           match MatitaMathView.get_selections () with
354           | None
355           | Some [] -> ()
356           | Some (s :: _) -> clipboard#set_text s);
357       connect_menu_item main#pasteMenuItem (fun () ->
358         source_view#buffer#paste_clipboard clipboard;
359         (MatitaScript.current ())#clean_dirty_lock);
360       connect_menu_item main#deleteMenuItem (fun () ->
361         ignore (source_view#buffer#delete_selection ()));
362       connect_menu_item main#selectAllMenuItem (fun () ->
363         source_buffer#move_mark `INSERT source_buffer#start_iter;
364         source_buffer#move_mark `SEL_BOUND source_buffer#end_iter);
365       connect_menu_item main#findReplMenuItem show_find_Repl;
366       connect_menu_item main#externalEditorMenuItem self#externalEditor;
367       connect_menu_item main#ligatureButton self#nextLigature;
368       ignore (findRepl#findEntry#connect#activate find_forward);
369         (* interface lockers *)
370       let lock_world _ =
371         main#buttonsToolbar#misc#set_sensitive false;
372         develList#buttonsHbox#misc#set_sensitive false;
373         source_view#set_editable false
374       in
375       let unlock_world _ =
376         main#buttonsToolbar#misc#set_sensitive true;
377         develList#buttonsHbox#misc#set_sensitive true;
378         source_view#set_editable true
379       in
380       let locker f = 
381         fun () -> 
382           lock_world ();
383           try f ();unlock_world () with exc -> unlock_world (); raise exc in
384       let keep_focus f =
385         fun () ->
386          try
387           f (); source_view#misc#grab_focus ()
388          with
389           exc -> source_view#misc#grab_focus (); raise exc in
390         (* developments win *)
391       let model = 
392         new MatitaGtkMisc.multiStringListModel 
393           ~cols:2 develList#developmentsTreeview
394       in
395       let refresh_devels_win () =
396         model#list_store#clear ();
397         List.iter 
398           (fun (name, root) -> model#easy_mappend [name;root]) 
399           (MatitamakeLib.list_known_developments ())
400       in
401       let get_devel_selected () = 
402         match model#easy_mselection () with
403         | [[name;_]] -> MatitamakeLib.development_for_name name
404         | _ -> None
405       in
406       let refresh () = 
407         while Glib.Main.pending () do 
408           ignore(Glib.Main.iteration false); 
409         done
410       in
411       connect_button develList#newButton
412         (fun () -> 
413           next_devel_must_contain <- None;
414           newDevel#toplevel#misc#show());
415       connect_button develList#deleteButton
416         (locker (fun () -> 
417           (match get_devel_selected () with
418           | None -> ()
419           | Some d -> MatitamakeLib.destroy_development_in_bg refresh d);
420           refresh_devels_win ()));
421       connect_button develList#buildButton 
422         (locker (fun () -> 
423           match get_devel_selected () with
424           | None -> ()
425           | Some d -> 
426               let build = locker 
427                 (fun () -> MatitamakeLib.build_development_in_bg refresh d)
428               in
429               ignore(build ())));
430       connect_button develList#cleanButton 
431         (locker (fun () -> 
432           match get_devel_selected () with
433           | None -> ()
434           | Some d -> 
435               let clean = locker 
436                 (fun () -> MatitamakeLib.clean_development_in_bg refresh d)
437               in
438               ignore(clean ())));
439       connect_button develList#closeButton 
440         (fun () -> develList#toplevel#misc#hide());
441       ignore(develList#toplevel#event#connect#delete 
442         (fun _ -> develList#toplevel#misc#hide();true));
443       connect_menu_item main#developmentsMenuItem
444         (fun () -> refresh_devels_win ();develList#toplevel#misc#show ());
445       
446         (* add development win *)
447       let check_if_root_contains root =
448         match next_devel_must_contain with
449         | None -> true
450         | Some path -> 
451             let is_prefix_of d1 d2 =
452               let len1 = String.length d1 in
453               let len2 = String.length d2 in
454               if len2 < len1 then 
455                 false
456               else
457                 let pref = String.sub d2 0 len1 in
458                 pref = d1
459             in
460             is_prefix_of root path
461       in
462       connect_button newDevel#addButton 
463        (fun () -> 
464           let name = newDevel#nameEntry#text in
465           let root = newDevel#rootEntry#text in
466           if check_if_root_contains root then
467             begin
468               ignore (MatitamakeLib.initialize_development name root);
469               refresh_devels_win ();
470               newDevel#nameEntry#set_text "";
471               newDevel#rootEntry#set_text "";
472               newDevel#toplevel#misc#hide()
473             end
474           else
475             HLog.error ("The selected root does not contain " ^ 
476               match next_devel_must_contain with 
477               | Some x -> x 
478               | _ -> assert false));
479       connect_button newDevel#chooseRootButton 
480        (fun () ->
481          let path = self#chooseDir () in
482          match path with
483          | Some path -> newDevel#rootEntry#set_text path
484          | None -> ());
485       connect_button newDevel#cancelButton 
486        (fun () -> newDevel#toplevel#misc#hide ());
487       ignore(newDevel#toplevel#event#connect#delete 
488         (fun _ -> newDevel#toplevel#misc#hide();true));
489       
490         (* file selection win *)
491       ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true));
492       ignore (fileSel#fileSelectionWin#connect#response (fun event ->
493         let return r =
494           chosen_file <- r;
495           fileSel#fileSelectionWin#misc#hide ();
496           GMain.Main.quit ()
497         in
498         match event with
499         | `OK ->
500             let fname = fileSel#fileSelectionWin#filename in
501             if Sys.file_exists fname then
502               begin
503                 if HExtlib.is_regular fname && not (_only_directory) then 
504                   return (Some fname) 
505                 else if _only_directory && HExtlib.is_dir fname then 
506                   return (Some fname)
507               end
508             else
509               begin
510                 if _ok_not_exists then 
511                   return (Some fname)
512               end
513         | `CANCEL -> return None
514         | `HELP -> ()
515         | `DELETE_EVENT -> return None));
516         (* menus *)
517       List.iter (fun w -> w#misc#set_sensitive false) [ main#saveMenuItem ];
518         (* console *)
519       let adj = main#logScrolledWin#vadjustment in
520         ignore (adj#connect#changed
521                 (fun _ -> adj#set_value (adj#upper -. adj#page_size)));
522       console#message (sprintf "\tMatita version %s\n" BuildTimeConf.version);
523         (* toolbar *)
524       let module A = GrafiteAst in
525       let hole = CicNotationPt.UserInput in
526       let loc = DisambiguateTypes.dummy_floc in
527       let tac ast _ =
528         if (MatitaScript.current ())#onGoingProof () then
529           (MatitaScript.current ())#advance
530             ~statement:("\n" ^ GrafiteAstPp.pp_tactical (A.Tactic (loc, ast)))
531             ()
532       in
533       let tac_w_term ast _ =
534         if (MatitaScript.current ())#onGoingProof () then
535           let buf = source_buffer in
536           buf#insert ~iter:(buf#get_iter_at_mark (`NAME "locked"))
537             ("\n" ^ GrafiteAstPp.pp_tactic ast)
538       in
539       let tbar = main in
540       connect_button tbar#introsButton (tac (A.Intros (loc, None, [])));
541       connect_button tbar#applyButton (tac_w_term (A.Apply (loc, hole)));
542       connect_button tbar#exactButton (tac_w_term (A.Exact (loc, hole)));
543       connect_button tbar#elimButton (tac_w_term
544         (A.Elim (loc, hole, None, None, [])));
545       connect_button tbar#elimTypeButton (tac_w_term
546         (A.ElimType (loc, hole, None, None, [])));
547       connect_button tbar#splitButton (tac (A.Split loc));
548       connect_button tbar#leftButton (tac (A.Left loc));
549       connect_button tbar#rightButton (tac (A.Right loc));
550       connect_button tbar#existsButton (tac (A.Exists loc));
551       connect_button tbar#reflexivityButton (tac (A.Reflexivity loc));
552       connect_button tbar#symmetryButton (tac (A.Symmetry loc));
553       connect_button tbar#transitivityButton
554         (tac_w_term (A.Transitivity (loc, hole)));
555       connect_button tbar#assumptionButton (tac (A.Assumption loc));
556       connect_button tbar#cutButton (tac_w_term (A.Cut (loc, None, hole)));
557       connect_button tbar#autoButton (tac (A.Auto (loc,None,None,None,None)));
558       MatitaGtkMisc.toggle_widget_visibility
559        ~widget:(main#tacticsButtonsHandlebox :> GObj.widget)
560        ~check:main#tacticsBarMenuItem;
561       let module Hr = Helm_registry in
562       if
563         not (Hr.get_opt_default Hr.bool ~default:false "matita.tactics_bar")
564       then 
565         main#tacticsBarMenuItem#set_active false;
566       MatitaGtkMisc.toggle_callback 
567         ~callback:(function 
568           | true -> main#toplevel#fullscreen () 
569           | false -> main#toplevel#unfullscreen ())
570         ~check:main#fullscreenMenuItem;
571       main#fullscreenMenuItem#set_active false;
572         (* log *)
573       HLog.set_log_callback self#console#log_callback;
574       GtkSignal.user_handler :=
575         (fun exn ->
576           if not (Helm_registry.get_bool "matita.debug") then
577            let floc, msg = MatitaExcPp.to_string exn in
578             begin
579              match floc with
580                 None -> ()
581               | Some floc ->
582                  let (x, y) = HExtlib.loc_of_floc floc in
583                  let script = MatitaScript.current () in
584                  let locked_mark = script#locked_mark in
585                  let error_tag = script#error_tag in
586                  let baseoffset =
587                   (source_buffer#get_iter_at_mark (`MARK locked_mark))#offset in
588                  let x' = baseoffset + x in
589                  let y' = baseoffset + y in
590                  let x_iter = source_buffer#get_iter (`OFFSET x') in
591                  let y_iter = source_buffer#get_iter (`OFFSET y') in
592                  source_buffer#apply_tag error_tag ~start:x_iter ~stop:y_iter;
593                  let id = ref None in
594                  id := Some (source_buffer#connect#changed ~callback:(fun () ->
595                    source_buffer#remove_tag error_tag
596                      ~start:source_buffer#start_iter
597                      ~stop:source_buffer#end_iter;
598                    match !id with
599                    | None -> assert false (* a race condition occurred *)
600                    | Some id ->
601                        (new GObj.gobject_ops source_buffer#as_buffer)#disconnect id));
602                  source_buffer#place_cursor
603                   (source_buffer#get_iter (`OFFSET x'));
604             end;
605             HLog.error msg
606           else raise exn);
607         (* script *)
608       ignore (source_buffer#connect#mark_set (fun _ _ -> next_ligatures <- []));
609       let _ =
610         match GSourceView.source_language_from_file BuildTimeConf.lang_file with
611         | None ->
612             HLog.warn (sprintf "can't load language file %s"
613               BuildTimeConf.lang_file)
614         | Some matita_lang ->
615             source_buffer#set_language matita_lang;
616             source_buffer#set_highlight true
617       in
618       let s () = MatitaScript.current () in
619       let disableSave () =
620         script_fname <- None;
621         main#saveMenuItem#misc#set_sensitive false
622       in
623       let saveAsScript () =
624         let script = s () in
625         match self#chooseFile ~ok_not_exists:true () with
626         | Some f -> 
627               script#assignFileName f;
628               script#saveToFile (); 
629               console#message ("'"^f^"' saved.\n");
630               self#_enableSaveTo f
631         | None -> ()
632       in
633       let saveScript () =
634         match script_fname with
635         | None -> saveAsScript ()
636         | Some f -> 
637               (s ())#assignFileName f;
638               (s ())#saveToFile ();
639               console#message ("'"^f^"' saved.\n");
640       in
641       let abandon_script () =
642         let status = (s ())#status in
643         if source_view#buffer#modified then
644           (match ask_unsaved main#toplevel with
645           | `YES -> saveScript ()
646           | `NO -> ()
647           | `CANCEL -> raise MatitaTypes.Cancel);
648         (match script_fname with
649         | None -> ()
650         | Some fname -> ask_and_save_moo_if_needed main#toplevel fname status);
651       in
652       let loadScript () =
653         let script = s () in 
654         try 
655           match self#chooseFile () with
656           | Some f -> 
657               abandon_script ();
658               script#reset (); 
659               script#assignFileName f;
660               source_view#source_buffer#begin_not_undoable_action ();
661               script#loadFromFile f; 
662               source_view#source_buffer#end_not_undoable_action ();
663               console#message ("'"^f^"' loaded.\n");
664               self#_enableSaveTo f
665           | None -> ()
666         with MatitaTypes.Cancel -> ()
667       in
668       let newScript () = 
669         abandon_script ();
670         source_view#source_buffer#begin_not_undoable_action ();
671         (s ())#reset (); 
672         (s ())#template (); 
673         source_view#source_buffer#end_not_undoable_action ();
674         disableSave ();
675         script_fname <- None
676       in
677       let cursor () =
678         source_buffer#place_cursor
679           (source_buffer#get_iter_at_mark (`NAME "locked")) in
680       let advance _ = (MatitaScript.current ())#advance (); cursor () in
681       let retract _ = (MatitaScript.current ())#retract (); cursor () in
682       let top _ = (MatitaScript.current ())#goto `Top (); cursor () in
683       let bottom _ = (MatitaScript.current ())#goto `Bottom (); cursor () in
684       let jump _ = (MatitaScript.current ())#goto `Cursor (); cursor () in
685       let advance = locker (keep_focus advance) in
686       let retract = locker (keep_focus retract) in
687       let top = locker (keep_focus top) in
688       let bottom = locker (keep_focus bottom) in
689       let jump = locker (keep_focus jump) in
690       let connect_key sym f =
691         connect_key main#mainWinEventBox#event
692           ~modifiers:[`CONTROL] ~stop:true sym f;
693         connect_key self#sourceView#event
694           ~modifiers:[`CONTROL] ~stop:true sym f
695       in
696         (* quit *)
697       self#setQuitCallback (fun () -> 
698         let status = (MatitaScript.current ())#status in
699         if source_view#buffer#modified then
700           begin
701             let rc = ask_unsaved main#toplevel in 
702             try
703               match rc with
704               | `YES -> saveScript ();
705                         if not source_view#buffer#modified then
706                           begin
707                             (match script_fname with
708                             | None -> ()
709                             | Some fname -> 
710                                ask_and_save_moo_if_needed 
711                                  main#toplevel fname status);
712                           GMain.Main.quit ()
713                           end
714               | `NO -> GMain.Main.quit ()
715               | `CANCEL -> raise MatitaTypes.Cancel
716             with MatitaTypes.Cancel -> ()
717           end 
718         else 
719           begin  
720             (match script_fname with
721             | None -> clean_current_baseuri status; GMain.Main.quit ()
722             | Some fname ->
723                 try
724                   ask_and_save_moo_if_needed main#toplevel fname status;
725                   GMain.Main.quit ()
726                 with MatitaTypes.Cancel -> ())
727           end);
728       connect_button main#scriptAdvanceButton advance;
729       connect_button main#scriptRetractButton retract;
730       connect_button main#scriptTopButton top;
731       connect_button main#scriptBottomButton bottom;
732       connect_button main#scriptJumpButton jump;
733       connect_menu_item main#scriptAdvanceMenuItem advance;
734       connect_menu_item main#scriptRetractMenuItem retract;
735       connect_menu_item main#scriptTopMenuItem top;
736       connect_menu_item main#scriptBottomMenuItem bottom;
737       connect_menu_item main#scriptJumpMenuItem jump;
738       connect_menu_item main#openMenuItem   loadScript;
739       connect_menu_item main#saveMenuItem   saveScript;
740       connect_menu_item main#saveAsMenuItem saveAsScript;
741       connect_menu_item main#newMenuItem    newScript;
742          (* script monospace font stuff *)  
743       self#updateFontSize ();
744         (* debug menu *)
745       main#debugMenu#misc#hide ();
746         (* status bar *)
747       main#hintLowImage#set_file (image_path "matita-bulb-low.png");
748       main#hintMediumImage#set_file (image_path "matita-bulb-medium.png");
749       main#hintHighImage#set_file (image_path "matita-bulb-high.png");
750         (* focus *)
751       self#sourceView#misc#grab_focus ();
752         (* main win dimension *)
753       let width = Gdk.Screen.width () in
754       let height = Gdk.Screen.height () in
755       let main_w = width * 90 / 100 in 
756       let main_h = height * 80 / 100 in
757       let script_w = main_w * 6 / 10 in
758       main#toplevel#resize ~width:main_w ~height:main_h;
759       main#hpaneScriptSequent#set_position script_w;
760         (* source_view *)
761       ignore(source_view#connect#after#paste_clipboard 
762         ~callback:(fun () -> (MatitaScript.current ())#clean_dirty_lock));
763       (* clean_locked is set to true only "during" a PRIMARY paste
764          operation (i.e. by clicking with the second mouse button) *)
765       let clean_locked = ref false in
766       ignore(source_view#event#connect#button_press
767         ~callback:
768           (fun button ->
769             if GdkEvent.Button.button button = 2 then
770              clean_locked := true;
771             false
772           ));
773       ignore(source_view#event#connect#button_release
774         ~callback:(fun button -> clean_locked := false; false));
775       ignore(source_view#buffer#connect#after#apply_tag
776        ~callback:(
777          fun tag ~start:_ ~stop:_ ->
778           if !clean_locked &&
779              tag#get_oid = (MatitaScript.current ())#locked_tag#get_oid
780           then
781            begin
782             clean_locked := false;
783             (MatitaScript.current ())#clean_dirty_lock;
784             clean_locked := true
785            end));
786       (* math view handling *)
787       connect_menu_item main#newCicBrowserMenuItem (fun () ->
788         ignore (MatitaMathView.cicBrowser ()));
789       connect_menu_item main#increaseFontSizeMenuItem (fun () ->
790         self#increaseFontSize ();
791         MatitaMathView.increase_font_size ();
792         MatitaMathView.update_font_sizes ());
793       connect_menu_item main#decreaseFontSizeMenuItem (fun () ->
794         self#decreaseFontSize ();
795         MatitaMathView.decrease_font_size ();
796         MatitaMathView.update_font_sizes ());
797       connect_menu_item main#normalFontSizeMenuItem (fun () ->
798         self#resetFontSize ();
799         MatitaMathView.reset_font_size ();
800         MatitaMathView.update_font_sizes ());
801       MatitaMathView.reset_font_size ();
802     
803     method private nextLigature () =
804       let iter = source_buffer#get_iter_at_mark `INSERT in
805       let write_ligature len s =
806         source_buffer#delete ~start:iter ~stop:(iter#copy#backward_chars len);
807         source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT) s
808       in
809       let get_ligature word =
810         let len = String.length word in
811         let aux_tex () =
812           try
813             for i = len - 1 downto 0 do
814               if HExtlib.is_alpha word.[i] then ()
815               else
816                 (if word.[i] = '\\' then raise (Found i) else raise (Found ~-1))
817             done;
818             None
819           with Found i ->
820             if i = ~-1 then None else Some (String.sub word i (len - i))
821         in
822         let aux_ligature () =
823           try
824             for i = len - 1 downto 0 do
825               if CicNotationLexer.is_ligature_char word.[i] then ()
826               else raise (Found (i+1))
827             done;
828             raise (Found 0)
829           with
830           | Found i ->
831               (try
832                 Some (String.sub word i (len - i))
833               with Invalid_argument _ -> None)
834         in
835         match aux_tex () with
836         | Some macro -> macro
837         | None -> (match aux_ligature () with Some l -> l | None -> word)
838       in
839       (match next_ligatures with
840       | [] -> (* find ligatures and fill next_ligatures, then try again *)
841           let last_word =
842             iter#get_slice
843               ~stop:(iter#copy#backward_find_char Glib.Unichar.isspace)
844           in
845           let ligature = get_ligature last_word in
846           (match CicNotationLexer.lookup_ligatures ligature with
847           | [] -> ()
848           | hd :: tl ->
849               write_ligature (String.length ligature) hd;
850               next_ligatures <- tl @ [ hd ])
851       | hd :: tl ->
852           write_ligature 1 hd;
853           next_ligatures <- tl @ [ hd ])
854
855     method private externalEditor () =
856       let cmd = Helm_registry.get "matita.external_editor" in
857 (* ZACK uncomment to enable interactive ask of external editor command *)
858 (*      let cmd =
859          let msg =
860           "External editor command:
861 %f  will be substitute for the script name,
862 %p  for the cursor position in bytes,
863 %l  for the execution point in bytes."
864         in
865         ask_text ~gui:self ~title:"External editor" ~msg ~multiline:false
866           ~default:(Helm_registry.get "matita.external_editor") ()
867       in *)
868       let fname = (MatitaScript.current ())#filename in
869       let slice mark =
870         source_buffer#start_iter#get_slice
871           ~stop:(source_buffer#get_iter_at_mark mark)
872       in
873       let script = MatitaScript.current () in
874       let locked = `MARK script#locked_mark in
875       let string_pos mark = string_of_int (String.length (slice mark)) in
876       let cursor_pos = string_pos `INSERT in
877       let locked_pos = string_pos locked in
878       let cmd =
879         Pcre.replace ~pat:"%f" ~templ:fname
880           (Pcre.replace ~pat:"%p" ~templ:cursor_pos
881             (Pcre.replace ~pat:"%l" ~templ:locked_pos
882               cmd))
883       in
884       let locked_before = slice locked in
885       let locked_offset = (source_buffer#get_iter_at_mark locked)#offset in
886       ignore (Unix.system cmd);
887       source_buffer#set_text (HExtlib.input_file fname);
888       let locked_iter = source_buffer#get_iter (`OFFSET locked_offset) in
889       source_buffer#move_mark locked locked_iter;
890       source_buffer#apply_tag script#locked_tag
891         ~start:source_buffer#start_iter ~stop:locked_iter;
892       let locked_after = slice locked in
893       let line = ref 0 in
894       let col = ref 0 in
895       try
896         for i = 0 to String.length locked_before - 1 do
897           if locked_before.[i] <> locked_after.[i] then begin
898             source_buffer#place_cursor
899               ~where:(source_buffer#get_iter (`LINEBYTE (!line, !col)));
900             script#goto `Cursor ();
901             raise Exit
902           end else if locked_before.[i] = '\n' then begin
903             incr line;
904             col := 0
905           end
906         done
907       with
908       | Exit -> ()
909       | Invalid_argument _ -> script#goto `Bottom ()
910
911     method loadScript file =       
912       let script = MatitaScript.current () in
913       script#reset (); 
914       script#assignFileName file;
915       let content =
916        if Sys.file_exists file then file
917        else BuildTimeConf.script_template
918       in
919        source_view#source_buffer#begin_not_undoable_action ();
920        script#loadFromFile content;
921        source_view#source_buffer#end_not_undoable_action ();
922        console#message ("'"^file^"' loaded.");
923        self#_enableSaveTo file
924       
925     method setStar name b =
926       let l = main#scriptLabel in
927       if b then
928         l#set_text (name ^  " *")
929       else
930         l#set_text (name)
931         
932     method private _enableSaveTo file =
933       script_fname <- Some file;
934       self#main#saveMenuItem#misc#set_sensitive true
935         
936     method console = console
937     method sourceView: GSourceView.source_view =
938       (source_view: GSourceView.source_view)
939     method fileSel = fileSel
940     method findRepl = findRepl
941     method main = main
942     method develList = develList
943     method newDevel = newDevel
944
945     method newBrowserWin () =
946       object (self)
947         inherit browserWin ()
948         val combo = GEdit.combo_box_entry ()
949         initializer
950           self#check_widgets ();
951           let combo_widget = combo#coerce in
952           uriHBox#pack ~from:`END ~fill:true ~expand:true combo_widget;
953           combo#entry#misc#grab_focus ()
954         method browserUri = combo
955       end
956
957     method newUriDialog () =
958       let dialog = new uriChoiceDialog () in
959       dialog#check_widgets ();
960       dialog
961
962     method newRecordDialog () =
963       let dialog = new recordChoiceDialog () in
964       dialog#check_widgets ();
965       dialog
966
967     method newConfirmationDialog () =
968       let dialog = new confirmationDialog () in
969       dialog#check_widgets ();
970       dialog
971
972     method newEmptyDialog () =
973       let dialog = new emptyDialog () in
974       dialog#check_widgets ();
975       dialog
976
977     method private addKeyBinding key callback =
978       List.iter (fun evbox -> add_key_binding key callback evbox)
979         keyBindingBoxes
980
981     method setQuitCallback callback =
982       connect_menu_item main#quitMenuItem callback;
983       ignore (main#toplevel#event#connect#delete 
984         (fun _ -> callback ();true));
985       self#addKeyBinding GdkKeysyms._q callback
986
987     method chooseFile ?(ok_not_exists = false) () =
988       _ok_not_exists <- ok_not_exists;
989       _only_directory <- false;
990       fileSel#fileSelectionWin#show ();
991       GtkThread.main ();
992       chosen_file
993
994     method private chooseDir ?(ok_not_exists = false) () =
995       _ok_not_exists <- ok_not_exists;
996       _only_directory <- true;
997       fileSel#fileSelectionWin#show ();
998       GtkThread.main ();
999       (* we should check that this is a directory *)
1000       chosen_file
1001   
1002     method createDevelopment ~containing =
1003       next_devel_must_contain <- containing;
1004       newDevel#toplevel#misc#show()
1005
1006     method askText ?(title = "") ?(msg = "") () =
1007       let dialog = new textDialog () in
1008       dialog#textDialog#set_title title;
1009       dialog#textDialogLabel#set_label msg;
1010       let text = ref None in
1011       let return v =
1012         text := v;
1013         dialog#textDialog#destroy ();
1014         GMain.Main.quit ()
1015       in
1016       ignore (dialog#textDialog#event#connect#delete (fun _ -> true));
1017       connect_button dialog#textDialogCancelButton (fun _ -> return None);
1018       connect_button dialog#textDialogOkButton (fun _ ->
1019         let text = dialog#textDialogTextView#buffer#get_text () in
1020         return (Some text));
1021       dialog#textDialog#show ();
1022       GtkThread.main ();
1023       !text
1024
1025     method private updateFontSize () =
1026       self#sourceView#misc#modify_font_by_name
1027         (sprintf "%s %d" BuildTimeConf.script_font font_size)
1028
1029     method increaseFontSize () =
1030       font_size <- font_size + 1;
1031       self#updateFontSize ()
1032
1033     method decreaseFontSize () =
1034       font_size <- font_size - 1;
1035       self#updateFontSize ()
1036
1037     method resetFontSize () =
1038       font_size <- default_font_size;
1039       self#updateFontSize ()
1040
1041   end
1042
1043 let gui () = 
1044   let g = new gui () in
1045   gui_instance := Some g;
1046   MatitaMathView.set_gui g;
1047   g
1048   
1049 let instance = singleton gui
1050
1051 let non p x = not (p x)
1052
1053 (* this is a shit and should be changed :-{ *)
1054 let interactive_uri_choice
1055   ?(selection_mode:[`SINGLE|`MULTIPLE] = `MULTIPLE) ?(title = "")
1056   ?(msg = "") ?(nonvars_button = false) ?(hide_uri_entry=false) 
1057   ?(hide_try=false) ?(ok_label="_Auto") ?(ok_action:[`SELECT|`AUTO] = `AUTO) 
1058   ?copy_cb ()
1059   ~id uris
1060 =
1061   let gui = instance () in
1062   let nonvars_uris = lazy (List.filter (non UriManager.uri_is_var) uris) in
1063   if (selection_mode <> `SINGLE) &&
1064     (Helm_registry.get_bool "matita.auto_disambiguation")
1065   then
1066     Lazy.force nonvars_uris
1067   else begin
1068     let dialog = gui#newUriDialog () in
1069     if hide_uri_entry then
1070       dialog#uriEntryHBox#misc#hide ();
1071     if hide_try then
1072       begin
1073       dialog#uriChoiceSelectedButton#misc#hide ();
1074       dialog#uriChoiceConstantsButton#misc#hide ();
1075       end;
1076     dialog#okLabel#set_label ok_label;  
1077     dialog#uriChoiceTreeView#selection#set_mode
1078       (selection_mode :> Gtk.Tags.selection_mode);
1079     let model = new stringListModel dialog#uriChoiceTreeView in
1080     let choices = ref None in
1081     (match copy_cb with
1082     | None -> ()
1083     | Some cb ->
1084         dialog#copyButton#misc#show ();
1085         connect_button dialog#copyButton 
1086         (fun _ ->
1087           match model#easy_selection () with
1088           | [u] -> (cb u)
1089           | _ -> ()));
1090     dialog#uriChoiceDialog#set_title title;
1091     dialog#uriChoiceLabel#set_text msg;
1092     List.iter model#easy_append (List.map UriManager.string_of_uri uris);
1093     dialog#uriChoiceConstantsButton#misc#set_sensitive nonvars_button;
1094     let return v =
1095       choices := v;
1096       dialog#uriChoiceDialog#destroy ();
1097       GMain.Main.quit ()
1098     in
1099     ignore (dialog#uriChoiceDialog#event#connect#delete (fun _ -> true));
1100     connect_button dialog#uriChoiceConstantsButton (fun _ ->
1101       return (Some (Lazy.force nonvars_uris)));
1102     if ok_action = `AUTO then
1103       connect_button dialog#uriChoiceAutoButton (fun _ ->
1104         Helm_registry.set_bool "matita.auto_disambiguation" true;
1105         return (Some (Lazy.force nonvars_uris)))
1106     else
1107       connect_button dialog#uriChoiceAutoButton (fun _ ->
1108         match model#easy_selection () with
1109         | [] -> ()
1110         | uris -> return (Some (List.map UriManager.uri_of_string uris)));
1111     connect_button dialog#uriChoiceSelectedButton (fun _ ->
1112       match model#easy_selection () with
1113       | [] -> ()
1114       | uris -> return (Some (List.map UriManager.uri_of_string uris)));
1115     connect_button dialog#uriChoiceAbortButton (fun _ -> return None);
1116     dialog#uriChoiceDialog#show ();
1117     GtkThread.main ();
1118     (match !choices with 
1119     | None -> raise MatitaTypes.Cancel
1120     | Some uris -> uris)
1121   end
1122
1123 class interpModel =
1124   let cols = new GTree.column_list in
1125   let id_col = cols#add Gobject.Data.string in
1126   let dsc_col = cols#add Gobject.Data.string in
1127   let interp_no_col = cols#add Gobject.Data.int in
1128   let tree_store = GTree.tree_store cols in
1129   let id_renderer = GTree.cell_renderer_text [], ["text", id_col] in
1130   let dsc_renderer = GTree.cell_renderer_text [], ["text", dsc_col] in
1131   let id_view_col = GTree.view_column ~renderer:id_renderer () in
1132   let dsc_view_col = GTree.view_column ~renderer:dsc_renderer () in
1133   fun tree_view choices ->
1134     object
1135       initializer
1136         tree_view#set_model (Some (tree_store :> GTree.model));
1137         ignore (tree_view#append_column id_view_col);
1138         ignore (tree_view#append_column dsc_view_col);
1139         let name_of_interp =
1140           (* try to find a reasonable name for an interpretation *)
1141           let idx = ref 0 in
1142           fun interp ->
1143             try
1144               List.assoc "0" interp
1145             with Not_found ->
1146               incr idx; string_of_int !idx
1147         in
1148         tree_store#clear ();
1149         let idx = ref ~-1 in
1150         List.iter
1151           (fun interp ->
1152             incr idx;
1153             let interp_row = tree_store#append () in
1154             tree_store#set ~row:interp_row ~column:id_col
1155               (name_of_interp interp);
1156             tree_store#set ~row:interp_row ~column:interp_no_col !idx;
1157             List.iter
1158               (fun (id, dsc) ->
1159                 let row = tree_store#append ~parent:interp_row () in
1160                 tree_store#set ~row ~column:id_col id;
1161                 tree_store#set ~row ~column:dsc_col dsc;
1162                 tree_store#set ~row ~column:interp_no_col !idx)
1163               interp)
1164           choices
1165
1166       method get_interp_no tree_path =
1167         let iter = tree_store#get_iter tree_path in
1168         tree_store#get ~row:iter ~column:interp_no_col
1169     end
1170
1171 let interactive_interp_choice () choices =
1172   let gui = instance () in
1173   assert (choices <> []);
1174   let dialog = gui#newRecordDialog () in
1175   let model = new interpModel dialog#recordChoiceTreeView choices in
1176   dialog#recordChoiceDialog#set_title "Interpretation choice";
1177   dialog#recordChoiceDialogLabel#set_label "Choose an interpretation:";
1178   let interp_no = ref None in
1179   let return _ =
1180     dialog#recordChoiceDialog#destroy ();
1181     GMain.Main.quit ()
1182   in
1183   let fail _ = interp_no := None; return () in
1184   ignore (dialog#recordChoiceDialog#event#connect#delete (fun _ -> true));
1185   connect_button dialog#recordChoiceOkButton (fun _ ->
1186     match !interp_no with None -> () | Some _ -> return ());
1187   connect_button dialog#recordChoiceCancelButton fail;
1188   ignore (dialog#recordChoiceTreeView#connect#row_activated (fun path _ ->
1189     interp_no := Some (model#get_interp_no path);
1190     return ()));
1191   let selection = dialog#recordChoiceTreeView#selection in
1192   ignore (selection#connect#changed (fun _ ->
1193     match selection#get_selected_rows with
1194     | [path] -> interp_no := Some (model#get_interp_no path)
1195     | _ -> assert false));
1196   dialog#recordChoiceDialog#show ();
1197   GtkThread.main ();
1198   (match !interp_no with Some row -> [row] | _ -> raise MatitaTypes.Cancel)
1199
1200 let _ =
1201   (* disambiguator callbacks *)
1202   MatitaDisambiguator.set_choose_uris_callback (interactive_uri_choice ());
1203   MatitaDisambiguator.set_choose_interp_callback (interactive_interp_choice ());
1204   (* gtk initialization *)
1205   GtkMain.Rc.add_default_file BuildTimeConf.gtkrc_file; (* loads gtk rc *)
1206   GMathView.add_configuration_path BuildTimeConf.gtkmathview_conf;
1207   ignore (GMain.Main.init ())
1208