1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
(**************************************************************************)
(* Lablgtk - Examples *)
(* *)
(* This code is in the public domain. *)
(* You may freely copy parts of it in your application. *)
(* *)
(**************************************************************************)
(* #require "lablgtksourceview2.gtksourceview2";; *)
let provider =
let open GSourceView2 in
let provider_ref = ref None in
let provided_list = ["toto"; "titi"; "tata"] in
let do_provider () = match !provider_ref with None -> assert false | Some x -> x in
let populate context =
let ctx = new source_completion_context context in
let item s = source_completion_item ~label:s ~text:s () in
let proposal s = (item s :> source_completion_proposal) in
let proposals = List.map proposal provided_list in
ctx#add_proposals (do_provider ()) proposals true
in
let info_widget provider =
let label = GMisc.label ~text:"toto" () in
Some (label#coerce#as_widget)
in
let provider =
let provider = {
provider_name = "default";
provider_icon = Some (GdkPixbuf.create 60 60 ());
provider_populate = populate;
provider_activation = [];
provider_match = (fun _ -> true);
provider_info_widget = info_widget;
provider_update_info = (fun _ _ -> ());
provider_start_iter = (fun _ _ _ -> false);
provider_activate_proposal = (fun _ _ -> false);
provider_interactive_delay = 0;
provider_priority = 0;
} in
GSourceView2.source_completion_provider provider
in
provider_ref := (Some provider);
provider
module C = GSourceView2
let window = GWindow.window ~width:400 ~height:400 ()
let box = GPack.vbox ~packing:window#add ()
let button = GButton.button ~label:"Click" ~packing:(box#pack) ()
let v = GSourceView2.source_view ~packing:(box#pack ~expand:true) ()
let cpl = v#completion
let _ = cpl#add_provider provider
let () = window#show ()
let cb () =
let itr = v#buffer#start_iter in
let ctx = cpl#create_context itr in
ignore (cpl#show [provider] ctx)
let _ = button#connect#clicked cb
(* let _ = cpl#add_provider provider *)
(* let _ = Glib.Timeout.add 1000 (fun _ -> cpl#show [provider] ctx) *)
(* let _ = completion#add_provider provider in *)
let () =
GMain.Main.main ()
|