]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaGui.ml
Bug fixed: no .moo can be generated if the status is <> No_proof
[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 let gui_instance = ref None ;;
33
34 class type browserWin =
35   (* this class exists only because GEdit.combo_box_entry is not supported by
36    * lablgladecc :-(((( *)
37 object
38   inherit MatitaGeneratedGui.browserWin
39   method browserUri: GEdit.combo_box_entry
40 end
41
42 class console ~(buffer: GText.buffer) () =
43   object (self)
44     val error_tag   = buffer#create_tag [ `FOREGROUND "red" ]
45     val warning_tag = buffer#create_tag [ `FOREGROUND "yellow" ]
46     val message_tag = buffer#create_tag []
47     val debug_tag   = buffer#create_tag [ `FOREGROUND "#888888" ]
48     method message s = buffer#insert ~iter:buffer#end_iter ~tags:[message_tag] s
49     method error s   = buffer#insert ~iter:buffer#end_iter ~tags:[error_tag] s
50     method warning s = buffer#insert ~iter:buffer#end_iter ~tags:[warning_tag] s
51     method debug s   = buffer#insert ~iter:buffer#end_iter ~tags:[debug_tag] s
52     method clear () =
53       buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter
54     method log_callback (tag: MatitaLog.log_tag) s =
55       match tag with
56       | `Debug -> self#debug (s ^ "\n")
57       | `Error -> self#error (s ^ "\n")
58       | `Message -> self#message (s ^ "\n")
59       | `Warning -> self#warning (s ^ "\n")
60   end
61         
62 let clean_current_baseuri status = 
63     try  
64       let baseuri = MatitaTypes.get_string_option status "baseuri" in
65       MatitacleanLib.clean_baseuris [baseuri]
66     with MatitaTypes.Option_error _ -> ()
67
68 let ask_and_save_moo_if_needed parent fname status = 
69   let save () =
70     MatitacLib.dump_moo_to_file fname status.MatitaTypes.moo_content_rev in
71   if (MatitaScript.instance ())#eos &&
72      status.MatitaTypes.proof_status = MatitaTypes.No_proof
73   then
74     begin
75       let mooname = 
76         MatitaMisc.obj_file_of_script fname
77       in
78       let rc = 
79         MatitaGtkMisc.ask_confirmation
80         ~title:"A .moo can be generated"
81         ~message:(Printf.sprintf 
82           "%s can be generated for %s.\n<i>Should I generate it?</i>"
83           mooname fname)
84         ~parent ()
85       in
86       let b = 
87         match rc with 
88         | `YES -> true 
89         | `NO -> false 
90         | `CANCEL -> raise MatitaTypes.Cancel 
91       in
92       if b then
93         save ()
94       else
95         clean_current_baseuri status
96     end
97   else
98     clean_current_baseuri status 
99     
100 let ask_unsaved parent =
101   MatitaGtkMisc.ask_confirmation 
102     ~parent ~title:"Unsaved work!" 
103     ~message:("Your work is <b>unsaved</b>!\n\n"^
104          "<i>Do you want to save the script before exiting?</i>")
105     ()
106
107 class gui () =
108     (* creation order _is_ relevant for windows placement *)
109   let main = new mainWin () in
110   let about = new aboutWin () in
111   let fileSel = new fileSelectionWin () in
112   let keyBindingBoxes = (* event boxes which should receive global key events *)
113     [ main#mainWinEventBox ]
114   in
115   let console = new console ~buffer:main#logTextView#buffer () in
116   let (source_view: GSourceView.source_view) =
117     GSourceView.source_view
118       ~auto_indent:true
119       ~insert_spaces_instead_of_tabs:true ~tabs_width:2
120       ~margin:80 ~show_margin:true
121       ~smart_home_end:true
122       ~packing:main#scriptScrolledWin#add
123       ()
124   in
125   let default_font_size =
126     Helm_registry.get_opt_default Helm_registry.int
127       ~default:BuildTimeConf.default_font_size "matita.font_size"
128   in
129   let source_buffer = source_view#source_buffer in
130   object (self)
131     val mutable chosen_file = None
132     val mutable _ok_not_exists = false
133     val mutable script_fname = None
134     val mutable font_size = default_font_size
135    
136     initializer
137         (* glade's check widgets *)
138       List.iter (fun w -> w#check_widgets ())
139         (let c w = (w :> <check_widgets: unit -> unit>) in
140          [ c about; c fileSel; c main ]);
141         (* key bindings *)
142       List.iter (* global key bindings *)
143         (fun (key, callback) -> self#addKeyBinding key callback)
144 (*
145         [ GdkKeysyms._F3,
146             toggle_win ~check:main#showProofMenuItem proof#proofWin;
147           GdkKeysyms._F4,
148             toggle_win ~check:main#showCheckMenuItem check#checkWin;
149 *)
150         [ ];
151         (* about win *)
152       ignore (about#aboutWin#event#connect#delete (fun _ -> true));
153       ignore (main#aboutMenuItem#connect#activate (fun _ ->
154         about#aboutWin#show ()));
155       connect_button about#aboutDismissButton (fun _ ->
156         about#aboutWin#misc#hide ());
157       about#aboutLabel#set_label (Pcre.replace ~pat:"@VERSION@"
158         ~templ:BuildTimeConf.version about#aboutLabel#label);
159         (* file selection win *)
160       ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true));
161       ignore (fileSel#fileSelectionWin#connect#response (fun event ->
162         let return r =
163           chosen_file <- r;
164           fileSel#fileSelectionWin#misc#hide ();
165           GMain.Main.quit ()
166         in
167         match event with
168         | `OK ->
169             let fname = fileSel#fileSelectionWin#filename in
170             if Sys.file_exists fname then
171               (if is_regular fname then return (Some fname))
172             else
173               (if _ok_not_exists then return (Some fname))
174         | `CANCEL -> return None
175         | `HELP -> ()
176         | `DELETE_EVENT -> return None));
177         (* menus *)
178       List.iter (fun w -> w#misc#set_sensitive false) [ main#saveMenuItem ];
179       main#helpMenu#set_right_justified true;
180         (* console *)
181       let adj = main#logScrolledWin#vadjustment in
182       ignore (adj#connect#changed
183                 (fun _ -> adj#set_value (adj#upper -. adj#page_size)));
184       console#message (sprintf "\tMatita version %s\n" BuildTimeConf.version);
185         (* toolbar *)
186       let module A = TacticAst in
187       let hole = CicAst.UserInput in
188       let loc = CicAst.dummy_floc in
189       let tac ast _ =
190         if (MatitaScript.instance ())#onGoingProof () then
191           (MatitaScript.instance ())#advance
192             ~statement:("\n" ^ TacticAstPp.pp_tactical (A.Tactic (loc, ast))) ()
193       in
194       let tac_w_term ast _ =
195         if (MatitaScript.instance ())#onGoingProof () then
196           let buf = source_buffer in
197           buf#insert ~iter:(buf#get_iter_at_mark (`NAME "locked"))
198             ("\n" ^ TacticAstPp.pp_tactic ast)
199       in
200       let tbar = self#main in
201       connect_button tbar#introsButton (tac (A.Intros (loc, None, [])));
202       connect_button tbar#applyButton (tac_w_term (A.Apply (loc, hole)));
203       connect_button tbar#exactButton (tac_w_term (A.Exact (loc, hole)));
204       connect_button tbar#elimButton (tac_w_term (A.Elim (loc, hole, None, None, [])));
205       connect_button tbar#elimTypeButton (tac_w_term (A.ElimType (loc, hole, None, None, [])));
206       connect_button tbar#splitButton (tac (A.Split loc));
207       connect_button tbar#leftButton (tac (A.Left loc));
208       connect_button tbar#rightButton (tac (A.Right loc));
209       connect_button tbar#existsButton (tac (A.Exists loc));
210       connect_button tbar#reflexivityButton (tac (A.Reflexivity loc));
211       connect_button tbar#symmetryButton (tac (A.Symmetry loc));
212       connect_button tbar#transitivityButton
213         (tac_w_term (A.Transitivity (loc, hole)));
214       connect_button tbar#assumptionButton (tac (A.Assumption loc));
215       connect_button tbar#cutButton (tac_w_term (A.Cut (loc, None, hole)));
216       connect_button tbar#autoButton (tac (A.Auto (loc,None,None)));
217       MatitaGtkMisc.toggle_widget_visibility
218        ~widget:(self#main#tacticsButtonsHandlebox :> GObj.widget)
219        ~check:self#main#tacticsBarMenuItem;
220       let module Hr = Helm_registry in
221       if
222         not (Hr.get_opt_default Hr.bool ~default:false "matita.tactics_bar")
223       then 
224         self#main#tacticsBarMenuItem#set_active false;
225       MatitaGtkMisc.toggle_callback 
226         ~callback:(function 
227           | true -> self#main#toplevel#fullscreen () 
228           | false -> self#main#toplevel#unfullscreen ())
229         ~check:self#main#fullscreenMenuItem;
230       self#main#fullscreenMenuItem#set_active false;
231         (* log *)
232       MatitaLog.set_log_callback self#console#log_callback;
233       GtkSignal.user_handler :=
234         (fun exn -> MatitaLog.error (MatitaExcPp.to_string exn));
235         (* script *)
236       let _ =
237         match GSourceView.source_language_from_file BuildTimeConf.lang_file with
238         | None ->
239             MatitaLog.warn (sprintf "can't load language file %s"
240               BuildTimeConf.lang_file)
241         | Some matita_lang ->
242             source_buffer#set_language matita_lang;
243             source_buffer#set_highlight true
244       in
245       let s () = MatitaScript.instance () in
246       let disableSave () =
247         script_fname <- None;
248         self#main#saveMenuItem#misc#set_sensitive false
249       in
250       let saveAsScript () =
251         let script = s () in
252         match self#chooseFile ~ok_not_exists:true () with
253         | Some f -> 
254               script#assignFileName f;
255               script#saveToFile (); 
256               console#message ("'"^f^"' saved.\n");
257               self#_enableSaveTo f
258         | None -> ()
259       in
260       let saveScript () =
261         match script_fname with
262         | None -> saveAsScript ()
263         | Some f -> 
264               (s ())#assignFileName f;
265               (s ())#saveToFile ();
266               console#message ("'"^f^"' saved.\n");
267       in
268       let loadScript () =
269         let script = s () in 
270         let status = script#status in
271         try 
272           if source_view#buffer#modified then
273             begin
274               match ask_unsaved main#toplevel with
275               | `YES -> saveScript ()
276               | `NO -> ()
277               | `CANCEL -> raise MatitaTypes.Cancel
278             end;
279           (match script_fname with
280           | None -> ()
281           | Some fname -> 
282               ask_and_save_moo_if_needed main#toplevel fname status);
283           match self#chooseFile () with
284           | Some f -> 
285                 script#reset (); 
286                 script#assignFileName f;
287                 script#loadFromFile (); 
288                 console#message ("'"^f^"' loaded.\n");
289                 self#_enableSaveTo f
290           | None -> ()
291         with MatitaTypes.Cancel -> ()
292       in
293       let newScript () = 
294         (s ())#reset (); 
295         (s ())#template (); 
296         disableSave ();
297         script_fname <- None
298       in
299       let cursor () =
300         source_buffer#place_cursor
301           (source_buffer#get_iter_at_mark (`NAME "locked"))
302       in
303       let advance _ = (MatitaScript.instance ())#advance (); cursor () in
304       let retract _ = (MatitaScript.instance ())#retract (); cursor () in
305       let top _ = (MatitaScript.instance ())#goto `Top (); cursor () in
306       let bottom _ = (MatitaScript.instance ())#goto `Bottom (); cursor () in
307       let jump _ = (MatitaScript.instance ())#goto `Cursor (); cursor () in
308       let connect_key sym f =
309         connect_key self#main#mainWinEventBox#event
310           ~modifiers:[`CONTROL] ~stop:true sym f;
311         connect_key self#sourceView#event
312           ~modifiers:[`CONTROL] ~stop:true sym f
313       in
314         (* quit *)
315       self#setQuitCallback (fun () -> 
316         let status = (MatitaScript.instance ())#status in
317         if source_view#buffer#modified then
318           begin
319             let rc = ask_unsaved main#toplevel in 
320             try
321               match rc with
322               | `YES -> saveScript ();
323                         if not source_view#buffer#modified then
324                           begin
325                             (match script_fname with
326                             | None -> ()
327                             | Some fname -> 
328                                ask_and_save_moo_if_needed 
329                                  main#toplevel fname status);
330                           GMain.Main.quit ()
331                           end
332               | `NO -> GMain.Main.quit ()
333               | `CANCEL -> raise MatitaTypes.Cancel
334             with MatitaTypes.Cancel -> ()
335           end 
336         else 
337           begin  
338             (match script_fname with
339             | None -> clean_current_baseuri status; GMain.Main.quit ()
340             | Some fname ->
341                 try
342                   ask_and_save_moo_if_needed main#toplevel fname status;
343                   GMain.Main.quit ()
344                 with MatitaTypes.Cancel -> ())
345           end);
346       connect_button self#main#scriptAdvanceButton advance;
347       connect_button self#main#scriptRetractButton retract;
348       connect_button self#main#scriptTopButton top;
349       connect_button self#main#scriptBottomButton bottom;
350       connect_key GdkKeysyms._Down advance;
351       connect_key GdkKeysyms._Up retract;
352       connect_key GdkKeysyms._Home top;
353       connect_key GdkKeysyms._End bottom;
354       connect_button self#main#scriptJumpButton jump;
355       connect_menu_item self#main#openMenuItem   loadScript;
356       connect_menu_item self#main#saveMenuItem   saveScript;
357       connect_menu_item self#main#saveAsMenuItem saveAsScript;
358       connect_menu_item self#main#newMenuItem    newScript;
359       connect_key GdkKeysyms._period
360         (fun () ->
361           source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT)
362             ".\n";
363           advance ());
364       connect_key GdkKeysyms._Return
365         (fun () ->
366           source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT)
367             "\n";
368           advance ());
369          (* script monospace font stuff *)  
370       self#updateFontSize ();
371         (* debug menu *)
372       self#main#debugMenu#misc#hide ();
373         (* status bar *)
374       self#main#hintLowImage#set_file (image_path "matita-bulb-low.png");
375       self#main#hintMediumImage#set_file (image_path "matita-bulb-medium.png");
376       self#main#hintHighImage#set_file (image_path "matita-bulb-high.png");
377         (* focus *)
378       self#sourceView#misc#grab_focus ();
379         (* main win dimension *)
380       let width = Gdk.Screen.width () in
381       let height = Gdk.Screen.height () in
382       let main_w = width * 90 / 100 in 
383       let main_h = height * 80 / 100 in
384       let script_w = main_w * 6 / 10 in
385       self#main#toplevel#resize ~width:main_w ~height:main_h;
386       self#main#hpaneScriptSequent#set_position script_w  
387     
388     method loadScript file =       
389       let script = MatitaScript.instance () in
390       script#reset (); 
391       script#assignFileName file;
392       script#loadFromFile (); 
393       console#message ("'"^file^"' loaded.");
394       self#_enableSaveTo file
395       
396     method setStar name b =
397       let l = main#scriptLabel in
398       if b then
399         l#set_text (name ^  " *")
400       else
401         l#set_text (name)
402         
403     method private _enableSaveTo file =
404       script_fname <- Some file;
405       self#main#saveMenuItem#misc#set_sensitive true
406         
407
408     method console = console
409     method sourceView: GSourceView.source_view = (source_view: GSourceView.source_view)
410     method about = about
411     method fileSel = fileSel
412     method main = main
413
414     method newBrowserWin () =
415       object (self)
416         inherit browserWin ()
417         val combo = GEdit.combo_box_entry ()
418         initializer
419           self#check_widgets ();
420           let combo_widget = combo#coerce in
421           uriHBox#pack ~from:`END ~fill:true ~expand:true combo_widget;
422           combo#entry#misc#grab_focus ()
423         method browserUri = combo
424       end
425
426     method newUriDialog () =
427       let dialog = new uriChoiceDialog () in
428       dialog#check_widgets ();
429       dialog
430
431     method newInterpDialog () =
432       let dialog = new interpChoiceDialog () in
433       dialog#check_widgets ();
434       dialog
435
436     method newConfirmationDialog () =
437       let dialog = new confirmationDialog () in
438       dialog#check_widgets ();
439       dialog
440
441     method newEmptyDialog () =
442       let dialog = new emptyDialog () in
443       dialog#check_widgets ();
444       dialog
445
446     method private addKeyBinding key callback =
447       List.iter (fun evbox -> add_key_binding key callback evbox)
448         keyBindingBoxes
449
450     method setQuitCallback callback =
451       ignore (main#quitMenuItem#connect#activate callback);
452       ignore (main#toplevel#event#connect#delete 
453         (fun _ -> callback ();true));
454       self#addKeyBinding GdkKeysyms._q callback
455
456     method chooseFile ?(ok_not_exists = false) () =
457       _ok_not_exists <- ok_not_exists;
458       fileSel#fileSelectionWin#show ();
459       GtkThread.main ();
460       chosen_file
461
462     method askText ?(title = "") ?(msg = "") () =
463       let dialog = new textDialog () in
464       dialog#textDialog#set_title title;
465       dialog#textDialogLabel#set_label msg;
466       let text = ref None in
467       let return v =
468         text := v;
469         dialog#textDialog#destroy ();
470         GMain.Main.quit ()
471       in
472       ignore (dialog#textDialog#event#connect#delete (fun _ -> true));
473       connect_button dialog#textDialogCancelButton (fun _ -> return None);
474       connect_button dialog#textDialogOkButton (fun _ ->
475         let text = dialog#textDialogTextView#buffer#get_text () in
476         return (Some text));
477       dialog#textDialog#show ();
478       GtkThread.main ();
479       !text
480
481     method private updateFontSize () =
482       self#sourceView#misc#modify_font_by_name
483         (sprintf "%s %d" BuildTimeConf.script_font font_size)
484
485     method increaseFontSize () =
486       font_size <- font_size + 1;
487       self#updateFontSize ()
488
489     method decreaseFontSize () =
490       font_size <- font_size - 1;
491       self#updateFontSize ()
492
493     method resetFontSize () =
494       font_size <- default_font_size;
495       self#updateFontSize ()
496
497   end
498
499 let gui () = 
500   let g = new gui () in
501   gui_instance := Some g;
502   g
503   
504 let instance = singleton gui
505
506 let non p x = not (p x)
507
508 (* this is a shit and should be changed :-{ *)
509 let interactive_uri_choice
510   ?(selection_mode:[`SINGLE|`MULTIPLE] = `MULTIPLE) ?(title = "")
511   ?(msg = "") ?(nonvars_button = false) ?(hide_uri_entry=false) 
512   ?(hide_try=false) ?(ok_label="_Auto") ?(ok_action:[`SELECT|`AUTO] = `AUTO) 
513   ?copy_cb ()
514   ~id uris
515 =
516   let gui = instance () in
517   let nonvars_uris = lazy (List.filter (non UriManager.uri_is_var) uris) in
518   if (selection_mode <> `SINGLE) &&
519     (Helm_registry.get_bool "matita.auto_disambiguation")
520   then
521     Lazy.force nonvars_uris
522   else begin
523     let dialog = gui#newUriDialog () in
524     if hide_uri_entry then
525       dialog#uriEntryHBox#misc#hide ();
526     if hide_try then
527       begin
528       dialog#uriChoiceSelectedButton#misc#hide ();
529       dialog#uriChoiceConstantsButton#misc#hide ();
530       end;
531     dialog#okLabel#set_label ok_label;  
532     dialog#uriChoiceTreeView#selection#set_mode
533       (selection_mode :> Gtk.Tags.selection_mode);
534     let model = new stringListModel dialog#uriChoiceTreeView in
535     let choices = ref None in
536     let nonvars = ref false in
537     (match copy_cb with
538     | None -> ()
539     | Some cb ->
540         dialog#copyButton#misc#show ();
541         connect_button dialog#copyButton 
542         (fun _ ->
543           match model#easy_selection () with
544           | [u] -> (cb u)
545           | _ -> ()));
546     dialog#uriChoiceDialog#set_title title;
547     dialog#uriChoiceLabel#set_text msg;
548     List.iter model#easy_append (List.map UriManager.string_of_uri uris);
549     dialog#uriChoiceConstantsButton#misc#set_sensitive nonvars_button;
550     let return v =
551       choices := v;
552       dialog#uriChoiceDialog#destroy ();
553       GMain.Main.quit ()
554     in
555     ignore (dialog#uriChoiceDialog#event#connect#delete (fun _ -> true));
556     connect_button dialog#uriChoiceConstantsButton (fun _ ->
557       return (Some (Lazy.force nonvars_uris)));
558     if ok_action = `AUTO then
559       connect_button dialog#uriChoiceAutoButton (fun _ ->
560         Helm_registry.set_bool "matita.auto_disambiguation" true;
561         return (Some (Lazy.force nonvars_uris)))
562     else
563       connect_button dialog#uriChoiceAutoButton (fun _ ->
564         match model#easy_selection () with
565         | [] -> ()
566         | uris -> return (Some (List.map UriManager.uri_of_string uris)));
567     connect_button dialog#uriChoiceSelectedButton (fun _ ->
568       match model#easy_selection () with
569       | [] -> ()
570       | uris -> return (Some (List.map UriManager.uri_of_string uris)));
571     connect_button dialog#uriChoiceAbortButton (fun _ -> return None);
572     dialog#uriChoiceDialog#show ();
573     GtkThread.main ();
574     (match !choices with 
575     | None -> raise MatitaTypes.Cancel
576     | Some uris -> uris)
577   end
578
579 class interpModel =
580   let cols = new GTree.column_list in
581   let id_col = cols#add Gobject.Data.string in
582   let dsc_col = cols#add Gobject.Data.string in
583   let interp_no_col = cols#add Gobject.Data.int in
584   let tree_store = GTree.tree_store cols in
585   let id_renderer = GTree.cell_renderer_text [], ["text", id_col] in
586   let dsc_renderer = GTree.cell_renderer_text [], ["text", dsc_col] in
587   let id_view_col = GTree.view_column ~renderer:id_renderer () in
588   let dsc_view_col = GTree.view_column ~renderer:dsc_renderer () in
589   fun tree_view choices ->
590     object
591       initializer
592         tree_view#set_model (Some (tree_store :> GTree.model));
593         ignore (tree_view#append_column id_view_col);
594         ignore (tree_view#append_column dsc_view_col);
595         let name_of_interp =
596           (* try to find a reasonable name for an interpretation *)
597           let idx = ref 0 in
598           fun interp ->
599             try
600               List.assoc "0" interp
601             with Not_found ->
602               incr idx; string_of_int !idx
603         in
604         tree_store#clear ();
605         let idx = ref ~-1 in
606         List.iter
607           (fun interp ->
608             incr idx;
609             let interp_row = tree_store#append () in
610             tree_store#set ~row:interp_row ~column:id_col
611               (name_of_interp interp);
612             tree_store#set ~row:interp_row ~column:interp_no_col !idx;
613             List.iter
614               (fun (id, dsc) ->
615                 let row = tree_store#append ~parent:interp_row () in
616                 tree_store#set ~row ~column:id_col id;
617                 tree_store#set ~row ~column:dsc_col dsc;
618                 tree_store#set ~row ~column:interp_no_col !idx)
619               interp)
620           choices
621
622       method get_interp_no tree_path =
623         let iter = tree_store#get_iter tree_path in
624         tree_store#get ~row:iter ~column:interp_no_col
625     end
626
627 let interactive_interp_choice () choices =
628   let gui = instance () in
629   assert (choices <> []);
630   let dialog = gui#newInterpDialog () in
631   let model = new interpModel dialog#interpChoiceTreeView choices in
632   let interp_len = List.length (List.hd choices) in
633   dialog#interpChoiceDialog#set_title "Interpretation choice";
634   dialog#interpChoiceDialogLabel#set_label "Choose an interpretation:";
635   let interp_no = ref None in
636   let return _ =
637     dialog#interpChoiceDialog#destroy ();
638     GMain.Main.quit ()
639   in
640   let fail _ = interp_no := None; return () in
641   ignore (dialog#interpChoiceDialog#event#connect#delete (fun _ -> true));
642   connect_button dialog#interpChoiceOkButton (fun _ ->
643     match !interp_no with None -> () | Some _ -> return ());
644   connect_button dialog#interpChoiceCancelButton fail;
645   ignore (dialog#interpChoiceTreeView#connect#row_activated (fun path _ ->
646     interp_no := Some (model#get_interp_no path);
647     return ()));
648   let selection = dialog#interpChoiceTreeView#selection in
649   ignore (selection#connect#changed (fun _ ->
650     match selection#get_selected_rows with
651     | [path] ->
652         MatitaLog.debug (sprintf "selection: %d" (model#get_interp_no path));
653         interp_no := Some (model#get_interp_no path)
654     | _ -> assert false));
655   dialog#interpChoiceDialog#show ();
656   GtkThread.main ();
657   (match !interp_no with Some row -> [row] | _ -> raise MatitaTypes.Cancel)
658