+ let script = HExtlib.input_file f in
+ let hs = MatitaScriptLexer.get_hot_spots script in
+ let hstext =
+ String.concat "\n" (List.map (fun (l1,l2,uri,desc) ->
+ let a,b = HExtlib.loc_of_floc l1 in
+ let c,d = HExtlib.loc_of_floc l2 in
+ let uri = match uri with None -> "()" | Some s -> s in
+ let desc = match desc with None -> "()" | Some s -> s in
+ Printf.sprintf "[%d,%d] [%d,%d] '%s' '%s'" a b c d uri desc) hs)
+ in
+ HLog.debug hstext;
+ buffer#set_text script;
+
+ (* this is the default tag for the whole script (mainly used for
+ * setting the default behaviour when needed *)
+ let all_tag = buffer#create_tag [] in
+ buffer#apply_tag all_tag ~start:(buffer#get_iter `START)
+ ~stop:(buffer#get_iter `END);
+ ignore(all_tag#connect#event
+ ~callback:(fun ~origin event pos ->
+ match GdkEvent.get_type event with
+ | `MOTION_NOTIFY ->
+ Gdk.Window.set_cursor
+ (match source_view#get_window `TEXT with None -> assert false | Some x -> x)
+ (Gdk.Cursor.create `ARROW);
+ (* code for removing message from statusbar *)
+ false
+ | _ -> false));
+
+ let invisible_tag = buffer#create_tag [ `INVISIBLE true ] in
+ let apply_tag (l1,l2,uri,desc) =
+ let hyperlink_tag =
+ buffer#create_tag [ `FOREGROUND "blue" ; `UNDERLINE `SINGLE] in
+ (* hyperlink_tag#connect#after#changed ~callback:(fun _ -> HLog.debug "***"); *)
+ let a,b = HExtlib.loc_of_floc l1 in
+ let c,d = HExtlib.loc_of_floc l2 in
+ (* setting invisibility for <A...> and </A> *)
+ buffer#apply_tag invisible_tag
+ ~start:(buffer#get_iter_at_char a)
+ ~stop:(buffer#get_iter_at_char b);
+ buffer#apply_tag invisible_tag
+ ~start:(buffer#get_iter_at_char c)
+ ~stop:(buffer#get_iter_at_char d);
+ (* setting hyperlink inside <A...> and </A> *)
+ (* XXX: I'm not sure why I'm required to put those -1 and +1
+ * otherwise I get too small a clickable area, especially for
+ * single characters hyperlinks. *)
+ buffer#apply_tag hyperlink_tag
+ ~start:(buffer#get_iter_at_char (b-1))
+ ~stop:(buffer#get_iter_at_char (c+1));
+ match uri with
+ | None -> ()
+ | Some uri ->
+ ignore(hyperlink_tag#connect#event
+ ~callback:(fun ~origin event pos ->
+ match GdkEvent.get_type event with
+ `BUTTON_PRESS ->
+ let uri' = NReference.reference_of_string uri in
+ MatitaMathView.cicBrowser (Some (`NRef uri'));
+ true
+ | `MOTION_NOTIFY ->
+ Gdk.Window.set_cursor
+ (match source_view#get_window `TEXT with None -> assert false | Some x -> x)
+ (Gdk.Cursor.create `HAND1);
+ (* let ctxt = (MatitaMisc.get_gui ())#main#statusBar#new_context ~name:"href" in
+ let msg = ctxt#push uri in
+ (* href_statusbar_msg <- Some (ctxt, msg);*) *)
+ false
+ | _ -> false))
+ in