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