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/
30 open MatitaGeneratedGui
34 exception Found of int
36 let gui_instance = ref None
38 class type browserWin =
39 (* this class exists only because GEdit.combo_box_entry is not supported by
40 * lablgladecc :-(((( *)
42 inherit MatitaGeneratedGui.browserWin
43 method browserUri: GEdit.combo_box_entry
46 class console ~(buffer: GText.buffer) () =
48 val error_tag = buffer#create_tag [ `FOREGROUND "red" ]
49 val warning_tag = buffer#create_tag [ `FOREGROUND "orange" ]
50 val message_tag = buffer#create_tag []
51 val debug_tag = buffer#create_tag [ `FOREGROUND "#888888" ]
52 method message s = buffer#insert ~iter:buffer#end_iter ~tags:[message_tag] s
53 method error s = buffer#insert ~iter:buffer#end_iter ~tags:[error_tag] s
54 method warning s = buffer#insert ~iter:buffer#end_iter ~tags:[warning_tag] s
55 method debug s = buffer#insert ~iter:buffer#end_iter ~tags:[debug_tag] s
57 buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter
58 method log_callback (tag: HLog.log_tag) s =
60 | `Debug -> self#debug (s ^ "\n")
61 | `Error -> self#error (s ^ "\n")
62 | `Message -> self#message (s ^ "\n")
63 | `Warning -> self#warning (s ^ "\n")
66 let clean_current_baseuri grafite_status =
68 let baseuri = GrafiteTypes.get_string_option grafite_status "baseuri" in
69 LibraryClean.clean_baseuris [baseuri]
70 with GrafiteTypes.Option_error _ -> ()
72 let ask_and_save_moo_if_needed parent fname lexicon_status grafite_status =
74 try Some (GrafiteTypes.get_string_option grafite_status "baseuri")
75 with GrafiteTypes.Option_error _ -> None
77 if (MatitaScript.current ())#eos &&
78 grafite_status.GrafiteTypes.proof_status = GrafiteTypes.No_proof &&
82 let baseuri = match baseuri with Some b -> b | None -> assert false in
84 LibraryMisc.obj_file_of_baseuri ~must_exist:false ~baseuri
88 LibraryMisc.metadata_file_of_baseuri
89 ~must_exist:false ~baseuri ~writable:true in
91 LibraryMisc.lexicon_file_of_baseuri
92 ~must_exist:false ~baseuri ~writable:true
94 GrafiteMarshal.save_moo moo_fname
95 grafite_status.GrafiteTypes.moo_content_rev;
96 LibraryNoDb.save_metadata metadata_fname
97 lexicon_status.LexiconEngine.metadata;
98 LexiconMarshal.save_lexicon lexicon_fname
99 lexicon_status.LexiconEngine.lexicon_content_rev
103 MatitaGtkMisc.ask_confirmation
104 ~title:"A .moo can be generated"
105 ~message:(Printf.sprintf
106 "%s can be generated for %s.\n<i>Should I generate it?</i>"
107 (Filename.basename moo_fname) (Filename.basename fname))
114 | `CANCEL -> raise MatitaTypes.Cancel
119 clean_current_baseuri grafite_status
123 clean_current_baseuri grafite_status
125 let ask_unsaved parent =
126 MatitaGtkMisc.ask_confirmation
127 ~parent ~title:"Unsaved work!"
128 ~message:("Your work is <b>unsaved</b>!\n\n"^
129 "<i>Do you want to save the script before continuing?</i>")
132 (** Selection handling
133 * Two clipboards are used: "clipboard" and "primary".
134 * "primary" is used by X, when you hit the middle button mouse is content is
135 * pasted between applications. In Matita this selection always contain the
136 * textual version of the selected term.
137 * "clipboard" is used inside Matita only and support ATM two different targets:
138 * "TERM" and "PATTERN", in the future other targets like "MATHMLCONTENT" may
143 (* creation order _is_ relevant for windows placement *)
144 let main = new mainWin () in
145 let fileSel = new fileSelectionWin () in
146 let findRepl = new findReplWin () in
147 let develList = new develListWin () in
148 let newDevel = new newDevelWin () in
149 let keyBindingBoxes = (* event boxes which should receive global key events *)
150 [ main#mainWinEventBox ]
152 let console = new console ~buffer:main#logTextView#buffer () in
153 let (source_view: GSourceView.source_view) =
154 GSourceView.source_view
156 ~insert_spaces_instead_of_tabs:true ~tabs_width:2
157 ~margin:80 ~show_margin:true
159 ~packing:main#scriptScrolledWin#add
162 let default_font_size =
163 Helm_registry.get_opt_default Helm_registry.int
164 ~default:BuildTimeConf.default_font_size "matita.font_size"
166 let source_buffer = source_view#source_buffer in
168 val mutable chosen_file = None
169 val mutable _ok_not_exists = false
170 val mutable _only_directory = false
171 val mutable script_fname = None
172 val mutable font_size = default_font_size
173 val mutable next_devel_must_contain = None
174 val mutable next_ligatures = []
175 val clipboard = GData.clipboard Gdk.Atom.clipboard
176 val primary = GData.clipboard Gdk.Atom.primary
179 (* glade's check widgets *)
180 List.iter (fun w -> w#check_widgets ())
181 (let c w = (w :> <check_widgets: unit -> unit>) in
182 [ c fileSel; c main; c findRepl]);
184 List.iter (* global key bindings *)
185 (fun (key, callback) -> self#addKeyBinding key callback)
188 toggle_win ~check:main#showProofMenuItem proof#proofWin;
190 toggle_win ~check:main#showCheckMenuItem check#checkWin;
194 let parse_txt_file file =
195 let ch = open_in (BuildTimeConf.runtime_base_dir ^ "/" ^ file) in
196 let l_rev = ref [] in
199 l_rev := input_line ch :: !l_rev;
208 ~authors:(parse_txt_file "AUTHORS")
209 (*~comments:"comments"*)
210 ~copyright:"Copyright (C) 2005, the HELM team"
211 ~license:(String.concat "\n" (parse_txt_file "LICENSE"))
212 ~logo:(GdkPixbuf.from_file (MatitaMisc.image_path "/matita_medium.png"))
214 ~version:BuildTimeConf.version
215 ~website:"http://helm.cs.unibo.it"
218 connect_menu_item main#contentsMenuItem (fun () ->
220 sprintf "gnome-help ghelp://%s/C/matita.xml &" BuildTimeConf.help_dir
222 ignore (Sys.command cmd));
223 connect_menu_item main#aboutMenuItem about_dialog#present;
225 let show_find_Repl () =
226 findRepl#toplevel#misc#show ();
227 findRepl#toplevel#misc#grab_focus ()
229 let hide_find_Repl () = findRepl#toplevel#misc#hide () in
231 let highlight start end_ =
232 source_buffer#move_mark `INSERT ~where:start;
233 source_buffer#move_mark `SEL_BOUND ~where:end_;
234 source_view#scroll_mark_onscreen `INSERT
236 let text = findRepl#findEntry#text in
237 let iter = source_buffer#get_iter `SEL_BOUND in
238 match iter#forward_search text with
240 (match source_buffer#start_iter#forward_search text with
242 | Some (start,end_) -> highlight start end_)
243 | Some (start,end_) -> highlight start end_
246 let text = findRepl#replaceEntry#text in
247 let ins = source_buffer#get_iter `INSERT in
248 let sel = source_buffer#get_iter `SEL_BOUND in
249 if ins#compare sel < 0 then
251 ignore(source_buffer#delete_selection ());
252 source_buffer#insert text
255 connect_button findRepl#findButton find_forward;
256 connect_button findRepl#findReplButton replace;
257 connect_button findRepl#cancelButton (fun _ -> hide_find_Repl ());
258 ignore(findRepl#toplevel#event#connect#delete
259 ~callback:(fun _ -> hide_find_Repl ();true));
262 (* phase 1: we save the actual status of the marks and we undo *)
263 let locked_mark = `MARK ((MatitaScript.current ())#locked_mark) in
264 let locked_iter = source_view#buffer#get_iter_at_mark locked_mark in
265 let locked_iter_offset = locked_iter#offset in
268 (source_view#buffer#create_mark ~name:"lock_point"
269 ~left_gravity:true locked_iter) in
270 source_view#source_buffer#undo ();
271 (* phase 2: we save the cursor position and we redo, restoring
272 the previous status of all the marks *)
273 let cursor_iter = source_view#buffer#get_iter_at_mark `INSERT in
276 (source_view#buffer#create_mark ~name:"undo_point"
277 ~left_gravity:true cursor_iter)
279 source_view#source_buffer#redo ();
280 let mark_iter = source_view#buffer#get_iter_at_mark mark in
281 let mark2_iter = source_view#buffer#get_iter_at_mark mark2 in
282 let mark2_iter = mark2_iter#set_offset locked_iter_offset in
283 source_view#buffer#move_mark locked_mark ~where:mark2_iter;
284 source_view#buffer#delete_mark mark;
285 source_view#buffer#delete_mark mark2;
286 (* phase 3: if after the undo the cursor was in the locked area,
287 then we move it there again and we perform a goto *)
288 if mark_iter#offset < locked_iter_offset then
290 source_view#buffer#move_mark `INSERT ~where:mark_iter;
291 (MatitaScript.current ())#goto `Cursor ();
293 (* phase 4: we perform again the undo. This time we are sure that
294 the text to undo is not locked *)
295 source_view#source_buffer#undo ();
296 source_view#misc#grab_focus () in
299 (* phase 1: we save the actual status of the marks, we redo and
301 let locked_mark = `MARK ((MatitaScript.current ())#locked_mark) in
302 let locked_iter = source_view#buffer#get_iter_at_mark locked_mark in
303 let locked_iter_offset = locked_iter#offset in
306 (source_view#buffer#create_mark ~name:"lock_point"
307 ~left_gravity:true locked_iter) in
308 source_view#source_buffer#redo ();
309 source_view#source_buffer#undo ();
310 (* phase 2: we save the cursor position and we restore
311 the previous status of all the marks *)
312 let cursor_iter = source_view#buffer#get_iter_at_mark `INSERT in
315 (source_view#buffer#create_mark ~name:"undo_point"
316 ~left_gravity:true cursor_iter)
318 let mark_iter = source_view#buffer#get_iter_at_mark mark in
319 let mark2_iter = source_view#buffer#get_iter_at_mark mark2 in
320 let mark2_iter = mark2_iter#set_offset locked_iter_offset in
321 source_view#buffer#move_mark locked_mark ~where:mark2_iter;
322 source_view#buffer#delete_mark mark;
323 source_view#buffer#delete_mark mark2;
324 (* phase 3: if after the undo the cursor is in the locked area,
325 then we move it there again and we perform a goto *)
326 if mark_iter#offset < locked_iter_offset then
328 source_view#buffer#move_mark `INSERT ~where:mark_iter;
329 (MatitaScript.current ())#goto `Cursor ();
331 (* phase 4: we perform again the redo. This time we are sure that
332 the text to redo is not locked *)
333 source_view#source_buffer#redo ();
334 source_view#misc#grab_focus ()
336 connect_menu_item main#undoMenuItem safe_undo;
337 ignore(source_view#source_buffer#connect#can_undo
338 ~callback:main#undoMenuItem#misc#set_sensitive);
339 connect_menu_item main#redoMenuItem safe_redo;
340 ignore(source_view#source_buffer#connect#can_redo
341 ~callback:main#redoMenuItem#misc#set_sensitive);
342 ignore(source_view#connect#after#populate_popup
343 ~callback:(fun pre_menu ->
344 let menu = new GMenu.menu pre_menu in
345 let menuItems = menu#children in
346 let undoMenuItem, redoMenuItem =
348 [undo;redo;sep1;cut;copy;paste;delete;sep2;
349 selectall;sep3;inputmethod;insertunicodecharacter] ->
350 List.iter menu#remove [ copy; cut; delete; paste ];
352 | _ -> assert false in
354 let i = ref 2 in (* last occupied position *)
355 fun ?label ?stock () ->
357 GMenu.image_menu_item ?label ?stock ~packing:(menu#insert ~pos:!i)
360 let copy = add_menu_item ~stock:`COPY () in
361 let cut = add_menu_item ~stock:`CUT () in
362 let delete = add_menu_item ~stock:`DELETE () in
363 let paste = add_menu_item ~stock:`PASTE () in
364 let paste_pattern = add_menu_item ~label:"Paste as pattern" () in
365 copy#misc#set_sensitive self#canCopy;
366 cut#misc#set_sensitive self#canCut;
367 delete#misc#set_sensitive self#canDelete;
368 paste#misc#set_sensitive self#canPaste;
369 paste_pattern#misc#set_sensitive self#canPastePattern;
370 connect_menu_item copy self#copy;
371 connect_menu_item cut self#cut;
372 connect_menu_item delete self#delete;
373 connect_menu_item paste self#paste;
374 connect_menu_item paste_pattern self#pastePattern;
375 let new_undoMenuItem =
376 GMenu.image_menu_item
377 ~image:(GMisc.image ~stock:`UNDO ())
380 ~packing:(menu#insert ~pos:0) () in
381 new_undoMenuItem#misc#set_sensitive
382 (undoMenuItem#misc#get_flag `SENSITIVE);
383 menu#remove (undoMenuItem :> GMenu.menu_item);
384 connect_menu_item new_undoMenuItem safe_undo;
385 let new_redoMenuItem =
386 GMenu.image_menu_item
387 ~image:(GMisc.image ~stock:`REDO ())
390 ~packing:(menu#insert ~pos:1) () in
391 new_redoMenuItem#misc#set_sensitive
392 (redoMenuItem#misc#get_flag `SENSITIVE);
393 menu#remove (redoMenuItem :> GMenu.menu_item);
394 connect_menu_item new_redoMenuItem safe_redo));
396 connect_menu_item main#editMenu (fun () ->
397 main#copyMenuItem#misc#set_sensitive self#canCopy;
398 main#cutMenuItem#misc#set_sensitive self#canCut;
399 main#deleteMenuItem#misc#set_sensitive self#canDelete;
400 main#pasteMenuItem#misc#set_sensitive self#canPaste;
401 main#pastePatternMenuItem#misc#set_sensitive self#canPastePattern);
402 connect_menu_item main#copyMenuItem self#copy;
403 connect_menu_item main#cutMenuItem self#cut;
404 connect_menu_item main#deleteMenuItem self#delete;
405 connect_menu_item main#pasteMenuItem self#paste;
406 connect_menu_item main#pastePatternMenuItem self#pastePattern;
407 connect_menu_item main#selectAllMenuItem (fun () ->
408 source_buffer#move_mark `INSERT source_buffer#start_iter;
409 source_buffer#move_mark `SEL_BOUND source_buffer#end_iter);
410 connect_menu_item main#findReplMenuItem show_find_Repl;
411 connect_menu_item main#externalEditorMenuItem self#externalEditor;
412 connect_menu_item main#ligatureButton self#nextLigature;
413 ignore (findRepl#findEntry#connect#activate find_forward);
414 (* interface lockers *)
416 main#buttonsToolbar#misc#set_sensitive false;
417 develList#buttonsHbox#misc#set_sensitive false;
418 source_view#set_editable false
421 main#buttonsToolbar#misc#set_sensitive true;
422 develList#buttonsHbox#misc#set_sensitive true;
423 source_view#set_editable true
429 try f ();unlock_world () with exc -> unlock_world (); raise exc
431 ignore (Thread.create thread_main ()) in
435 f (); source_view#misc#grab_focus ()
437 exc -> source_view#misc#grab_focus (); raise exc in
438 (* developments win *)
440 new MatitaGtkMisc.multiStringListModel
441 ~cols:2 develList#developmentsTreeview
443 let refresh_devels_win () =
444 model#list_store#clear ();
446 (fun (name, root) -> model#easy_mappend [name;root])
447 (MatitamakeLib.list_known_developments ())
449 let get_devel_selected () =
450 match model#easy_mselection () with
451 | [[name;_]] -> MatitamakeLib.development_for_name name
455 while Glib.Main.pending () do
456 ignore(Glib.Main.iteration false);
459 connect_button develList#newButton
461 next_devel_must_contain <- None;
462 newDevel#toplevel#misc#show());
463 connect_button develList#deleteButton
465 (match get_devel_selected () with
467 | Some d -> MatitamakeLib.destroy_development_in_bg refresh d);
468 refresh_devels_win ()));
469 connect_button develList#buildButton
471 match get_devel_selected () with
475 (fun () -> MatitamakeLib.build_development_in_bg refresh d)
478 connect_button develList#cleanButton
480 match get_devel_selected () with
484 (fun () -> MatitamakeLib.clean_development_in_bg refresh d)
487 connect_button develList#publishButton
489 match get_devel_selected () with
492 let publish = locker (fun () ->
493 MatitamakeLib.publish_development_in_bg refresh d) in
494 ignore(publish ())));
495 connect_button develList#graphButton (fun () ->
496 match get_devel_selected () with
499 (match MatitamakeLib.dot_for_development d with
502 let browser = MatitaMathView.cicBrowser () in
503 browser#load (`Development
504 (MatitamakeLib.name_for_development d))));
505 connect_button develList#closeButton
506 (fun () -> develList#toplevel#misc#hide());
507 ignore(develList#toplevel#event#connect#delete
508 (fun _ -> develList#toplevel#misc#hide();true));
509 connect_menu_item main#developmentsMenuItem
510 (fun () -> refresh_devels_win ();develList#toplevel#misc#show ());
512 (* add development win *)
513 let check_if_root_contains root =
514 match next_devel_must_contain with
517 let is_prefix_of d1 d2 =
518 let len1 = String.length d1 in
519 let len2 = String.length d2 in
523 let pref = String.sub d2 0 len1 in
526 is_prefix_of root path
528 connect_button newDevel#addButton
530 let name = newDevel#nameEntry#text in
531 let root = newDevel#rootEntry#text in
532 if check_if_root_contains root then
534 ignore (MatitamakeLib.initialize_development name root);
535 refresh_devels_win ();
536 newDevel#nameEntry#set_text "";
537 newDevel#rootEntry#set_text "";
538 newDevel#toplevel#misc#hide()
541 HLog.error ("The selected root does not contain " ^
542 match next_devel_must_contain with
544 | _ -> assert false));
545 connect_button newDevel#chooseRootButton
547 let path = self#chooseDir () in
549 | Some path -> newDevel#rootEntry#set_text path
551 connect_button newDevel#cancelButton
552 (fun () -> newDevel#toplevel#misc#hide ());
553 ignore(newDevel#toplevel#event#connect#delete
554 (fun _ -> newDevel#toplevel#misc#hide();true));
556 (* file selection win *)
557 ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true));
558 ignore (fileSel#fileSelectionWin#connect#response (fun event ->
561 fileSel#fileSelectionWin#misc#hide ();
566 let fname = fileSel#fileSelectionWin#filename in
567 if Sys.file_exists fname then
569 if HExtlib.is_regular fname && not (_only_directory) then
571 else if _only_directory && HExtlib.is_dir fname then
576 if _ok_not_exists then
579 | `CANCEL -> return None
581 | `DELETE_EVENT -> return None));
583 List.iter (fun w -> w#misc#set_sensitive false) [ main#saveMenuItem ];
585 let adj = main#logScrolledWin#vadjustment in
586 ignore (adj#connect#changed
587 (fun _ -> adj#set_value (adj#upper -. adj#page_size)));
588 console#message (sprintf "\tMatita version %s\n" BuildTimeConf.version);
590 let module A = GrafiteAst in
591 let hole = CicNotationPt.UserInput in
592 let loc = HExtlib.dummy_floc in
594 if (MatitaScript.current ())#onGoingProof () then
595 (MatitaScript.current ())#advance
597 ^ GrafiteAstPp.pp_tactical ~term_pp:CicNotationPp.pp_term
598 ~lazy_term_pp:CicNotationPp.pp_term (A.Tactic (loc, ast)))
601 let tac_w_term ast _ =
602 if (MatitaScript.current ())#onGoingProof () then
603 let buf = source_buffer in
604 buf#insert ~iter:(buf#get_iter_at_mark (`NAME "locked"))
606 ^ GrafiteAstPp.pp_tactic ~term_pp:CicNotationPp.pp_term
607 ~lazy_term_pp:CicNotationPp.pp_term ast)
610 connect_button tbar#introsButton (tac (A.Intros (loc, None, [])));
611 connect_button tbar#applyButton (tac_w_term (A.Apply (loc, hole)));
612 connect_button tbar#exactButton (tac_w_term (A.Exact (loc, hole)));
613 connect_button tbar#elimButton (tac_w_term
614 (A.Elim (loc, hole, None, None, [])));
615 connect_button tbar#elimTypeButton (tac_w_term
616 (A.ElimType (loc, hole, None, None, [])));
617 connect_button tbar#splitButton (tac (A.Split loc));
618 connect_button tbar#leftButton (tac (A.Left loc));
619 connect_button tbar#rightButton (tac (A.Right loc));
620 connect_button tbar#existsButton (tac (A.Exists loc));
621 connect_button tbar#reflexivityButton (tac (A.Reflexivity loc));
622 connect_button tbar#symmetryButton (tac (A.Symmetry loc));
623 connect_button tbar#transitivityButton
624 (tac_w_term (A.Transitivity (loc, hole)));
625 connect_button tbar#assumptionButton (tac (A.Assumption loc));
626 connect_button tbar#cutButton (tac_w_term (A.Cut (loc, None, hole)));
627 connect_button tbar#autoButton (tac (A.Auto (loc,[])));
628 MatitaGtkMisc.toggle_widget_visibility
629 ~widget:(main#tacticsButtonsHandlebox :> GObj.widget)
630 ~check:main#tacticsBarMenuItem;
631 let module Hr = Helm_registry in
633 not (Hr.get_opt_default Hr.bool ~default:false "matita.tactics_bar")
635 main#tacticsBarMenuItem#set_active false;
636 MatitaGtkMisc.toggle_callback
638 | true -> main#toplevel#fullscreen ()
639 | false -> main#toplevel#unfullscreen ())
640 ~check:main#fullscreenMenuItem;
641 main#fullscreenMenuItem#set_active false;
643 HLog.set_log_callback self#console#log_callback;
644 GtkSignal.user_handler :=
646 | MatitaScript.ActionCancelled s -> HLog.error s
648 if not (Helm_registry.get_bool "matita.debug") then
649 let floc, msg = MatitaExcPp.to_string exn in
654 let (x, y) = HExtlib.loc_of_floc floc in
655 let script = MatitaScript.current () in
656 let locked_mark = script#locked_mark in
657 let error_tag = script#error_tag in
659 (source_buffer#get_iter_at_mark (`MARK locked_mark))#offset in
660 let x' = baseoffset + x in
661 let y' = baseoffset + y in
662 let x_iter = source_buffer#get_iter (`OFFSET x') in
663 let y_iter = source_buffer#get_iter (`OFFSET y') in
664 source_buffer#apply_tag error_tag ~start:x_iter ~stop:y_iter;
666 id := Some (source_buffer#connect#changed ~callback:(fun () ->
667 source_buffer#remove_tag error_tag
668 ~start:source_buffer#start_iter
669 ~stop:source_buffer#end_iter;
671 | None -> assert false (* a race condition occurred *)
673 (new GObj.gobject_ops source_buffer#as_buffer)#disconnect id));
674 source_buffer#place_cursor
675 (source_buffer#get_iter (`OFFSET x'));
680 ignore (source_buffer#connect#mark_set (fun _ _ -> next_ligatures <- []));
682 match GSourceView.source_language_from_file BuildTimeConf.lang_file with
684 HLog.warn (sprintf "can't load language file %s"
685 BuildTimeConf.lang_file)
686 | Some matita_lang ->
687 source_buffer#set_language matita_lang;
688 source_buffer#set_highlight true
690 let s () = MatitaScript.current () in
692 script_fname <- None;
693 main#saveMenuItem#misc#set_sensitive false
695 let saveAsScript () =
697 match self#chooseFile ~ok_not_exists:true () with
699 script#assignFileName f;
700 script#saveToFile ();
701 console#message ("'"^f^"' saved.\n");
706 match script_fname with
707 | None -> saveAsScript ()
709 (s ())#assignFileName f;
710 (s ())#saveToFile ();
711 console#message ("'"^f^"' saved.\n");
713 let abandon_script () =
714 let lexicon_status = (s ())#lexicon_status in
715 let grafite_status = (s ())#grafite_status in
716 if source_view#buffer#modified then
717 (match ask_unsaved main#toplevel with
718 | `YES -> saveScript ()
720 | `CANCEL -> raise MatitaTypes.Cancel);
721 (match script_fname with
724 ask_and_save_moo_if_needed main#toplevel fname
725 lexicon_status grafite_status);
730 match self#chooseFile () with
734 script#assignFileName f;
735 source_view#source_buffer#begin_not_undoable_action ();
736 script#loadFromFile f;
737 source_view#source_buffer#end_not_undoable_action ();
738 console#message ("'"^f^"' loaded.\n");
741 with MatitaTypes.Cancel -> ()
745 source_view#source_buffer#begin_not_undoable_action ();
748 source_view#source_buffer#end_not_undoable_action ();
753 source_buffer#place_cursor
754 (source_buffer#get_iter_at_mark (`NAME "locked")) in
755 let advance _ = (MatitaScript.current ())#advance (); cursor () in
756 let retract _ = (MatitaScript.current ())#retract (); cursor () in
757 let top _ = (MatitaScript.current ())#goto `Top (); cursor () in
758 let bottom _ = (MatitaScript.current ())#goto `Bottom (); cursor () in
759 let jump _ = (MatitaScript.current ())#goto `Cursor (); cursor () in
760 let advance = locker (keep_focus advance) in
761 let retract = locker (keep_focus retract) in
762 let top = locker (keep_focus top) in
763 let bottom = locker (keep_focus bottom) in
764 let jump = locker (keep_focus jump) in
766 self#setQuitCallback (fun () ->
767 let lexicon_status = (MatitaScript.current ())#lexicon_status in
768 let grafite_status = (MatitaScript.current ())#grafite_status in
769 if source_view#buffer#modified then
771 let rc = ask_unsaved main#toplevel in
774 | `YES -> saveScript ();
775 if not source_view#buffer#modified then
777 (match script_fname with
780 ask_and_save_moo_if_needed main#toplevel
781 fname lexicon_status grafite_status);
784 | `NO -> GMain.Main.quit ()
785 | `CANCEL -> raise MatitaTypes.Cancel
786 with MatitaTypes.Cancel -> ()
790 (match script_fname with
791 | None -> clean_current_baseuri grafite_status; GMain.Main.quit ()
794 ask_and_save_moo_if_needed main#toplevel fname lexicon_status
797 with MatitaTypes.Cancel -> ())
799 connect_button main#scriptAdvanceButton advance;
800 connect_button main#scriptRetractButton retract;
801 connect_button main#scriptTopButton top;
802 connect_button main#scriptBottomButton bottom;
803 connect_button main#scriptJumpButton jump;
804 connect_menu_item main#scriptAdvanceMenuItem advance;
805 connect_menu_item main#scriptRetractMenuItem retract;
806 connect_menu_item main#scriptTopMenuItem top;
807 connect_menu_item main#scriptBottomMenuItem bottom;
808 connect_menu_item main#scriptJumpMenuItem jump;
809 connect_menu_item main#openMenuItem loadScript;
810 connect_menu_item main#saveMenuItem saveScript;
811 connect_menu_item main#saveAsMenuItem saveAsScript;
812 connect_menu_item main#newMenuItem newScript;
813 (* script monospace font stuff *)
814 self#updateFontSize ();
816 main#debugMenu#misc#hide ();
818 main#hintLowImage#set_file (image_path "matita-bulb-low.png");
819 main#hintMediumImage#set_file (image_path "matita-bulb-medium.png");
820 main#hintHighImage#set_file (image_path "matita-bulb-high.png");
822 self#sourceView#misc#grab_focus ();
823 (* main win dimension *)
824 let width = Gdk.Screen.width () in
825 let height = Gdk.Screen.height () in
826 let main_w = width * 90 / 100 in
827 let main_h = height * 80 / 100 in
828 let script_w = main_w * 6 / 10 in
829 main#toplevel#resize ~width:main_w ~height:main_h;
830 main#hpaneScriptSequent#set_position script_w;
832 ignore(source_view#connect#after#paste_clipboard
833 ~callback:(fun () -> (MatitaScript.current ())#clean_dirty_lock));
834 (* clean_locked is set to true only "during" a PRIMARY paste
835 operation (i.e. by clicking with the second mouse button) *)
836 let clean_locked = ref false in
837 ignore(source_view#event#connect#button_press
840 if GdkEvent.Button.button button = 2 then
841 clean_locked := true;
844 ignore(source_view#event#connect#button_release
845 ~callback:(fun button -> clean_locked := false; false));
846 ignore(source_view#buffer#connect#after#apply_tag
848 fun tag ~start:_ ~stop:_ ->
850 tag#get_oid = (MatitaScript.current ())#locked_tag#get_oid
853 clean_locked := false;
854 (MatitaScript.current ())#clean_dirty_lock;
857 (* math view handling *)
858 connect_menu_item main#newCicBrowserMenuItem (fun () ->
859 ignore (MatitaMathView.cicBrowser ()));
860 connect_menu_item main#increaseFontSizeMenuItem (fun () ->
861 self#increaseFontSize ();
862 MatitaMathView.increase_font_size ();
863 MatitaMathView.update_font_sizes ());
864 connect_menu_item main#decreaseFontSizeMenuItem (fun () ->
865 self#decreaseFontSize ();
866 MatitaMathView.decrease_font_size ();
867 MatitaMathView.update_font_sizes ());
868 connect_menu_item main#normalFontSizeMenuItem (fun () ->
869 self#resetFontSize ();
870 MatitaMathView.reset_font_size ();
871 MatitaMathView.update_font_sizes ());
872 MatitaMathView.reset_font_size ();
874 (** selections / clipboards handling *)
876 method markupSelected = MatitaMathView.has_selection ()
877 method private textSelected =
878 (source_buffer#get_iter_at_mark `INSERT)#compare
879 (source_buffer#get_iter_at_mark `SEL_BOUND) <> 0
880 method private somethingSelected = self#markupSelected || self#textSelected
881 method private markupStored = MatitaMathView.has_clipboard ()
882 method private textStored = clipboard#text <> None
883 method private somethingStored = self#markupStored || self#textStored
885 method canCopy = self#somethingSelected
886 method canCut = self#textSelected
887 method canDelete = self#textSelected
888 method canPaste = self#somethingStored
889 method canPastePattern = self#markupStored
894 MatitaMathView.empty_clipboard ();
895 source_view#buffer#copy_clipboard clipboard;
897 MatitaMathView.copy_selection ()
899 source_view#buffer#cut_clipboard clipboard;
900 MatitaMathView.empty_clipboard ()
901 method delete () = ignore (source_view#buffer#delete_selection ())
903 if MatitaMathView.has_clipboard ()
904 then source_view#buffer#insert (MatitaMathView.paste_clipboard `Term)
905 else source_view#buffer#paste_clipboard clipboard;
906 (MatitaScript.current ())#clean_dirty_lock
907 method pastePattern () =
908 source_view#buffer#insert (MatitaMathView.paste_clipboard `Pattern)
910 method private nextLigature () =
911 let iter = source_buffer#get_iter_at_mark `INSERT in
912 let write_ligature len s =
913 assert(Glib.Utf8.validate s);
914 source_buffer#delete ~start:iter ~stop:(iter#copy#backward_chars len);
915 source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT) s
917 let get_ligature word =
918 let len = String.length word in
921 for i = len - 1 downto 0 do
922 if HExtlib.is_alpha word.[i] then ()
924 (if word.[i] = '\\' then raise (Found i) else raise (Found ~-1))
928 if i = ~-1 then None else Some (String.sub word i (len - i))
930 let aux_ligature () =
932 for i = len - 1 downto 0 do
933 if CicNotationLexer.is_ligature_char word.[i] then ()
934 else raise (Found (i+1))
940 Some (String.sub word i (len - i))
941 with Invalid_argument _ -> None)
943 match aux_tex () with
944 | Some macro -> macro
945 | None -> (match aux_ligature () with Some l -> l | None -> word)
947 (match next_ligatures with
948 | [] -> (* find ligatures and fill next_ligatures, then try again *)
951 ~stop:(iter#copy#backward_find_char Glib.Unichar.isspace)
953 let ligature = get_ligature last_word in
954 (match CicNotationLexer.lookup_ligatures ligature with
957 write_ligature (MatitaGtkMisc.utf8_string_length ligature) hd;
958 next_ligatures <- tl @ [ hd ])
961 next_ligatures <- tl @ [ hd ])
963 method private externalEditor () =
964 let cmd = Helm_registry.get "matita.external_editor" in
965 (* ZACK uncomment to enable interactive ask of external editor command *)
968 "External editor command:
969 %f will be substitute for the script name,
970 %p for the cursor position in bytes,
971 %l for the execution point in bytes."
973 ask_text ~gui:self ~title:"External editor" ~msg ~multiline:false
974 ~default:(Helm_registry.get "matita.external_editor") ()
976 let fname = (MatitaScript.current ())#filename in
978 source_buffer#start_iter#get_slice
979 ~stop:(source_buffer#get_iter_at_mark mark)
981 let script = MatitaScript.current () in
982 let locked = `MARK script#locked_mark in
983 let string_pos mark = string_of_int (String.length (slice mark)) in
984 let cursor_pos = string_pos `INSERT in
985 let locked_pos = string_pos locked in
987 Pcre.replace ~pat:"%f" ~templ:fname
988 (Pcre.replace ~pat:"%p" ~templ:cursor_pos
989 (Pcre.replace ~pat:"%l" ~templ:locked_pos
992 let locked_before = slice locked in
993 let locked_offset = (source_buffer#get_iter_at_mark locked)#offset in
994 ignore (Unix.system cmd);
995 source_buffer#set_text (HExtlib.input_file fname);
996 let locked_iter = source_buffer#get_iter (`OFFSET locked_offset) in
997 source_buffer#move_mark locked locked_iter;
998 source_buffer#apply_tag script#locked_tag
999 ~start:source_buffer#start_iter ~stop:locked_iter;
1000 let locked_after = slice locked in
1004 for i = 0 to String.length locked_before - 1 do
1005 if locked_before.[i] <> locked_after.[i] then begin
1006 source_buffer#place_cursor
1007 ~where:(source_buffer#get_iter (`LINEBYTE (!line, !col)));
1008 script#goto `Cursor ();
1010 end else if locked_before.[i] = '\n' then begin
1017 | Invalid_argument _ -> script#goto `Bottom ()
1019 method loadScript file =
1020 let script = MatitaScript.current () in
1022 if Pcre.pmatch ~pat:"\\.p$" file then
1025 Helm_registry.get_opt_default Helm_registry.string ~default:"./"
1028 let data = Matitaprover.p_to_ma ~filename:file ~tptppath () in
1029 let filename = Pcre.replace ~pat:"\\.p$" ~templ:".ma" file in
1030 script#assignFileName filename;
1031 source_view#source_buffer#begin_not_undoable_action ();
1032 script#loadFromString data;
1033 source_view#source_buffer#end_not_undoable_action ();
1034 console#message ("'"^filename^"' loaded.");
1035 self#_enableSaveTo filename
1039 script#assignFileName file;
1041 if Sys.file_exists file then file
1042 else BuildTimeConf.script_template
1044 source_view#source_buffer#begin_not_undoable_action ();
1045 script#loadFromFile content;
1046 source_view#source_buffer#end_not_undoable_action ();
1047 console#message ("'"^file^"' loaded.");
1048 self#_enableSaveTo file
1051 method setStar name b =
1052 let l = main#scriptLabel in
1054 l#set_text (name ^ " *")
1058 method private _enableSaveTo file =
1059 script_fname <- Some file;
1060 self#main#saveMenuItem#misc#set_sensitive true
1062 method console = console
1063 method sourceView: GSourceView.source_view =
1064 (source_view: GSourceView.source_view)
1065 method fileSel = fileSel
1066 method findRepl = findRepl
1068 method develList = develList
1069 method newDevel = newDevel
1071 method newBrowserWin () =
1073 inherit browserWin ()
1074 val combo = GEdit.combo_box_entry ()
1076 self#check_widgets ();
1077 let combo_widget = combo#coerce in
1078 uriHBox#pack ~from:`END ~fill:true ~expand:true combo_widget;
1079 combo#entry#misc#grab_focus ()
1080 method browserUri = combo
1083 method newUriDialog () =
1084 let dialog = new uriChoiceDialog () in
1085 dialog#check_widgets ();
1088 method newRecordDialog () =
1089 let dialog = new recordChoiceDialog () in
1090 dialog#check_widgets ();
1093 method newConfirmationDialog () =
1094 let dialog = new confirmationDialog () in
1095 dialog#check_widgets ();
1098 method newEmptyDialog () =
1099 let dialog = new emptyDialog () in
1100 dialog#check_widgets ();
1103 method private addKeyBinding key callback =
1104 List.iter (fun evbox -> add_key_binding key callback evbox)
1107 method setQuitCallback callback =
1108 connect_menu_item main#quitMenuItem callback;
1109 ignore (main#toplevel#event#connect#delete
1110 (fun _ -> callback ();true));
1111 self#addKeyBinding GdkKeysyms._q callback
1113 method chooseFile ?(ok_not_exists = false) () =
1114 _ok_not_exists <- ok_not_exists;
1115 _only_directory <- false;
1116 fileSel#fileSelectionWin#show ();
1120 method private chooseDir ?(ok_not_exists = false) () =
1121 _ok_not_exists <- ok_not_exists;
1122 _only_directory <- true;
1123 fileSel#fileSelectionWin#show ();
1125 (* we should check that this is a directory *)
1128 method createDevelopment ~containing =
1129 next_devel_must_contain <- containing;
1130 newDevel#toplevel#misc#show()
1132 method askText ?(title = "") ?(msg = "") () =
1133 let dialog = new textDialog () in
1134 dialog#textDialog#set_title title;
1135 dialog#textDialogLabel#set_label msg;
1136 let text = ref None in
1139 dialog#textDialog#destroy ();
1142 ignore (dialog#textDialog#event#connect#delete (fun _ -> true));
1143 connect_button dialog#textDialogCancelButton (fun _ -> return None);
1144 connect_button dialog#textDialogOkButton (fun _ ->
1145 let text = dialog#textDialogTextView#buffer#get_text () in
1146 return (Some text));
1147 dialog#textDialog#show ();
1151 method private updateFontSize () =
1152 self#sourceView#misc#modify_font_by_name
1153 (sprintf "%s %d" BuildTimeConf.script_font font_size)
1155 method increaseFontSize () =
1156 font_size <- font_size + 1;
1157 self#updateFontSize ()
1159 method decreaseFontSize () =
1160 font_size <- font_size - 1;
1161 self#updateFontSize ()
1163 method resetFontSize () =
1164 font_size <- default_font_size;
1165 self#updateFontSize ()
1170 let g = new gui () in
1171 gui_instance := Some g;
1172 MatitaMathView.set_gui g;
1175 let instance = singleton gui
1177 let non p x = not (p x)
1179 (* this is a shit and should be changed :-{ *)
1180 let interactive_uri_choice
1181 ?(selection_mode:[`SINGLE|`MULTIPLE] = `MULTIPLE) ?(title = "")
1182 ?(msg = "") ?(nonvars_button = false) ?(hide_uri_entry=false)
1183 ?(hide_try=false) ?(ok_label="_Auto") ?(ok_action:[`SELECT|`AUTO] = `AUTO)
1187 let gui = instance () in
1188 let nonvars_uris = lazy (List.filter (non UriManager.uri_is_var) uris) in
1189 if (selection_mode <> `SINGLE) &&
1190 (Helm_registry.get_opt_default Helm_registry.get_bool ~default:true "matita.auto_disambiguation")
1192 Lazy.force nonvars_uris
1194 let dialog = gui#newUriDialog () in
1195 if hide_uri_entry then
1196 dialog#uriEntryHBox#misc#hide ();
1199 dialog#uriChoiceSelectedButton#misc#hide ();
1200 dialog#uriChoiceConstantsButton#misc#hide ();
1202 dialog#okLabel#set_label ok_label;
1203 dialog#uriChoiceTreeView#selection#set_mode
1204 (selection_mode :> Gtk.Tags.selection_mode);
1205 let model = new stringListModel dialog#uriChoiceTreeView in
1206 let choices = ref None in
1210 dialog#copyButton#misc#show ();
1211 connect_button dialog#copyButton
1213 match model#easy_selection () with
1216 dialog#uriChoiceDialog#set_title title;
1217 dialog#uriChoiceLabel#set_text msg;
1218 List.iter model#easy_append (List.map UriManager.string_of_uri uris);
1219 dialog#uriChoiceConstantsButton#misc#set_sensitive nonvars_button;
1222 dialog#uriChoiceDialog#destroy ();
1225 ignore (dialog#uriChoiceDialog#event#connect#delete (fun _ -> true));
1226 connect_button dialog#uriChoiceConstantsButton (fun _ ->
1227 return (Some (Lazy.force nonvars_uris)));
1228 if ok_action = `AUTO then
1229 connect_button dialog#uriChoiceAutoButton (fun _ ->
1230 Helm_registry.set_bool "matita.auto_disambiguation" true;
1231 return (Some (Lazy.force nonvars_uris)))
1233 connect_button dialog#uriChoiceAutoButton (fun _ ->
1234 match model#easy_selection () with
1236 | uris -> return (Some (List.map UriManager.uri_of_string uris)));
1237 connect_button dialog#uriChoiceSelectedButton (fun _ ->
1238 match model#easy_selection () with
1240 | uris -> return (Some (List.map UriManager.uri_of_string uris)));
1241 connect_button dialog#uriChoiceAbortButton (fun _ -> return None);
1242 dialog#uriChoiceDialog#show ();
1244 (match !choices with
1245 | None -> raise MatitaTypes.Cancel
1246 | Some uris -> uris)
1250 let cols = new GTree.column_list in
1251 let id_col = cols#add Gobject.Data.string in
1252 let dsc_col = cols#add Gobject.Data.string in
1253 let interp_no_col = cols#add Gobject.Data.int in
1254 let tree_store = GTree.tree_store cols in
1255 let id_renderer = GTree.cell_renderer_text [], ["text", id_col] in
1256 let dsc_renderer = GTree.cell_renderer_text [], ["text", dsc_col] in
1257 let id_view_col = GTree.view_column ~renderer:id_renderer () in
1258 let dsc_view_col = GTree.view_column ~renderer:dsc_renderer () in
1259 fun tree_view choices ->
1262 tree_view#set_model (Some (tree_store :> GTree.model));
1263 ignore (tree_view#append_column id_view_col);
1264 ignore (tree_view#append_column dsc_view_col);
1265 let name_of_interp =
1266 (* try to find a reasonable name for an interpretation *)
1270 List.assoc "0" interp
1272 incr idx; string_of_int !idx
1274 tree_store#clear ();
1275 let idx = ref ~-1 in
1279 let interp_row = tree_store#append () in
1280 tree_store#set ~row:interp_row ~column:id_col
1281 (name_of_interp interp);
1282 tree_store#set ~row:interp_row ~column:interp_no_col !idx;
1285 let row = tree_store#append ~parent:interp_row () in
1286 tree_store#set ~row ~column:id_col id;
1287 tree_store#set ~row ~column:dsc_col dsc;
1288 tree_store#set ~row ~column:interp_no_col !idx)
1292 method get_interp_no tree_path =
1293 let iter = tree_store#get_iter tree_path in
1294 tree_store#get ~row:iter ~column:interp_no_col
1297 let interactive_interp_choice () =
1298 fun text prefix_len choices ->
1299 let gui = instance () in
1300 assert (choices <> []);
1301 let dialog = gui#newRecordDialog () in
1302 let model = new interpModel dialog#recordChoiceTreeView choices in
1303 dialog#recordChoiceDialog#set_title "Interpretation choice";
1304 dialog#recordChoiceDialogLabel#set_label "Choose an interpretation:";
1305 let interp_no = ref None in
1307 dialog#recordChoiceDialog#destroy ();
1310 let fail _ = interp_no := None; return () in
1311 ignore (dialog#recordChoiceDialog#event#connect#delete (fun _ -> true));
1312 connect_button dialog#recordChoiceOkButton (fun _ ->
1313 match !interp_no with None -> () | Some _ -> return ());
1314 connect_button dialog#recordChoiceCancelButton fail;
1315 ignore (dialog#recordChoiceTreeView#connect#row_activated (fun path _ ->
1316 interp_no := Some (model#get_interp_no path);
1318 let selection = dialog#recordChoiceTreeView#selection in
1319 ignore (selection#connect#changed (fun _ ->
1320 match selection#get_selected_rows with
1321 | [path] -> interp_no := Some (model#get_interp_no path)
1322 | _ -> assert false));
1323 dialog#recordChoiceDialog#show ();
1325 (match !interp_no with Some row -> [row] | _ -> raise MatitaTypes.Cancel)
1327 let interactive_string_choice
1328 text prefix_len ?(title = "") ?(msg = "") () ~id locs uris
1330 let gui = instance () in
1331 let dialog = gui#newUriDialog () in
1332 dialog#uriEntryHBox#misc#hide ();
1333 dialog#uriChoiceSelectedButton#misc#hide ();
1334 dialog#uriChoiceAutoButton#misc#hide ();
1335 dialog#uriChoiceConstantsButton#misc#hide ();
1336 dialog#uriChoiceTreeView#selection#set_mode
1337 (`SINGLE :> Gtk.Tags.selection_mode);
1338 let model = new stringListModel dialog#uriChoiceTreeView in
1339 let choices = ref None in
1340 dialog#uriChoiceDialog#set_title title;
1341 let hack_len = MatitaGtkMisc.utf8_string_length text in
1342 let rec colorize acc_len = function
1344 let floc = HExtlib.floc_of_loc (acc_len,hack_len) in
1345 fst(MatitaGtkMisc.utf8_parsed_text text floc)
1347 let start, stop = HExtlib.loc_of_floc he in
1348 let floc1 = HExtlib.floc_of_loc (acc_len,start) in
1349 let str1,_=MatitaGtkMisc.utf8_parsed_text text floc1 in
1350 let str2,_ = MatitaGtkMisc.utf8_parsed_text text he in
1351 str1 ^ "<b>" ^ str2 ^ "</b>" ^ colorize stop tl
1353 (* List.iter (fun l -> let start, stop = HExtlib.loc_of_floc l in
1354 Printf.eprintf "(%d,%d)" start stop) locs; *)
1358 fst (HExtlib.loc_of_floc loc1) - fst (HExtlib.loc_of_floc loc2))
1361 (* prerr_endline "XXXXXXXXXXXXXXXXXXXX";
1362 List.iter (fun l -> let start, stop = HExtlib.loc_of_floc l in
1363 Printf.eprintf "(%d,%d)" start stop) locs;
1364 prerr_endline "XXXXXXXXXXXXXXXXXXXX2"; *)
1365 dialog#uriChoiceLabel#set_use_markup true;
1366 let txt = colorize 0 locs in
1367 let txt,_ = MatitaGtkMisc.utf8_parsed_text txt
1368 (HExtlib.floc_of_loc (prefix_len,MatitaGtkMisc.utf8_string_length txt))
1370 dialog#uriChoiceLabel#set_label txt;
1371 List.iter model#easy_append uris;
1374 dialog#uriChoiceDialog#destroy ();
1377 ignore (dialog#uriChoiceDialog#event#connect#delete (fun _ -> true));
1378 connect_button dialog#uriChoiceForwardButton (fun _ ->
1379 match model#easy_selection () with
1381 | uris -> return (Some uris));
1382 connect_button dialog#uriChoiceAbortButton (fun _ -> return None);
1383 dialog#uriChoiceDialog#show ();
1385 (match !choices with
1386 | None -> raise MatitaTypes.Cancel
1387 | Some uris -> uris)
1389 let interactive_interp_choice () text prefix_len choices =
1390 (* List.iter (fun (l,_,_) ->
1391 List.iter (fun l -> let start, stop = HExtlib.loc_of_floc l in
1392 Printf.eprintf "(%d,%d)" start stop) l; prerr_endline "")
1393 ((List.hd choices)); *)
1394 let filter_choices filter =
1395 let rec is_compatible filter =
1400 if List.assoc id filter = dsc then
1401 is_compatible filter tl
1407 List.filter (fun (_,interp) -> is_compatible filter interp)
1409 let rec get_choices id =
1413 let _,_,dsc = List.find (fun (_,id',_) -> id = id') he in
1414 dsc :: (List.filter (fun dsc' -> dsc <> dsc') (get_choices id tl))
1416 let example_interp =
1420 let ask_user id locs choices =
1421 interactive_string_choice
1423 ~title:"Ambiguous input"
1424 ~msg:("Choose an interpretation for " ^ id) () ~id locs choices
1426 let rec classify ids filter partial_interpretations =
1428 [] -> List.map fst partial_interpretations
1429 | (locs,id,_)::tl ->
1430 let choices = get_choices id partial_interpretations in
1435 match ask_user id locs choices with
1439 let filter = (id,chosen_dsc)::filter in
1440 let compatible_interps = filter_choices filter partial_interpretations in
1441 classify tl filter compatible_interps in
1442 let enumerated_choices =
1443 let idx = ref ~-1 in
1444 List.map (fun interp -> incr idx; !idx,interp) choices
1446 classify example_interp [] enumerated_choices
1449 (* disambiguator callbacks *)
1450 GrafiteDisambiguator.set_choose_uris_callback (interactive_uri_choice ());
1451 GrafiteDisambiguator.set_choose_interp_callback (interactive_interp_choice ());
1452 (* gtk initialization *)
1453 GtkMain.Rc.add_default_file BuildTimeConf.gtkrc_file; (* loads gtk rc *)
1454 GMathView.add_configuration_path BuildTimeConf.gtkmathview_conf;
1455 ignore (GMain.Main.init ())