1 (* Copyright (C) 2004-2005, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 open MatitaGeneratedGui
32 let gui_instance = ref None ;;
34 class type browserWin =
35 (* this class exists only because GEdit.combo_box_entry is not supported by
36 * lablgladecc :-(((( *)
38 inherit MatitaGeneratedGui.browserWin
39 method browserUri: GEdit.combo_box_entry
42 class console ~(buffer: GText.buffer) () =
44 val error_tag = buffer#create_tag [ `FOREGROUND "red" ]
45 val warning_tag = buffer#create_tag [ `FOREGROUND "orange" ]
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
53 buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter
54 method log_callback (tag: MatitaLog.log_tag) s =
56 | `Debug -> self#debug (s ^ "\n")
57 | `Error -> self#error (s ^ "\n")
58 | `Message -> self#message (s ^ "\n")
59 | `Warning -> self#warning (s ^ "\n")
62 let clean_current_baseuri status =
64 let baseuri = MatitaTypes.get_string_option status "baseuri" in
65 MatitacleanLib.clean_baseuris [baseuri]
66 with MatitaTypes.Option_error _ -> ()
68 let ask_and_save_moo_if_needed parent fname status =
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
76 MatitaMisc.obj_file_of_script fname
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>"
90 | `CANCEL -> raise MatitaTypes.Cancel
95 clean_current_baseuri status
98 clean_current_baseuri status
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>")
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 findRepl = new findReplWin () in
113 let develList = new develListWin () in
114 let newDevel = new newDevelopmentWin () in
115 let keyBindingBoxes = (* event boxes which should receive global key events *)
116 [ main#mainWinEventBox ]
118 let console = new console ~buffer:main#logTextView#buffer () in
119 let (source_view: GSourceView.source_view) =
120 GSourceView.source_view
122 ~insert_spaces_instead_of_tabs:true ~tabs_width:2
123 ~margin:80 ~show_margin:true
125 ~packing:main#scriptScrolledWin#add
128 let default_font_size =
129 Helm_registry.get_opt_default Helm_registry.int
130 ~default:BuildTimeConf.default_font_size "matita.font_size"
132 let source_buffer = source_view#source_buffer in
134 val mutable chosen_file = None
135 val mutable _ok_not_exists = false
136 val mutable _only_directory = false
137 val mutable script_fname = None
138 val mutable font_size = default_font_size
139 val mutable next_devel_must_contain = None
142 (* glade's check widgets *)
143 List.iter (fun w -> w#check_widgets ())
144 (let c w = (w :> <check_widgets: unit -> unit>) in
145 [ c about; c fileSel; c main; c findRepl]);
147 List.iter (* global key bindings *)
148 (fun (key, callback) -> self#addKeyBinding key callback)
151 toggle_win ~check:main#showProofMenuItem proof#proofWin;
153 toggle_win ~check:main#showCheckMenuItem check#checkWin;
157 ignore (about#aboutWin#event#connect#delete (fun _ -> true));
158 ignore (main#aboutMenuItem#connect#activate (fun _ ->
159 about#aboutWin#show ()));
160 connect_button about#aboutDismissButton (fun _ ->
161 about#aboutWin#misc#hide ());
162 about#aboutLabel#set_label (Pcre.replace ~pat:"@VERSION@"
163 ~templ:BuildTimeConf.version about#aboutLabel#label);
165 let show_find_Repl () =
166 findRepl#toplevel#misc#show ();
167 findRepl#toplevel#misc#grab_focus ()
169 let hide_find_Repl () = findRepl#toplevel#misc#hide () in
171 let highlight start end_ =
172 source_buffer#move_mark `INSERT ~where:start;
173 source_buffer#move_mark `SEL_BOUND ~where:end_;
174 source_view#scroll_mark_onscreen `INSERT
176 let text = findRepl#findEntry#text in
177 let iter = source_buffer#get_iter `SEL_BOUND in
178 match iter#forward_search text with
180 (match source_buffer#start_iter#forward_search text with
182 | Some (start,end_) -> highlight start end_)
183 | Some (start,end_) -> highlight start end_
186 let text = findRepl#replaceEntry#text in
187 let ins = source_buffer#get_iter `INSERT in
188 let sel = source_buffer#get_iter `SEL_BOUND in
189 if ins#compare sel < 0 then
191 ignore(source_buffer#delete_selection ());
192 source_buffer#insert text
195 connect_button findRepl#findButton find_forward;
196 connect_button findRepl#findReplButton replace;
197 connect_button findRepl#cancelButton (fun _ -> hide_find_Repl ());
198 ignore(findRepl#toplevel#event#connect#delete
199 ~callback:(fun _ -> hide_find_Repl ();true));
200 ignore(self#main#undoMenuItem#connect#activate
201 ~callback:source_view#source_buffer#undo);
202 ignore(source_view#source_buffer#connect#can_undo
203 ~callback:self#main#undoMenuItem#misc#set_sensitive);
204 ignore(self#main#redoMenuItem#connect#activate
205 ~callback:source_view#source_buffer#redo);
206 ignore(source_view#source_buffer#connect#can_redo
207 ~callback:self#main#redoMenuItem#misc#set_sensitive);
209 let atom = Gdk.Atom.clipboard in
210 GData.clipboard atom in
211 ignore(self#main#cutMenuItem#connect#activate
212 ~callback:(fun () -> source_view#buffer#cut_clipboard clipboard));
213 ignore(self#main#copyMenuItem#connect#activate
214 ~callback:(fun () -> source_view#buffer#copy_clipboard clipboard));
215 ignore(self#main#pasteMenuItem#connect#activate
217 source_view#buffer#paste_clipboard clipboard;
218 (MatitaScript.instance ())#clean_dirty_lock));
219 ignore(self#main#deleteMenuItem#connect#activate
220 ~callback:(fun () -> ignore (source_view#buffer#delete_selection ())));
221 ignore(self#main#findReplMenuItem#connect#activate
222 ~callback:show_find_Repl);
223 ignore (findRepl#findEntry#connect#activate ~callback:find_forward);
224 (* developments win *)
226 new MatitaGtkMisc.multiStringListModel
227 ~cols:2 develList#developmentsTreeview
229 let refresh_devels_win () =
230 model#list_store#clear ();
232 (fun (name, root) -> model#easy_mappend [name;root])
233 (MatitamakeLib.list_known_developments ())
235 let get_devel_selected () =
236 match model#easy_mselection () with
237 | [[name;_]] -> MatitamakeLib.development_for_name name
240 connect_button develList#newButton
242 next_devel_must_contain <- None;
243 newDevel#toplevel#misc#show());
244 connect_button develList#deleteButton
246 (match get_devel_selected () with
248 | Some d -> MatitamakeLib.destroy_development d);
249 refresh_devels_win ());
251 while Glib.Main.pending () do
252 ignore(Glib.Main.iteration false);
255 connect_button develList#buildButton
257 match get_devel_selected () with
259 | Some d -> ignore(MatitamakeLib.build_development_in_bg refresh d));
260 connect_button develList#cleanButton
262 match get_devel_selected () with
264 | Some d -> ignore(MatitamakeLib.clean_development_in_bg refresh d));
265 connect_button develList#closeButton
266 (fun () -> develList#toplevel#misc#hide());
267 ignore(develList#toplevel#event#connect#delete
268 (fun _ -> develList#toplevel#misc#hide();true));
269 let selected_devel = ref None in
270 connect_menu_item self#main#developmentsMenuItem
271 (fun () -> refresh_devels_win ();develList#toplevel#misc#show ());
273 (* add development win *)
274 let check_if_root_contains root =
275 match next_devel_must_contain with
278 let is_prefix_of d1 d2 =
279 let len1 = String.length d1 in
280 let len2 = String.length d2 in
284 let pref = String.sub d2 0 len1 in
287 is_prefix_of root path
289 connect_button newDevel#addButton
291 let name = newDevel#nameEntry#text in
292 let root = newDevel#rootEntry#text in
293 if check_if_root_contains root then
295 ignore (MatitamakeLib.initialize_development name root);
296 refresh_devels_win ();
297 newDevel#nameEntry#set_text "";
298 newDevel#rootEntry#set_text "";
299 newDevel#toplevel#misc#hide()
302 MatitaLog.error ("The selected root does not contain " ^
303 match next_devel_must_contain with
305 | _ -> assert false));
306 connect_button newDevel#chooseRootButton
308 let path = self#chooseDir () in
310 | Some path -> newDevel#rootEntry#set_text path
312 connect_button newDevel#cancelButton
313 (fun () -> newDevel#toplevel#misc#hide ());
314 ignore(newDevel#toplevel#event#connect#delete
315 (fun _ -> newDevel#toplevel#misc#hide();true));
317 (* file selection win *)
318 ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true));
319 ignore (fileSel#fileSelectionWin#connect#response (fun event ->
322 fileSel#fileSelectionWin#misc#hide ();
327 let fname = fileSel#fileSelectionWin#filename in
328 if Sys.file_exists fname then
330 if is_regular fname && not(_only_directory) then
332 else if _only_directory && is_dir fname then
337 if _ok_not_exists then
340 | `CANCEL -> return None
342 | `DELETE_EVENT -> return None));
344 List.iter (fun w -> w#misc#set_sensitive false) [ main#saveMenuItem ];
345 main#helpMenu#set_right_justified true;
347 let adj = main#logScrolledWin#vadjustment in
348 ignore (adj#connect#changed
349 (fun _ -> adj#set_value (adj#upper -. adj#page_size)));
350 console#message (sprintf "\tMatita version %s\n" BuildTimeConf.version);
352 let module A = GrafiteAst in
353 let hole = CicNotationPt.UserInput in
354 let loc = Disambiguate.dummy_floc in
356 if (MatitaScript.instance ())#onGoingProof () then
357 (MatitaScript.instance ())#advance
358 ~statement:("\n" ^ GrafiteAstPp.pp_tactical (A.Tactic (loc, ast)))
361 let tac_w_term ast _ =
362 if (MatitaScript.instance ())#onGoingProof () then
363 let buf = source_buffer in
364 buf#insert ~iter:(buf#get_iter_at_mark (`NAME "locked"))
365 ("\n" ^ GrafiteAstPp.pp_tactic ast)
367 let tbar = self#main in
368 connect_button tbar#introsButton (tac (A.Intros (loc, None, [])));
369 connect_button tbar#applyButton (tac_w_term (A.Apply (loc, hole)));
370 connect_button tbar#exactButton (tac_w_term (A.Exact (loc, hole)));
371 connect_button tbar#elimButton (tac_w_term (A.Elim (loc, hole, None, None, [])));
372 connect_button tbar#elimTypeButton (tac_w_term (A.ElimType (loc, hole, None, None, [])));
373 connect_button tbar#splitButton (tac (A.Split loc));
374 connect_button tbar#leftButton (tac (A.Left loc));
375 connect_button tbar#rightButton (tac (A.Right loc));
376 connect_button tbar#existsButton (tac (A.Exists loc));
377 connect_button tbar#reflexivityButton (tac (A.Reflexivity loc));
378 connect_button tbar#symmetryButton (tac (A.Symmetry loc));
379 connect_button tbar#transitivityButton
380 (tac_w_term (A.Transitivity (loc, hole)));
381 connect_button tbar#assumptionButton (tac (A.Assumption loc));
382 connect_button tbar#cutButton (tac_w_term (A.Cut (loc, None, hole)));
383 connect_button tbar#autoButton (tac (A.Auto (loc,None,None)));
384 MatitaGtkMisc.toggle_widget_visibility
385 ~widget:(self#main#tacticsButtonsHandlebox :> GObj.widget)
386 ~check:self#main#tacticsBarMenuItem;
387 let module Hr = Helm_registry in
389 not (Hr.get_opt_default Hr.bool ~default:false "matita.tactics_bar")
391 self#main#tacticsBarMenuItem#set_active false;
392 MatitaGtkMisc.toggle_callback
394 | true -> self#main#toplevel#fullscreen ()
395 | false -> self#main#toplevel#unfullscreen ())
396 ~check:self#main#fullscreenMenuItem;
397 self#main#fullscreenMenuItem#set_active false;
399 MatitaLog.set_log_callback self#console#log_callback;
400 GtkSignal.user_handler :=
401 (fun exn -> MatitaLog.error (MatitaExcPp.to_string exn));
404 match GSourceView.source_language_from_file BuildTimeConf.lang_file with
406 MatitaLog.warn (sprintf "can't load language file %s"
407 BuildTimeConf.lang_file)
408 | Some matita_lang ->
409 source_buffer#set_language matita_lang;
410 source_buffer#set_highlight true
412 let s () = MatitaScript.instance () in
414 script_fname <- None;
415 self#main#saveMenuItem#misc#set_sensitive false
417 let saveAsScript () =
419 match self#chooseFile ~ok_not_exists:true () with
421 script#assignFileName f;
422 script#saveToFile ();
423 console#message ("'"^f^"' saved.\n");
428 match script_fname with
429 | None -> saveAsScript ()
431 (s ())#assignFileName f;
432 (s ())#saveToFile ();
433 console#message ("'"^f^"' saved.\n");
437 let status = script#status in
439 if source_view#buffer#modified then
441 match ask_unsaved main#toplevel with
442 | `YES -> saveScript ()
444 | `CANCEL -> raise MatitaTypes.Cancel
446 (match script_fname with
449 ask_and_save_moo_if_needed main#toplevel fname status);
450 match self#chooseFile () with
453 script#assignFileName f;
454 source_view#source_buffer#begin_not_undoable_action ();
455 script#loadFromFile ();
456 source_view#source_buffer#end_not_undoable_action ();
457 console#message ("'"^f^"' loaded.\n");
460 with MatitaTypes.Cancel -> ()
463 source_view#source_buffer#begin_not_undoable_action ();
466 source_view#source_buffer#end_not_undoable_action ();
471 source_buffer#place_cursor
472 (source_buffer#get_iter_at_mark (`NAME "locked"))
475 main#buttonsToolbar#misc#set_sensitive false;
476 source_view#set_editable false
479 main#buttonsToolbar#misc#set_sensitive true;
480 source_view#set_editable true
482 let advance _ = (MatitaScript.instance ())#advance (); cursor () in
483 let retract _ = (MatitaScript.instance ())#retract (); cursor () in
484 let top _ = (MatitaScript.instance ())#goto `Top (); cursor () in
485 let bottom _ = (MatitaScript.instance ())#goto `Bottom (); cursor () in
486 let jump _ = (MatitaScript.instance ())#goto `Cursor (); cursor () in
490 try f ();unlock_world () with exc -> unlock_world (); raise exc
492 let advance = locker advance in
493 let retract = locker retract in
494 let top = locker top in
495 let bottom = locker bottom in
496 let jump = locker jump in
497 let connect_key sym f =
498 connect_key self#main#mainWinEventBox#event
499 ~modifiers:[`CONTROL] ~stop:true sym f;
500 connect_key self#sourceView#event
501 ~modifiers:[`CONTROL] ~stop:true sym f
504 self#setQuitCallback (fun () ->
505 let status = (MatitaScript.instance ())#status in
506 if source_view#buffer#modified then
508 let rc = ask_unsaved main#toplevel in
511 | `YES -> saveScript ();
512 if not source_view#buffer#modified then
514 (match script_fname with
517 ask_and_save_moo_if_needed
518 main#toplevel fname status);
521 | `NO -> GMain.Main.quit ()
522 | `CANCEL -> raise MatitaTypes.Cancel
523 with MatitaTypes.Cancel -> ()
527 (match script_fname with
528 | None -> clean_current_baseuri status; GMain.Main.quit ()
531 ask_and_save_moo_if_needed main#toplevel fname status;
533 with MatitaTypes.Cancel -> ())
535 connect_button self#main#scriptAdvanceButton advance;
536 connect_button self#main#scriptRetractButton retract;
537 connect_button self#main#scriptTopButton top;
538 connect_button self#main#scriptBottomButton bottom;
539 connect_key GdkKeysyms._Down advance;
540 connect_key GdkKeysyms._Up retract;
541 connect_key GdkKeysyms._Home top;
542 connect_key GdkKeysyms._End bottom;
543 connect_button self#main#scriptJumpButton jump;
544 connect_menu_item self#main#openMenuItem loadScript;
545 connect_menu_item self#main#saveMenuItem saveScript;
546 connect_menu_item self#main#saveAsMenuItem saveAsScript;
547 connect_menu_item self#main#newMenuItem newScript;
548 connect_key GdkKeysyms._period
550 source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT)
553 connect_key GdkKeysyms._Return
555 source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT)
558 (* script monospace font stuff *)
559 self#updateFontSize ();
561 self#main#debugMenu#misc#hide ();
563 self#main#hintLowImage#set_file (image_path "matita-bulb-low.png");
564 self#main#hintMediumImage#set_file (image_path "matita-bulb-medium.png");
565 self#main#hintHighImage#set_file (image_path "matita-bulb-high.png");
567 self#sourceView#misc#grab_focus ();
568 (* main win dimension *)
569 let width = Gdk.Screen.width () in
570 let height = Gdk.Screen.height () in
571 let main_w = width * 90 / 100 in
572 let main_h = height * 80 / 100 in
573 let script_w = main_w * 6 / 10 in
574 self#main#toplevel#resize ~width:main_w ~height:main_h;
575 self#main#hpaneScriptSequent#set_position script_w;
577 ignore(source_view#connect#after#paste_clipboard
578 ~callback:(fun () -> (MatitaScript.instance ())#clean_dirty_lock))
580 method loadScript file =
581 let script = MatitaScript.instance () in
583 script#assignFileName file;
584 if not (Sys.file_exists file) then
586 let oc = open_out file in
587 let template = MatitaMisc.input_file BuildTimeConf.script_template in
588 output_string oc template;
591 source_view#source_buffer#begin_not_undoable_action ();
592 script#loadFromFile ();
593 source_view#source_buffer#end_not_undoable_action ();
594 console#message ("'"^file^"' loaded.");
595 self#_enableSaveTo file
597 method setStar name b =
598 let l = main#scriptLabel in
600 l#set_text (name ^ " *")
604 method private _enableSaveTo file =
605 script_fname <- Some file;
606 self#main#saveMenuItem#misc#set_sensitive true
609 method console = console
610 method sourceView: GSourceView.source_view = (source_view: GSourceView.source_view)
612 method fileSel = fileSel
613 method findRepl = findRepl
615 method develList = develList
616 method newDevel = newDevel
618 method newBrowserWin () =
620 inherit browserWin ()
621 val combo = GEdit.combo_box_entry ()
623 self#check_widgets ();
624 let combo_widget = combo#coerce in
625 uriHBox#pack ~from:`END ~fill:true ~expand:true combo_widget;
626 combo#entry#misc#grab_focus ()
627 method browserUri = combo
630 method newUriDialog () =
631 let dialog = new uriChoiceDialog () in
632 dialog#check_widgets ();
635 method newInterpDialog () =
636 let dialog = new interpChoiceDialog () in
637 dialog#check_widgets ();
640 method newConfirmationDialog () =
641 let dialog = new confirmationDialog () in
642 dialog#check_widgets ();
645 method newEmptyDialog () =
646 let dialog = new emptyDialog () in
647 dialog#check_widgets ();
650 method private addKeyBinding key callback =
651 List.iter (fun evbox -> add_key_binding key callback evbox)
654 method setQuitCallback callback =
655 ignore (main#quitMenuItem#connect#activate callback);
656 ignore (main#toplevel#event#connect#delete
657 (fun _ -> callback ();true));
658 self#addKeyBinding GdkKeysyms._q callback
660 method chooseFile ?(ok_not_exists = false) () =
661 _ok_not_exists <- ok_not_exists;
662 _only_directory <- false;
663 fileSel#fileSelectionWin#show ();
667 method private chooseDir ?(ok_not_exists = false) () =
668 _ok_not_exists <- ok_not_exists;
669 _only_directory <- true;
670 fileSel#fileSelectionWin#show ();
672 (* we should check that this is a directory *)
675 method createDevelopment ~containing =
676 next_devel_must_contain <- containing;
677 newDevel#toplevel#misc#show()
679 method askText ?(title = "") ?(msg = "") () =
680 let dialog = new textDialog () in
681 dialog#textDialog#set_title title;
682 dialog#textDialogLabel#set_label msg;
683 let text = ref None in
686 dialog#textDialog#destroy ();
689 ignore (dialog#textDialog#event#connect#delete (fun _ -> true));
690 connect_button dialog#textDialogCancelButton (fun _ -> return None);
691 connect_button dialog#textDialogOkButton (fun _ ->
692 let text = dialog#textDialogTextView#buffer#get_text () in
694 dialog#textDialog#show ();
698 method private updateFontSize () =
699 self#sourceView#misc#modify_font_by_name
700 (sprintf "%s %d" BuildTimeConf.script_font font_size)
702 method increaseFontSize () =
703 font_size <- font_size + 1;
704 self#updateFontSize ()
706 method decreaseFontSize () =
707 font_size <- font_size - 1;
708 self#updateFontSize ()
710 method resetFontSize () =
711 font_size <- default_font_size;
712 self#updateFontSize ()
717 let g = new gui () in
718 gui_instance := Some g;
721 let instance = singleton gui
723 let non p x = not (p x)
725 (* this is a shit and should be changed :-{ *)
726 let interactive_uri_choice
727 ?(selection_mode:[`SINGLE|`MULTIPLE] = `MULTIPLE) ?(title = "")
728 ?(msg = "") ?(nonvars_button = false) ?(hide_uri_entry=false)
729 ?(hide_try=false) ?(ok_label="_Auto") ?(ok_action:[`SELECT|`AUTO] = `AUTO)
733 let gui = instance () in
734 let nonvars_uris = lazy (List.filter (non UriManager.uri_is_var) uris) in
735 if (selection_mode <> `SINGLE) &&
736 (Helm_registry.get_bool "matita.auto_disambiguation")
738 Lazy.force nonvars_uris
740 let dialog = gui#newUriDialog () in
741 if hide_uri_entry then
742 dialog#uriEntryHBox#misc#hide ();
745 dialog#uriChoiceSelectedButton#misc#hide ();
746 dialog#uriChoiceConstantsButton#misc#hide ();
748 dialog#okLabel#set_label ok_label;
749 dialog#uriChoiceTreeView#selection#set_mode
750 (selection_mode :> Gtk.Tags.selection_mode);
751 let model = new stringListModel dialog#uriChoiceTreeView in
752 let choices = ref None in
753 let nonvars = ref false in
757 dialog#copyButton#misc#show ();
758 connect_button dialog#copyButton
760 match model#easy_selection () with
763 dialog#uriChoiceDialog#set_title title;
764 dialog#uriChoiceLabel#set_text msg;
765 List.iter model#easy_append (List.map UriManager.string_of_uri uris);
766 dialog#uriChoiceConstantsButton#misc#set_sensitive nonvars_button;
769 dialog#uriChoiceDialog#destroy ();
772 ignore (dialog#uriChoiceDialog#event#connect#delete (fun _ -> true));
773 connect_button dialog#uriChoiceConstantsButton (fun _ ->
774 return (Some (Lazy.force nonvars_uris)));
775 if ok_action = `AUTO then
776 connect_button dialog#uriChoiceAutoButton (fun _ ->
777 Helm_registry.set_bool "matita.auto_disambiguation" true;
778 return (Some (Lazy.force nonvars_uris)))
780 connect_button dialog#uriChoiceAutoButton (fun _ ->
781 match model#easy_selection () with
783 | uris -> return (Some (List.map UriManager.uri_of_string uris)));
784 connect_button dialog#uriChoiceSelectedButton (fun _ ->
785 match model#easy_selection () with
787 | uris -> return (Some (List.map UriManager.uri_of_string uris)));
788 connect_button dialog#uriChoiceAbortButton (fun _ -> return None);
789 dialog#uriChoiceDialog#show ();
792 | None -> raise MatitaTypes.Cancel
797 let cols = new GTree.column_list in
798 let id_col = cols#add Gobject.Data.string in
799 let dsc_col = cols#add Gobject.Data.string in
800 let interp_no_col = cols#add Gobject.Data.int in
801 let tree_store = GTree.tree_store cols in
802 let id_renderer = GTree.cell_renderer_text [], ["text", id_col] in
803 let dsc_renderer = GTree.cell_renderer_text [], ["text", dsc_col] in
804 let id_view_col = GTree.view_column ~renderer:id_renderer () in
805 let dsc_view_col = GTree.view_column ~renderer:dsc_renderer () in
806 fun tree_view choices ->
809 tree_view#set_model (Some (tree_store :> GTree.model));
810 ignore (tree_view#append_column id_view_col);
811 ignore (tree_view#append_column dsc_view_col);
813 (* try to find a reasonable name for an interpretation *)
817 List.assoc "0" interp
819 incr idx; string_of_int !idx
826 let interp_row = tree_store#append () in
827 tree_store#set ~row:interp_row ~column:id_col
828 (name_of_interp interp);
829 tree_store#set ~row:interp_row ~column:interp_no_col !idx;
832 let row = tree_store#append ~parent:interp_row () in
833 tree_store#set ~row ~column:id_col id;
834 tree_store#set ~row ~column:dsc_col dsc;
835 tree_store#set ~row ~column:interp_no_col !idx)
839 method get_interp_no tree_path =
840 let iter = tree_store#get_iter tree_path in
841 tree_store#get ~row:iter ~column:interp_no_col
844 let interactive_interp_choice () choices =
845 let gui = instance () in
846 assert (choices <> []);
847 let dialog = gui#newInterpDialog () in
848 let model = new interpModel dialog#interpChoiceTreeView choices in
849 let interp_len = List.length (List.hd choices) in
850 dialog#interpChoiceDialog#set_title "Interpretation choice";
851 dialog#interpChoiceDialogLabel#set_label "Choose an interpretation:";
852 let interp_no = ref None in
854 dialog#interpChoiceDialog#destroy ();
857 let fail _ = interp_no := None; return () in
858 ignore (dialog#interpChoiceDialog#event#connect#delete (fun _ -> true));
859 connect_button dialog#interpChoiceOkButton (fun _ ->
860 match !interp_no with None -> () | Some _ -> return ());
861 connect_button dialog#interpChoiceCancelButton fail;
862 ignore (dialog#interpChoiceTreeView#connect#row_activated (fun path _ ->
863 interp_no := Some (model#get_interp_no path);
865 let selection = dialog#interpChoiceTreeView#selection in
866 ignore (selection#connect#changed (fun _ ->
867 match selection#get_selected_rows with
869 MatitaLog.debug (sprintf "selection: %d" (model#get_interp_no path));
870 interp_no := Some (model#get_interp_no path)
871 | _ -> assert false));
872 dialog#interpChoiceDialog#show ();
874 (match !interp_no with Some row -> [row] | _ -> raise MatitaTypes.Cancel)