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