(* Copyright (C) 2004, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://helm.cs.unibo.it/ *) open Printf open MatitaGeneratedGui open MatitaGtkMisc open MatitaMisc 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 script = new scriptWin ~file () in let keyBindingBoxes = (* event boxes which should receive global key events *) [ toolbar#toolBarEventBox; main#mainWinEventBox; script#scriptWinEventBox; main#consoleEventBox ] in let console = MatitaConsole.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 :> unit>) in [ 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._F3, toggle_win ~check:main#showProofMenuItem proof#proofWin; GdkKeysyms._F4, toggle_win ~check:main#showCheckMenuItem check#checkWin; *) [ GdkKeysyms._F5, toggle_win ~check:main#showScriptMenuItem script#scriptWin; GdkKeysyms._x, (fun () -> console#toggle ()); ]; add_key_binding GdkKeysyms._Escape console#hide main#consoleEventBox; (* about win *) ignore (about#aboutWin#event#connect#delete (fun _ -> true)); ignore (main#aboutMenuItem#connect#activate (fun _ -> about#aboutWin#show ())); connect_button about#aboutDismissButton (fun _ -> about#aboutWin#misc#hide ()); about#aboutLabel#set_label (Pcre.replace ~pat:"@VERSION@" ~templ:BuildTimeConf.version about#aboutLabel#label); (* file selection win *) ignore (fileSel#fileSelectionWin#event#connect#delete (fun _ -> true)); ignore (fileSel#fileSelectionWin#connect#response (fun event -> let return r = chosen_file <- r; fileSel#fileSelectionWin#misc#hide (); GMain.Main.quit () in match event with | `OK -> let fname = fileSel#fileSelectionWin#filename in if is_regular fname then return (Some fname) | `CANCEL -> return None | `HELP -> () | `DELETE_EVENT -> return None)); (* script *) (* menus *) toggle_visibility toolbar#toolBarWin main#showToolBarMenuItem; (* toggle_visibility proof#proofWin main#showProofMenuItem; toggle_visibility check#checkWin main#showCheckMenuItem; *) toggle_visibility script#scriptWin main#showScriptMenuItem; 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); (* main *) connect_button main#hideConsoleButton console#hide; (* console *) console#echo_message (sprintf "\tMatita version %s\n" BuildTimeConf.version); console#echo_prompt (); console#misc#grab_focus (); method about = about method console = console method fileSel = fileSel method main = main method script = script method toolbar = toolbar method newBrowserWin () = let win = new browserWin ~file () in win#check_widgets (); win method newUriDialog () = let dialog = new uriChoiceDialog ~file () in dialog#check_widgets (); dialog method newInterpDialog () = let dialog = new interpChoiceDialog ~file () in dialog#check_widgets (); dialog method newConfirmationDialog () = let dialog = new confirmationDialog ~file () in dialog#check_widgets (); dialog method newEmptyDialog () = let dialog = new emptyDialog ~file () in dialog#check_widgets (); dialog method private addKeyBinding key callback = List.iter (fun evbox -> add_key_binding key callback evbox) keyBindingBoxes method setQuitCallback callback = ignore (main#toplevel#connect#destroy callback); ignore (main#quitMenuItem#connect#activate callback); self#addKeyBinding GdkKeysyms._q callback method setPhraseCallback = console#set_callback method chooseFile () = fileSel#fileSelectionWin#show (); GtkThread.main (); chosen_file method askText ?(title = "") ?(msg = "") () = let dialog = new textDialog () in dialog#textDialog#set_title title; dialog#textDialogLabel#set_label msg; let text = ref None in let return v = text := v; dialog#textDialog#destroy (); GMain.Main.quit () in ignore (dialog#textDialog#event#connect#delete (fun _ -> true)); connect_button dialog#textDialogCancelButton (fun _ -> return None); connect_button dialog#textDialogOkButton (fun _ -> let text = dialog#textDialogTextView#buffer#get_text () in return (Some text)); dialog#textDialog#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 gui () = new gui (Helm_registry.get "matita.glade_file") let instance = singleton gui