+ activate_combo_query arg query
+ in
+ let toplevel = win#toplevel in
+ let mathView = cicMathView ~packing:win#scrolledBrowser#add () in
+ let fail message =
+ MatitaGtkMisc.report_error ~title:"Cic browser" ~message
+ ~parent:toplevel ()
+ in
+ let tags =
+ [ "dir", GdkPixbuf.from_file (MatitaMisc.image_path "matita-folder.png");
+ "obj", GdkPixbuf.from_file (MatitaMisc.image_path "matita-object.png") ]
+ in
+ let handle_error f =
+ try
+ f ()
+ with exn ->
+ if not (Helm_registry.get_bool "matita.debug") then
+ fail (snd (MatitaExcPp.to_string exn))
+ else raise exn
+ in
+ let handle_error' f = (fun () -> handle_error (fun () -> f ())) in
+ let load_easter_egg = lazy (
+ win#easterEggImage#set_file (MatitaMisc.image_path "meegg.png"))
+ in
+ object (self)
+ inherit scriptAccessor
+
+ (* Whelp bar queries *)
+
+ initializer
+ activate_combo_query "" "locate";
+ win#whelpBarComboVbox#add combo#coerce;
+ let start_query () =
+ let query = String.lowercase (List.nth queries combo#active) in
+ let input = win#queryInputText#text in
+ let statement = "whelp " ^ query ^ " " ^ input ^ "." in
+ (MatitaScript.current ())#advance ~statement ()
+ in
+ ignore(win#queryInputText#connect#activate ~callback:start_query);
+ ignore(combo#connect#changed ~callback:start_query);
+ win#whelpBarImage#set_file (MatitaMisc.image_path "whelp.png");
+ win#mathOrListNotebook#set_show_tabs false;
+ win#browserForwardButton#misc#set_sensitive false;
+ win#browserBackButton#misc#set_sensitive false;
+ ignore (win#browserUri#entry#connect#activate (handle_error' (fun () ->
+ self#loadInput win#browserUri#entry#text)));
+ ignore (win#browserHomeButton#connect#clicked (handle_error' (fun () ->
+ self#load (`About `Current_proof))));
+ ignore (win#browserRefreshButton#connect#clicked
+ (handle_error' (self#refresh ~force:true)));
+ ignore (win#browserBackButton#connect#clicked (handle_error' self#back));
+ ignore (win#browserForwardButton#connect#clicked
+ (handle_error' self#forward));
+ ignore (win#toplevel#event#connect#delete (fun _ ->
+ let my_id = Oo.id self in
+ cicBrowsers := List.filter (fun b -> Oo.id b <> my_id) !cicBrowsers;
+ if !cicBrowsers = [] &&
+ Helm_registry.get "matita.mode" = "cicbrowser"
+ then
+ GMain.quit ();
+ false));
+ ignore(win#whelpResultTreeview#connect#row_activated
+ ~callback:(fun _ _ ->
+ handle_error (fun () -> self#loadInput (self#_getSelectedUri ()))));
+ mathView#set_href_callback (Some (fun uri ->
+ handle_error (fun () ->
+ self#load (`Uri (UriManager.uri_of_string uri)))));
+ self#_load (`About `Blank);
+ toplevel#show ()
+
+ val mutable current_entry = `About `Blank
+
+ val model =
+ new MatitaGtkMisc.taggedStringListModel tags win#whelpResultTreeview
+
+ val mutable lastDir = "" (* last loaded "directory" *)
+
+ method mathView = (mathView :> MatitaGuiTypes.clickableMathView)
+
+ method private _getSelectedUri () =
+ match model#easy_selection () with
+ | [sel] when is_uri sel -> sel (* absolute URI selected *)
+(* | [sel] -> win#browserUri#entry#text ^ sel |+ relative URI selected +| *)
+ | [sel] -> lastDir ^ sel
+ | _ -> assert false
+
+ (** history RATIONALE
+ *
+ * All operations about history are done using _historyFoo.
+ * Only toplevel functions (ATM load and loadInput) call _historyAdd.
+ *)
+
+ method private _historyAdd item =
+ history#add item;
+ win#browserBackButton#misc#set_sensitive true;
+ win#browserForwardButton#misc#set_sensitive false
+
+ method private _historyPrev () =
+ let item = history#previous in
+ if history#is_begin then win#browserBackButton#misc#set_sensitive false;
+ win#browserForwardButton#misc#set_sensitive true;
+ item
+
+ method private _historyNext () =
+ let item = history#next in
+ if history#is_end then win#browserForwardButton#misc#set_sensitive false;
+ win#browserBackButton#misc#set_sensitive true;
+ item
+
+ (** notebook RATIONALE
+ *
+ * Use only these functions to switch between the tabs
+ *)
+ method private _showMath = win#mathOrListNotebook#goto_page 0
+ method private _showList = win#mathOrListNotebook#goto_page 1
+
+ method private back () =
+ try
+ self#_load (self#_historyPrev ())
+ with MatitaMisc.History_failure -> ()
+
+ method private forward () =
+ try
+ self#_load (self#_historyNext ())
+ with MatitaMisc.History_failure -> ()
+
+ (* loads a uri which can be a cic uri or an about:* uri
+ * @param uri string *)
+ method private _load ?(force=false) entry =
+ handle_error (fun () ->
+ if entry <> current_entry || entry = `About `Current_proof || force then
+ begin
+ (match entry with
+ | `About `Current_proof -> self#home ()
+ | `About `Blank -> self#blank ()
+ | `About `Us -> self#egg ()
+ | `Check term -> self#_loadCheck term
+ | `Cic (term, metasenv) -> self#_loadTermCic term metasenv
+ | `Dir dir -> self#_loadDir dir
+ | `Uri uri -> self#_loadUriManagerUri uri
+ | `Whelp (query, results) ->
+ set_whelp_query query;
+ self#_loadList (List.map (fun r -> "obj",
+ UriManager.string_of_uri r) results));
+ self#setEntry entry
+ end)
+
+ method private blank () =
+ self#_showMath;
+ mathView#load_root (Lazy.force empty_mathml)#get_documentElement
+
+ method private _loadCheck term =
+ failwith "not implemented _loadCheck";
+(* self#_showMath *)
+
+ method private egg () =
+ win#mathOrListNotebook#goto_page 2;
+ Lazy.force load_easter_egg
+
+ method private home () =
+ self#_showMath;
+ match self#script#grafite_status.proof_status with
+ | Proof (uri, metasenv, bo, ty) ->
+ let name = UriManager.name_of_uri (HExtlib.unopt uri) in
+ let obj = Cic.CurrentProof (name, metasenv, bo, ty, [], []) in
+ self#_loadObj obj
+ | Incomplete_proof { proof = (uri, metasenv, bo, ty) } ->
+ let name = UriManager.name_of_uri (HExtlib.unopt uri) in
+ let obj = Cic.CurrentProof (name, metasenv, bo, ty, [], []) in
+ self#_loadObj obj
+ | _ -> self#blank ()
+
+ (** loads a cic uri from the environment
+ * @param uri UriManager.uri *)
+ method private _loadUriManagerUri uri =
+ let uri = UriManager.strip_xpointer uri in
+ let (obj, _) = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
+ self#_loadObj obj
+
+ method private _loadDir dir =
+ let content = Http_getter.ls dir in
+ let l =
+ List.fast_sort
+ Pervasives.compare
+ (List.map
+ (function
+ | Http_getter_types.Ls_section s -> "dir", s
+ | Http_getter_types.Ls_object o -> "obj", o.Http_getter_types.uri)
+ content)
+ in
+ lastDir <- dir;
+ self#_loadList l
+
+ method private setEntry entry =
+ win#browserUri#entry#set_text (MatitaTypes.string_of_entry entry);
+ current_entry <- entry
+
+ method private _loadObj obj =
+ (* showMath must be done _before_ loading the document, since if the
+ * widget is not mapped (hidden by the notebook) the document is not
+ * rendered *)
+ self#_showMath;
+ mathView#load_object obj