exception PopupClosed
open Printf
-let wrap_callback f = f
+let wrap_callback0 f = fun _ -> try f () with Not_found -> assert false
+let wrap_callback1 f = fun _ -> try f () with Not_found -> assert false
+let wrap_callback2 f = fun _ -> try f () with Not_found -> assert false
let connect_button (button: #GButton.button) callback =
- ignore (button#connect#clicked (wrap_callback callback))
+ ignore (button#connect#clicked (wrap_callback0 callback))
let connect_toggle_button (button: #GButton.toggle_button) callback =
- ignore (button#connect#toggled (wrap_callback callback))
+ ignore (button#connect#toggled (wrap_callback1 callback))
let connect_menu_item (menu_item: #GMenu.menu_item) callback =
- ignore (menu_item#connect#activate (wrap_callback callback))
+ ignore (menu_item#connect#activate (wrap_callback2 callback))
let connect_key (ev:GObj.event_ops) ?(modifiers = []) ?(stop = false) key
callback
GtkThread.main ();
(match !record_no with Some n -> n | _ -> raise MatitaTypes.Cancel)
+let utf8_parsed_text s floc =
+ let start, stop = HExtlib.loc_of_floc floc in
+ let start_bytes = Glib.Utf8.offset_to_pos s ~pos:0 ~off:start in
+ let stop_bytes = Glib.Utf8.offset_to_pos s ~pos:0 ~off:stop in
+ assert(stop_bytes >= start_bytes);
+ let bytes = stop_bytes - start_bytes in
+ try
+ String.sub s start_bytes bytes, bytes
+ with Invalid_argument _ ->
+ Printf.eprintf "%s/%d/%d\n" s start_bytes bytes;
+ assert false
+
+
+let utf8_string_length s =
+ if BuildTimeConf.debug then
+ assert(Glib.Utf8.validate s);
+ Glib.Utf8.length s
+