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 fileSel = new fileSelectionWin () in
111 let findRepl = new findReplWin () in
112 let develList = new develListWin () in
113 let newDevel = new newDevelopmentWin () in
114 let keyBindingBoxes = (* event boxes which should receive global key events *)
115 [ main#mainWinEventBox ]
117 let console = new console ~buffer:main#logTextView#buffer () in
118 let (source_view: GSourceView.source_view) =
119 GSourceView.source_view
121 ~insert_spaces_instead_of_tabs:true ~tabs_width:2
122 ~margin:80 ~show_margin:true
124 ~packing:main#scriptScrolledWin#add
127 let default_font_size =
128 Helm_registry.get_opt_default Helm_registry.int
129 ~default:BuildTimeConf.default_font_size "matita.font_size"
131 let source_buffer = source_view#source_buffer in
133 val mutable chosen_file = None
134 val mutable _ok_not_exists = false
135 val mutable _only_directory = false
136 val mutable script_fname = None
137 val mutable font_size = default_font_size
138 val mutable next_devel_must_contain = None
141 (* glade's check widgets *)
142 List.iter (fun w -> w#check_widgets ())
143 (let c w = (w :> <check_widgets: unit -> unit>) in
144 [ c fileSel; c main; c findRepl]);
146 List.iter (* global key bindings *)
147 (fun (key, callback) -> self#addKeyBinding key callback)
150 toggle_win ~check:main#showProofMenuItem proof#proofWin;
152 toggle_win ~check:main#showCheckMenuItem check#checkWin;
156 let parse_txt_file file =
157 let ch = open_in (BuildTimeConf.runtime_base_dir ^ "/" ^ file) in
158 let l_rev = ref [] in
161 l_rev := input_line ch :: !l_rev;
170 ~authors:(parse_txt_file "AUTHORS")
171 (*~comments:"comments"*)
172 ~copyright:"Copyright (C) 2005, the HELM team"
173 ~license:(String.concat "\n" (parse_txt_file "LICENSE"))
174 (*?logo:GdkPixbuf.pixbuf*)
175 (*?logo_icon_name:string*)
177 ~version:BuildTimeConf.version
178 ~website:"http://helm.cs.unibo.it"
181 ignore (main#aboutMenuItem#connect#activate
182 (fun _ -> about_dialog#present ()));
184 let show_find_Repl () =
185 findRepl#toplevel#misc#show ();
186 findRepl#toplevel#misc#grab_focus ()
188 let hide_find_Repl () = findRepl#toplevel#misc#hide () in
190 let highlight start end_ =
191 source_buffer#move_mark `INSERT ~where:start;
192 source_buffer#move_mark `SEL_BOUND ~where:end_;
193 source_view#scroll_mark_onscreen `INSERT
195 let text = findRepl#findEntry#text in
196 let iter = source_buffer#get_iter `SEL_BOUND in
197 match iter#forward_search text with
199 (match source_buffer#start_iter#forward_search text with
201 | Some (start,end_) -> highlight start end_)
202 | Some (start,end_) -> highlight start end_
205 let text = findRepl#replaceEntry#text in
206 let ins = source_buffer#get_iter `INSERT in
207 let sel = source_buffer#get_iter `SEL_BOUND in
208 if ins#compare sel < 0 then
210 ignore(source_buffer#delete_selection ());
211 source_buffer#insert text
214 connect_button findRepl#findButton find_forward;
215 connect_button findRepl#findReplButton replace;
216 connect_button findRepl#cancelButton (fun _ -> hide_find_Repl ());
217 ignore(findRepl#toplevel#event#connect#delete
218 ~callback:(fun _ -> hide_find_Repl ();true));
221 (* phase 1: we save the actual status of the marks and we undo *)
222 let locked_mark = `MARK ((MatitaScript.instance ())#locked_mark) in
223 let locked_iter = source_view#buffer#get_iter_at_mark locked_mark in
224 let locked_iter_offset = locked_iter#offset in
227 (source_view#buffer#create_mark ~name:"lock_point"
228 ~left_gravity:true locked_iter) in
229 source_view#source_buffer#undo ();
230 (* phase 2: we save the cursor position and we redo, restoring
231 the previous status of all the marks *)
232 let cursor_iter = source_view#buffer#get_iter_at_mark `INSERT in
235 (source_view#buffer#create_mark ~name:"undo_point"
236 ~left_gravity:true cursor_iter)
238 source_view#source_buffer#redo ();
239 let mark_iter = source_view#buffer#get_iter_at_mark mark in
240 let mark2_iter = source_view#buffer#get_iter_at_mark mark2 in
241 let mark2_iter = mark2_iter#set_offset locked_iter_offset in
242 source_view#buffer#move_mark locked_mark ~where:mark2_iter;
243 source_view#buffer#delete_mark mark;
244 source_view#buffer#delete_mark mark2;
245 (* phase 3: if after the undo the cursor was in the locked area,
246 then we move it there again and we perform a goto *)
247 if mark_iter#offset < locked_iter_offset then
249 source_view#buffer#move_mark `INSERT ~where:mark_iter;
250 (MatitaScript.instance ())#goto `Cursor ();
252 (* phase 4: we perform again the undo. This time we are sure that
253 the text to undo is not locked *)
254 source_view#source_buffer#undo ();
255 source_view#misc#grab_focus () in
258 (* phase 1: we save the actual status of the marks, we redo and
260 let locked_mark = `MARK ((MatitaScript.instance ())#locked_mark) in
261 let locked_iter = source_view#buffer#get_iter_at_mark locked_mark in
262 let locked_iter_offset = locked_iter#offset in
265 (source_view#buffer#create_mark ~name:"lock_point"
266 ~left_gravity:true locked_iter) in
267 source_view#source_buffer#redo ();
268 source_view#source_buffer#undo ();
269 (* phase 2: we save the cursor position and we restore
270 the previous status of all the marks *)
271 let cursor_iter = source_view#buffer#get_iter_at_mark `INSERT in
274 (source_view#buffer#create_mark ~name:"undo_point"
275 ~left_gravity:true cursor_iter)
277 let mark_iter = source_view#buffer#get_iter_at_mark mark in
278 let mark2_iter = source_view#buffer#get_iter_at_mark mark2 in
279 let mark2_iter = mark2_iter#set_offset locked_iter_offset in
280 source_view#buffer#move_mark locked_mark ~where:mark2_iter;
281 source_view#buffer#delete_mark mark;
282 source_view#buffer#delete_mark mark2;
283 (* phase 3: if after the undo the cursor is in the locked area,
284 then we move it there again and we perform a goto *)
285 if mark_iter#offset < locked_iter_offset then
287 source_view#buffer#move_mark `INSERT ~where:mark_iter;
288 (MatitaScript.instance ())#goto `Cursor ();
290 (* phase 4: we perform again the redo. This time we are sure that
291 the text to redo is not locked *)
292 source_view#source_buffer#redo ();
293 source_view#misc#grab_focus ()
295 ignore(self#main#undoMenuItem#connect#activate ~callback:safe_undo);
296 ignore(source_view#source_buffer#connect#can_undo
297 ~callback:self#main#undoMenuItem#misc#set_sensitive);
298 ignore(self#main#redoMenuItem#connect#activate ~callback:safe_redo);
299 ignore(source_view#source_buffer#connect#can_redo
300 ~callback:self#main#redoMenuItem#misc#set_sensitive);
301 ignore(source_view#connect#after#populate_popup
302 ~callback:(fun pre_menu ->
303 let menu = new GMenu.menu pre_menu in
304 let menuItems = menu#children in
305 let undoMenuItem, redoMenuItem =
307 [undo;redo;sep1;cut;copy;paste;delete;sep2;
308 selectall;sep3;inputmethod;insertunicodecharacter] -> undo,redo
309 | _ -> assert false in
310 let new_undoMenuItem =
311 GMenu.image_menu_item
312 ~image:(GMisc.image ~stock:`UNDO ())
315 ~packing:(menu#insert ~pos:0) () in
316 new_undoMenuItem#misc#set_sensitive
317 (undoMenuItem#misc#get_flag `SENSITIVE);
318 menu#remove (undoMenuItem :> GMenu.menu_item);
319 ignore(new_undoMenuItem#connect#activate ~callback:safe_undo);
320 let new_redoMenuItem =
321 GMenu.image_menu_item
322 ~image:(GMisc.image ~stock:`REDO ())
325 ~packing:(menu#insert ~pos:1) () in
326 new_redoMenuItem#misc#set_sensitive
327 (redoMenuItem#misc#get_flag `SENSITIVE);
328 menu#remove (redoMenuItem :> GMenu.menu_item);
329 ignore(new_redoMenuItem#connect#activate ~callback:safe_redo);
332 let atom = Gdk.Atom.clipboard in
333 GData.clipboard atom in
334 ignore(self#main#cutMenuItem#connect#activate
335 ~callback:(fun () -> source_view#buffer#cut_clipboard clipboard));
336 ignore(self#main#copyMenuItem#connect#activate
337 ~callback:(fun () -> source_view#buffer#copy_clipboard clipboard));
338 ignore(self#main#pasteMenuItem#connect#activate
340 source_view#buffer#paste_clipboard clipboard;
341 (MatitaScript.instance ())#clean_dirty_lock));
342 ignore(self#main#deleteMenuItem#connect#activate
343 ~callback:(fun () -> ignore (source_view#buffer#delete_selection ())));
344 ignore(self#main#findReplMenuItem#connect#activate
345 ~callback:show_find_Repl);
346 ignore (findRepl#findEntry#connect#activate ~callback:find_forward);
347 (* interface lockers *)
349 main#buttonsToolbar#misc#set_sensitive false;
350 develList#buttonsHbox#misc#set_sensitive false;
351 source_view#set_editable false
354 main#buttonsToolbar#misc#set_sensitive true;
355 develList#buttonsHbox#misc#set_sensitive true;
356 source_view#set_editable true
361 try f ();unlock_world () with exc -> unlock_world (); raise exc
363 (* developments win *)
365 new MatitaGtkMisc.multiStringListModel
366 ~cols:2 develList#developmentsTreeview
368 let refresh_devels_win () =
369 model#list_store#clear ();
371 (fun (name, root) -> model#easy_mappend [name;root])
372 (MatitamakeLib.list_known_developments ())
374 let get_devel_selected () =
375 match model#easy_mselection () with
376 | [[name;_]] -> MatitamakeLib.development_for_name name
380 while Glib.Main.pending () do
381 ignore(Glib.Main.iteration false);
384 connect_button develList#newButton
386 next_devel_must_contain <- None;
387 newDevel#toplevel#misc#show());
388 connect_button develList#deleteButton
390 (match get_devel_selected () with
392 | Some d -> MatitamakeLib.destroy_development_in_bg refresh d);
393 refresh_devels_win ()));
394 connect_button develList#buildButton
396 match get_devel_selected () with
400 (fun () -> MatitamakeLib.build_development_in_bg refresh d)
403 connect_button develList#cleanButton
405 match get_devel_selected () with
409 (fun () -> MatitamakeLib.clean_development_in_bg refresh d)
412 connect_button develList#closeButton
413 (fun () -> develList#toplevel#misc#hide());
414 ignore(develList#toplevel#event#connect#delete
415 (fun _ -> develList#toplevel#misc#hide();true));
416 let selected_devel = ref None in
417 connect_menu_item self#main#developmentsMenuItem
418 (fun () -> refresh_devels_win ();develList#toplevel#misc#show ());
420 (* add development win *)
421 let check_if_root_contains root =
422 match next_devel_must_contain with
425 let is_prefix_of d1 d2 =
426 let len1 = String.length d1 in
427 let len2 = String.length d2 in
431 let pref = String.sub d2 0 len1 in
434 is_prefix_of root path
436 connect_button newDevel#addButton
438 let name = newDevel#nameEntry#text in
439 let root = newDevel#rootEntry#text in
440 if check_if_root_contains root then
442 ignore (MatitamakeLib.initialize_development name root);
443 refresh_devels_win ();
444 newDevel#nameEntry#set_text "";
445 newDevel#rootEntry#set_text "";
446 newDevel#toplevel#misc#hide()
449 MatitaLog.error ("The selected root does not contain " ^
450 match next_devel_must_contain with
452 | _ -> assert false));
453 connect_button newDevel#chooseRootButton
455 let path = self#chooseDir () in
457 | Some path -> newDevel#rootEntry#set_text path
459 connect_button newDevel#cancelButton
460 (fun () -> newDevel#toplevel#misc#hide ());
461 ignore(newDevel#toplevel#event#connect#delete
462 (fun _ -> newDevel#toplevel#misc#hide();true));
464 (* file selection win *)
465 ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true));
466 ignore (fileSel#fileSelectionWin#connect#response (fun event ->
469 fileSel#fileSelectionWin#misc#hide ();
474 let fname = fileSel#fileSelectionWin#filename in
475 if Sys.file_exists fname then
477 if is_regular fname && not(_only_directory) then
479 else if _only_directory && is_dir fname then
484 if _ok_not_exists then
487 | `CANCEL -> return None
489 | `DELETE_EVENT -> return None));
491 List.iter (fun w -> w#misc#set_sensitive false) [ main#saveMenuItem ];
493 let adj = main#logScrolledWin#vadjustment in
494 ignore (adj#connect#changed
495 (fun _ -> adj#set_value (adj#upper -. adj#page_size)));
496 console#message (sprintf "\tMatita version %s\n" BuildTimeConf.version);
498 let module A = GrafiteAst in
499 let hole = CicNotationPt.UserInput in
500 let loc = Disambiguate.dummy_floc in
502 if (MatitaScript.instance ())#onGoingProof () then
503 (MatitaScript.instance ())#advance
504 ~statement:("\n" ^ GrafiteAstPp.pp_tactical (A.Tactic (loc, ast)))
507 let tac_w_term ast _ =
508 if (MatitaScript.instance ())#onGoingProof () then
509 let buf = source_buffer in
510 buf#insert ~iter:(buf#get_iter_at_mark (`NAME "locked"))
511 ("\n" ^ GrafiteAstPp.pp_tactic ast)
513 let tbar = self#main in
514 connect_button tbar#introsButton (tac (A.Intros (loc, None, [])));
515 connect_button tbar#applyButton (tac_w_term (A.Apply (loc, hole)));
516 connect_button tbar#exactButton (tac_w_term (A.Exact (loc, hole)));
517 connect_button tbar#elimButton (tac_w_term (A.Elim (loc, hole, None, None, [])));
518 connect_button tbar#elimTypeButton (tac_w_term (A.ElimType (loc, hole, None, None, [])));
519 connect_button tbar#splitButton (tac (A.Split loc));
520 connect_button tbar#leftButton (tac (A.Left loc));
521 connect_button tbar#rightButton (tac (A.Right loc));
522 connect_button tbar#existsButton (tac (A.Exists loc));
523 connect_button tbar#reflexivityButton (tac (A.Reflexivity loc));
524 connect_button tbar#symmetryButton (tac (A.Symmetry loc));
525 connect_button tbar#transitivityButton
526 (tac_w_term (A.Transitivity (loc, hole)));
527 connect_button tbar#assumptionButton (tac (A.Assumption loc));
528 connect_button tbar#cutButton (tac_w_term (A.Cut (loc, None, hole)));
529 connect_button tbar#autoButton (tac (A.Auto (loc,None,None,None))); (* ALB *)
530 MatitaGtkMisc.toggle_widget_visibility
531 ~widget:(self#main#tacticsButtonsHandlebox :> GObj.widget)
532 ~check:self#main#tacticsBarMenuItem;
533 let module Hr = Helm_registry in
535 not (Hr.get_opt_default Hr.bool ~default:false "matita.tactics_bar")
537 self#main#tacticsBarMenuItem#set_active false;
538 MatitaGtkMisc.toggle_callback
540 | true -> self#main#toplevel#fullscreen ()
541 | false -> self#main#toplevel#unfullscreen ())
542 ~check:self#main#fullscreenMenuItem;
543 self#main#fullscreenMenuItem#set_active false;
545 MatitaLog.set_log_callback self#console#log_callback;
546 GtkSignal.user_handler :=
547 (fun exn -> MatitaLog.error (MatitaExcPp.to_string exn));
550 match GSourceView.source_language_from_file BuildTimeConf.lang_file with
552 MatitaLog.warn (sprintf "can't load language file %s"
553 BuildTimeConf.lang_file)
554 | Some matita_lang ->
555 source_buffer#set_language matita_lang;
556 source_buffer#set_highlight true
558 let s () = MatitaScript.instance () in
560 script_fname <- None;
561 self#main#saveMenuItem#misc#set_sensitive false
563 let saveAsScript () =
565 match self#chooseFile ~ok_not_exists:true () with
567 script#assignFileName f;
568 script#saveToFile ();
569 console#message ("'"^f^"' saved.\n");
574 match script_fname with
575 | None -> saveAsScript ()
577 (s ())#assignFileName f;
578 (s ())#saveToFile ();
579 console#message ("'"^f^"' saved.\n");
583 let status = script#status in
585 if source_view#buffer#modified then
587 match ask_unsaved main#toplevel with
588 | `YES -> saveScript ()
590 | `CANCEL -> raise MatitaTypes.Cancel
592 (match script_fname with
595 ask_and_save_moo_if_needed main#toplevel fname status);
596 match self#chooseFile () with
599 script#assignFileName f;
600 source_view#source_buffer#begin_not_undoable_action ();
601 script#loadFromFile f;
602 source_view#source_buffer#end_not_undoable_action ();
603 console#message ("'"^f^"' loaded.\n");
606 with MatitaTypes.Cancel -> ()
609 source_view#source_buffer#begin_not_undoable_action ();
612 source_view#source_buffer#end_not_undoable_action ();
617 source_buffer#place_cursor
618 (source_buffer#get_iter_at_mark (`NAME "locked"));
619 source_view#misc#grab_focus ()
621 let advance _ = (MatitaScript.instance ())#advance (); cursor () in
622 let retract _ = (MatitaScript.instance ())#retract (); cursor () in
623 let top _ = (MatitaScript.instance ())#goto `Top (); cursor () in
624 let bottom _ = (MatitaScript.instance ())#goto `Bottom (); cursor () in
625 let jump _ = (MatitaScript.instance ())#goto `Cursor (); cursor () in
626 let advance = locker advance in
627 let retract = locker retract in
628 let top = locker top in
629 let bottom = locker bottom in
630 let jump = locker jump in
631 let connect_key sym f =
632 connect_key self#main#mainWinEventBox#event
633 ~modifiers:[`CONTROL] ~stop:true sym f;
634 connect_key self#sourceView#event
635 ~modifiers:[`CONTROL] ~stop:true sym f
638 self#setQuitCallback (fun () ->
639 let status = (MatitaScript.instance ())#status in
640 if source_view#buffer#modified then
642 let rc = ask_unsaved main#toplevel in
645 | `YES -> saveScript ();
646 if not source_view#buffer#modified then
648 (match script_fname with
651 ask_and_save_moo_if_needed
652 main#toplevel fname status);
655 | `NO -> GMain.Main.quit ()
656 | `CANCEL -> raise MatitaTypes.Cancel
657 with MatitaTypes.Cancel -> ()
661 (match script_fname with
662 | None -> clean_current_baseuri status; GMain.Main.quit ()
665 ask_and_save_moo_if_needed main#toplevel fname status;
667 with MatitaTypes.Cancel -> ())
669 connect_button self#main#scriptAdvanceButton advance;
670 connect_button self#main#scriptRetractButton retract;
671 connect_button self#main#scriptTopButton top;
672 connect_button self#main#scriptBottomButton bottom;
673 connect_key GdkKeysyms._Down advance;
674 connect_key GdkKeysyms._Up retract;
675 connect_key GdkKeysyms._Home top;
676 connect_key GdkKeysyms._End bottom;
677 connect_button self#main#scriptJumpButton jump;
678 connect_menu_item self#main#openMenuItem loadScript;
679 connect_menu_item self#main#saveMenuItem saveScript;
680 connect_menu_item self#main#saveAsMenuItem saveAsScript;
681 connect_menu_item self#main#newMenuItem newScript;
682 connect_key GdkKeysyms._period
684 source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT)
687 connect_key GdkKeysyms._Return
689 source_buffer#insert ~iter:(source_buffer#get_iter_at_mark `INSERT)
692 (* script monospace font stuff *)
693 self#updateFontSize ();
695 self#main#debugMenu#misc#hide ();
697 self#main#hintLowImage#set_file (image_path "matita-bulb-low.png");
698 self#main#hintMediumImage#set_file (image_path "matita-bulb-medium.png");
699 self#main#hintHighImage#set_file (image_path "matita-bulb-high.png");
701 self#sourceView#misc#grab_focus ();
702 (* main win dimension *)
703 let width = Gdk.Screen.width () in
704 let height = Gdk.Screen.height () in
705 let main_w = width * 90 / 100 in
706 let main_h = height * 80 / 100 in
707 let script_w = main_w * 6 / 10 in
708 self#main#toplevel#resize ~width:main_w ~height:main_h;
709 self#main#hpaneScriptSequent#set_position script_w;
711 ignore(source_view#connect#after#paste_clipboard
712 ~callback:(fun () -> (MatitaScript.instance ())#clean_dirty_lock))
714 method loadScript file =
715 let script = MatitaScript.instance () in
717 script#assignFileName file;
719 if Sys.file_exists file then file
720 else BuildTimeConf.script_template
722 source_view#source_buffer#begin_not_undoable_action ();
723 script#loadFromFile content;
724 source_view#source_buffer#end_not_undoable_action ();
725 console#message ("'"^file^"' loaded.");
726 self#_enableSaveTo file
728 method setStar name b =
729 let l = main#scriptLabel in
731 l#set_text (name ^ " *")
735 method private _enableSaveTo file =
736 script_fname <- Some file;
737 self#main#saveMenuItem#misc#set_sensitive true
740 method console = console
741 method sourceView: GSourceView.source_view = (source_view: GSourceView.source_view)
742 method fileSel = fileSel
743 method findRepl = findRepl
745 method develList = develList
746 method newDevel = newDevel
748 method newBrowserWin () =
750 inherit browserWin ()
751 val combo = GEdit.combo_box_entry ()
753 self#check_widgets ();
754 let combo_widget = combo#coerce in
755 uriHBox#pack ~from:`END ~fill:true ~expand:true combo_widget;
756 combo#entry#misc#grab_focus ()
757 method browserUri = combo
760 method newUriDialog () =
761 let dialog = new uriChoiceDialog () in
762 dialog#check_widgets ();
765 method newInterpDialog () =
766 let dialog = new interpChoiceDialog () in
767 dialog#check_widgets ();
770 method newConfirmationDialog () =
771 let dialog = new confirmationDialog () in
772 dialog#check_widgets ();
775 method newEmptyDialog () =
776 let dialog = new emptyDialog () in
777 dialog#check_widgets ();
780 method private addKeyBinding key callback =
781 List.iter (fun evbox -> add_key_binding key callback evbox)
784 method setQuitCallback callback =
785 ignore (main#quitMenuItem#connect#activate callback);
786 ignore (main#toplevel#event#connect#delete
787 (fun _ -> callback ();true));
788 self#addKeyBinding GdkKeysyms._q callback
790 method chooseFile ?(ok_not_exists = false) () =
791 _ok_not_exists <- ok_not_exists;
792 _only_directory <- false;
793 fileSel#fileSelectionWin#show ();
797 method private chooseDir ?(ok_not_exists = false) () =
798 _ok_not_exists <- ok_not_exists;
799 _only_directory <- true;
800 fileSel#fileSelectionWin#show ();
802 (* we should check that this is a directory *)
805 method createDevelopment ~containing =
806 next_devel_must_contain <- containing;
807 newDevel#toplevel#misc#show()
809 method askText ?(title = "") ?(msg = "") () =
810 let dialog = new textDialog () in
811 dialog#textDialog#set_title title;
812 dialog#textDialogLabel#set_label msg;
813 let text = ref None in
816 dialog#textDialog#destroy ();
819 ignore (dialog#textDialog#event#connect#delete (fun _ -> true));
820 connect_button dialog#textDialogCancelButton (fun _ -> return None);
821 connect_button dialog#textDialogOkButton (fun _ ->
822 let text = dialog#textDialogTextView#buffer#get_text () in
824 dialog#textDialog#show ();
828 method private updateFontSize () =
829 self#sourceView#misc#modify_font_by_name
830 (sprintf "%s %d" BuildTimeConf.script_font font_size)
832 method increaseFontSize () =
833 font_size <- font_size + 1;
834 self#updateFontSize ()
836 method decreaseFontSize () =
837 font_size <- font_size - 1;
838 self#updateFontSize ()
840 method resetFontSize () =
841 font_size <- default_font_size;
842 self#updateFontSize ()
847 let g = new gui () in
848 gui_instance := Some g;
851 let instance = singleton gui
853 let non p x = not (p x)
855 (* this is a shit and should be changed :-{ *)
856 let interactive_uri_choice
857 ?(selection_mode:[`SINGLE|`MULTIPLE] = `MULTIPLE) ?(title = "")
858 ?(msg = "") ?(nonvars_button = false) ?(hide_uri_entry=false)
859 ?(hide_try=false) ?(ok_label="_Auto") ?(ok_action:[`SELECT|`AUTO] = `AUTO)
863 let gui = instance () in
864 let nonvars_uris = lazy (List.filter (non UriManager.uri_is_var) uris) in
865 if (selection_mode <> `SINGLE) &&
866 (Helm_registry.get_bool "matita.auto_disambiguation")
868 Lazy.force nonvars_uris
870 let dialog = gui#newUriDialog () in
871 if hide_uri_entry then
872 dialog#uriEntryHBox#misc#hide ();
875 dialog#uriChoiceSelectedButton#misc#hide ();
876 dialog#uriChoiceConstantsButton#misc#hide ();
878 dialog#okLabel#set_label ok_label;
879 dialog#uriChoiceTreeView#selection#set_mode
880 (selection_mode :> Gtk.Tags.selection_mode);
881 let model = new stringListModel dialog#uriChoiceTreeView in
882 let choices = ref None in
883 let nonvars = ref false in
887 dialog#copyButton#misc#show ();
888 connect_button dialog#copyButton
890 match model#easy_selection () with
893 dialog#uriChoiceDialog#set_title title;
894 dialog#uriChoiceLabel#set_text msg;
895 List.iter model#easy_append (List.map UriManager.string_of_uri uris);
896 dialog#uriChoiceConstantsButton#misc#set_sensitive nonvars_button;
899 dialog#uriChoiceDialog#destroy ();
902 ignore (dialog#uriChoiceDialog#event#connect#delete (fun _ -> true));
903 connect_button dialog#uriChoiceConstantsButton (fun _ ->
904 return (Some (Lazy.force nonvars_uris)));
905 if ok_action = `AUTO then
906 connect_button dialog#uriChoiceAutoButton (fun _ ->
907 Helm_registry.set_bool "matita.auto_disambiguation" true;
908 return (Some (Lazy.force nonvars_uris)))
910 connect_button dialog#uriChoiceAutoButton (fun _ ->
911 match model#easy_selection () with
913 | uris -> return (Some (List.map UriManager.uri_of_string uris)));
914 connect_button dialog#uriChoiceSelectedButton (fun _ ->
915 match model#easy_selection () with
917 | uris -> return (Some (List.map UriManager.uri_of_string uris)));
918 connect_button dialog#uriChoiceAbortButton (fun _ -> return None);
919 dialog#uriChoiceDialog#show ();
922 | None -> raise MatitaTypes.Cancel
927 let cols = new GTree.column_list in
928 let id_col = cols#add Gobject.Data.string in
929 let dsc_col = cols#add Gobject.Data.string in
930 let interp_no_col = cols#add Gobject.Data.int in
931 let tree_store = GTree.tree_store cols in
932 let id_renderer = GTree.cell_renderer_text [], ["text", id_col] in
933 let dsc_renderer = GTree.cell_renderer_text [], ["text", dsc_col] in
934 let id_view_col = GTree.view_column ~renderer:id_renderer () in
935 let dsc_view_col = GTree.view_column ~renderer:dsc_renderer () in
936 fun tree_view choices ->
939 tree_view#set_model (Some (tree_store :> GTree.model));
940 ignore (tree_view#append_column id_view_col);
941 ignore (tree_view#append_column dsc_view_col);
943 (* try to find a reasonable name for an interpretation *)
947 List.assoc "0" interp
949 incr idx; string_of_int !idx
956 let interp_row = tree_store#append () in
957 tree_store#set ~row:interp_row ~column:id_col
958 (name_of_interp interp);
959 tree_store#set ~row:interp_row ~column:interp_no_col !idx;
962 let row = tree_store#append ~parent:interp_row () in
963 tree_store#set ~row ~column:id_col id;
964 tree_store#set ~row ~column:dsc_col dsc;
965 tree_store#set ~row ~column:interp_no_col !idx)
969 method get_interp_no tree_path =
970 let iter = tree_store#get_iter tree_path in
971 tree_store#get ~row:iter ~column:interp_no_col
974 let interactive_interp_choice () choices =
975 let gui = instance () in
976 assert (choices <> []);
977 let dialog = gui#newInterpDialog () in
978 let model = new interpModel dialog#interpChoiceTreeView choices in
979 let interp_len = List.length (List.hd choices) in
980 dialog#interpChoiceDialog#set_title "Interpretation choice";
981 dialog#interpChoiceDialogLabel#set_label "Choose an interpretation:";
982 let interp_no = ref None in
984 dialog#interpChoiceDialog#destroy ();
987 let fail _ = interp_no := None; return () in
988 ignore (dialog#interpChoiceDialog#event#connect#delete (fun _ -> true));
989 connect_button dialog#interpChoiceOkButton (fun _ ->
990 match !interp_no with None -> () | Some _ -> return ());
991 connect_button dialog#interpChoiceCancelButton fail;
992 ignore (dialog#interpChoiceTreeView#connect#row_activated (fun path _ ->
993 interp_no := Some (model#get_interp_no path);
995 let selection = dialog#interpChoiceTreeView#selection in
996 ignore (selection#connect#changed (fun _ ->
997 match selection#get_selected_rows with
999 MatitaLog.debug (sprintf "selection: %d" (model#get_interp_no path));
1000 interp_no := Some (model#get_interp_no path)
1001 | _ -> assert false));
1002 dialog#interpChoiceDialog#show ();
1004 (match !interp_no with Some row -> [row] | _ -> raise MatitaTypes.Cancel)