open MatitaGtkMisc
open MatitaMisc
+let gui_instance = ref None ;;
+
+class console ~evbox ~phrase_sep ~packing ~paned () =
+ let console = MatitaConsole.console ~evbox ~phrase_sep ~packing ~paned () in
+ object
+ method clear = console#clear
+ method echo_error = console#echo_error
+ method echo_message = console#echo_message
+ method wrap_exn: 'a. (unit -> 'a) -> 'a option = console#wrap_exn
+ method choose_uri uris =
+ let g = match !gui_instance with None -> assert false | Some g -> g in
+ let ul = g#newUriDialog () in
+ ul#toplevel#show ();
+ let model = new stringListModel ul#uriChoiceTreeView in
+ List.iter model#easy_append uris;
+ ul#uriChoiceDialog#set_title "Hints";
+ ul#uriChoiceLabel#set_text "Suggested uris";
+ ul#uriChoiceAbortButton#misc#hide ();
+ ul#uriChoiceAutoButton#misc#hide ();
+ ul#uriChoiceConstantsButton#misc#hide ();
+ ul#hbox2#misc#hide ();
+ ul#uriChoiceTreeView#selection#set_mode
+ (`SINGLE :> Gtk.Tags.selection_mode);
+ let _ = ul#uriChoiceTreeView#selection#connect#changed
+ ~callback:(fun () -> ()) in
+ let _ = ul#toplevel#connect#destroy
+ ~callback:(fun () -> GMain.Main.quit ()) in
+ let choices = ref None in
+ let _ = ul#uriChoiceSelectedButton#connect#clicked
+ ~callback:(fun () ->
+ (match model#easy_selection () with
+ | [] -> ()
+ | [uri] -> choices := (Some uri)
+ | _ -> assert false);
+ ul#uriChoiceDialog#destroy ();
+ GMain.Main.quit ()) in
+ GMain.main ();
+ match !choices with
+ | Some u -> u
+ | None -> raise MatitaTypes.Cancel
+
+ method show = console#show
+
+ method console = console
+ end
+
class gui file =
(* creation order _is_ relevant for windows placement *)
let toolbar = new toolBarWin ~file () in
let main = new mainWin ~file () in
let about = new aboutWin ~file () in
let fileSel = new fileSelectionWin ~file () in
- let proof = new proofWin ~file () in
- let check = new checkWin ~file () in
let script = new scriptWin ~file () in
let keyBindingBoxes = (* event boxes which should receive global key events *)
- [ toolbar#toolBarEventBox; proof#proofWinEventBox; main#mainWinEventBox;
- check#checkWinEventBox; script#scriptWinEventBox; main#consoleEventBox ]
+ [ toolbar#toolBarEventBox; main#mainWinEventBox;
+ script#scriptWinEventBox; main#consoleEventBox ]
in
let console =
- MatitaConsole.console ~evbox:main#consoleEventBox
+ new console ~evbox:main#consoleEventBox
~phrase_sep:BuildTimeConf.phrase_sep
~packing:main#scrolledConsole#add ~paned:main#mainVPanes ()
in
- let script_buf = script#scriptTextView#buffer in
object (self)
val mutable chosen_file = None
- (** text mark and tag representing locked part of a script *)
- val locked_mark =
- script_buf#create_mark ~name:"locked" ~left_gravity:true
- script_buf#start_iter
- val locked_tag =
- script_buf#create_tag [`BACKGROUND "green"; `EDITABLE false]
-
initializer
(* glade's check widgets *)
List.iter (fun w -> w#check_widgets ())
(let c w = (w :> <check_widgets: unit -> unit>) in
- [ c about; c fileSel; c main; c proof; c toolbar; c check; c script ]);
+ [ c about; c fileSel; c main; c toolbar; c script ]);
(* key bindings *)
List.iter (* global key bindings *)
(fun (key, callback) -> self#addKeyBinding key callback)
*)
[ GdkKeysyms._F5,
toggle_win ~check:main#showScriptMenuItem script#scriptWin;
- GdkKeysyms._x, (fun () -> console#toggle ());
+ GdkKeysyms._x, (fun () -> console#console#toggle ());
];
- add_key_binding GdkKeysyms._Escape console#hide main#consoleEventBox;
+ add_key_binding GdkKeysyms._Escape console#console#hide
+ main#consoleEventBox;
(* about win *)
ignore (about#aboutWin#event#connect#delete (fun _ -> true));
ignore (main#aboutMenuItem#connect#activate (fun _ ->
List.iter (fun w -> w#misc#set_sensitive false)
[ main#saveMenuItem; main#saveAsMenuItem ];
main#helpMenu#set_right_justified true;
- ignore (main#showConsoleMenuItem#connect#activate console#toggle);
+ ignore (main#showConsoleMenuItem#connect#activate console#console#toggle);
(* main *)
- connect_button main#hideConsoleButton console#hide;
+ connect_button main#hideConsoleButton console#console#hide;
(* console *)
console#echo_message (sprintf "\tMatita version %s\n"
BuildTimeConf.version);
- console#echo_prompt ();
- console#misc#grab_focus ();
+ console#console#echo_prompt ();
+ console#console#misc#grab_focus ();
method about = about
- method check = check
- method console = console
+ method console = (console :> MatitaTypes.console)
method fileSel = fileSel
method main = main
- method proof = proof
method script = script
method toolbar = toolbar
ignore (main#quitMenuItem#connect#activate callback);
self#addKeyBinding GdkKeysyms._q callback
- method setPhraseCallback = console#set_callback
+ method setPhraseCallback = console#console#set_callback
method chooseFile () =
fileSel#fileSelectionWin#show ();
GtkThread.main ();
!text
- method lockScript offset =
- let mark = `MARK locked_mark in
- script_buf#move_mark mark ~where:(script_buf#get_iter_at_char offset);
- script_buf#remove_tag locked_tag ~start:script_buf#start_iter
- ~stop:script_buf#end_iter;
- script_buf#apply_tag locked_tag ~start:script_buf#start_iter
- ~stop:(script_buf#get_iter_at_mark mark)
-
end
-let instance =
- let gui = lazy (new gui (Helm_registry.get "matita.glade_file")) in
- fun () -> Lazy.force gui
+let gui () =
+ let g = new gui (Helm_registry.get "matita.glade_file") in
+ gui_instance := Some g;
+ g
+
+let instance = singleton gui