Download The demexp Book - Linux

Transcript
Function update view adds needed columns to view and connects them to the backend.
125a
hnewquestion.ml 124ai+≡
/ 124b 125b .
let update_view ˜view ˜backend () =
(* response column *)
let col = GTree.view_column ˜title:(s_ "response")
˜renderer:(GTree.cell_renderer_text [], ["text",
backend#col_response]) () in
ignore(view#append_column col);
(* link column *)
let col = GTree.view_column ˜title:(s_ "link")
˜renderer:(GTree.cell_renderer_text [], ["text",
backend#col_link]) () in
ignore(view#append_column col);
view#set_rules_hint true;
view#selection#set_mode ‘SINGLE;
view#set_model (Some backend#store#coerce)
25.2
New question window
Callback remove response is called when user clicks on button “Remove”. It just gets the
selected row and remove it from backend.
Note: We consider only one path because only one row can be selected at a time (see end of
code chunk 125a).
125b
hnewquestion.ml 124ai+≡
/ 125a 126a .
let remove_response ui_new_question backend sb_context () =
(* get current selected row *)
let paths = ui_new_question#treeview23#selection#get_selected_rows in
let model : #GTree.model = backend#store in
match paths with
| [] -> ()
| path :: _ ->
let iter = model#get_iter path in
let response = model#get ˜row:iter ˜column:backend#col_response in
ignore(model#remove iter);
Hashtbl.remove backend#response_hash response;
sb_context#pop ()
125