From 12f5034282288694272f5386db7a68d41e0d5326 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Tue, 6 Mar 2012 11:45:57 +0000 Subject: [PATCH] Major speed-up improvement. Adding one callback per hyperlink was extremely costly. It is now immediate. --- matita/matita/cicMathView.ml | 46 ++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/matita/matita/cicMathView.ml b/matita/matita/cicMathView.ml index d619482de..81c89360a 100644 --- a/matita/matita/cicMathView.ml +++ b/matita/matita/cicMathView.ml @@ -209,31 +209,41 @@ object (self) href_statusbar_msg; false | _ -> false)); + let hyperlink_tag = self#buffer#create_tag [] in + ignore(hyperlink_tag#connect#event + ~callback:(fun ~origin event pos -> + let offset = (new GText.iter pos)#offset in + let _,_,href = + try + List.find + (fun (start,stop,href) -> start <= offset && offset <= stop + ) hyperlinks + with + Not_found -> assert false + in + match GdkEvent.get_type event with + `BUTTON_PRESS -> + (match href_callback with + None -> () + | Some f -> f href); + true + | `MOTION_NOTIFY -> + Gdk.Window.set_cursor + (match self#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 href in + href_statusbar_msg <- Some (ctxt, msg); + false + | _ -> false)); List.iter ( fun (start,stop,(href : string)) -> - let hyperlink_tag = self#buffer#create_tag [] in self#buffer#apply_tag hyperlink_tag ~start:(self#buffer#get_iter_at_char start) ~stop:(self#buffer#get_iter_at_char (stop+1)); - ignore(hyperlink_tag#connect#event - ~callback:(fun ~origin event pos -> - match GdkEvent.get_type event with - `BUTTON_PRESS -> - (match href_callback with - None -> () - | Some f -> f href); - true - | `MOTION_NOTIFY -> - Gdk.Window.set_cursor - (match self#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 href in - href_statusbar_msg <- Some (ctxt, msg); - false - | _ -> false)); ) hyperlinks + method action_toggle = (fun _ -> assert false : document_element -> bool) method remove_selections = (() : unit) method set_selection = (fun _ -> () : document_element option -> unit) -- 2.39.2