Debian Codegraph @

ide/rocqide/session.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Preferences
12
13 (** A session is a script buffer + proof + messages,
14 interacting with a rocqtop, and a few other elements around *)
15
16 class type ['a] page =
17 object
18 inherit GObj.widget
19 method update : 'a -> unit
20 method on_update : callback:('a -> unit) -> unit
21 method data : 'a
22 end
23
24 class type control =
25 object
26 method detach : unit -> unit
27 end
28
29 type errpage = (int * string) list page
30 type jobpage = string CString.Map.t page
31 type breakpoint = {
32 mark_id : string;
33 mutable prev_byte_offset : int; (* UTF-8 byte offset for Rocq *)
34 (* prev_uni_offset may differ from mark#offset as the script is edited *)
35 mutable prev_uni_offset : int; (* unicode offset for GTK *)
36 }
37
38 type session = {
39 buffer : GText.buffer;
40 script : Wg_ScriptView.script_view;
41 proof : Wg_ProofView.proof_view; (* the proof context panel *)
42 messages : Wg_RoutedMessageViews.message_views_router;
43 segment : Wg_Segment.segment; (* color coded status bar near bottom of the screen *)
44 fileops : FileOps.ops;
45 rocqops : RocqOps.ops;
46 rocqtop : RocqDriver.rocqtop;
47 command : Wg_Command.command_window; (* aka the Query Pane *)
48 finder : Wg_Find.finder; (* Find / Replace panel *)
49 debugger : Wg_Debugger.debugger_view;
50 tab_label : GMisc.label;
51 errpage : errpage;
52 warnpage : errpage;
53 jobpage : jobpage;
54 sid : int;
55 basename : string;
56 mutable control : control;
57 mutable abs_file_name : string option;
58 mutable debug_stop_pt : (session * int * int) option;
59 mutable breakpoints : breakpoint list;
60 mutable last_db_goals : Pp.t
61 }
62
63 let next_sid = ref 0
64
65 let create_buffer () =
66 let buffer = GSourceView3.source_buffer
67 ~tag_table:Tags.Script.table
68 ~highlight_matching_brackets:true
69 ?language:(lang_manager#language source_language#get)
70 ?style_scheme:(style_manager#style_scheme source_style#get)
71 ()
72 in
73 let _ = buffer#create_mark ~name:"start_of_input" buffer#start_iter in
74 let _ = buffer#create_mark
75 ~left_gravity:false ~name:"stop_of_input" buffer#end_iter in
76 let _ = buffer#create_mark ~name:"prev_insert" buffer#start_iter in
77 let _ = buffer#place_cursor ~where:buffer#start_iter in
78 let _ = buffer#add_selection_clipboard Ideutils.cb in
79 buffer
80
81 let create_script rocqtop source_buffer =
82 let script = Wg_ScriptView.script_view rocqtop ~source_buffer
83 ~show_line_numbers:true ~wrap_mode:`NONE ()
84 (* todo: line numbers don't appear *)
85 in
86 let _ = script#misc#set_name "ScriptWindow"
87 in
88 script
89
90 (** NB: Events during text edition:
91
92 - [begin_user_action]
93 - [insert_text] (or [delete_range] when deleting)
94 - [changed]
95 - [end_user_action]
96
97 When pasting a text containing tags (e.g. the sentence terminators),
98 there is actually many [insert_text] and [changed]. For instance,
99 for "a. b.":
100
101 - [begin_user_action]
102 - [insert_text] (for "a")
103 - [changed]
104 - [insert_text] (for ".")
105 - [changed]
106 - [apply_tag] (for the tag of ".")
107 - [insert_text] (for " b")
108 - [changed]
109 - [insert_text] (for ".")
110 - [changed]
111 - [apply_tag] (for the tag of ".")
112 - [end_user_action]
113
114 Since these copy-pasted tags may interact badly with the retag mechanism,
115 we now don't monitor the "changed" event, but rather the "begin_user_action"
116 and "end_user_action". We begin by setting a mark at the initial cursor
117 point. At the end, the zone between the mark and the cursor is to be
118 untagged and then retagged. *)
119
120 let misc () = CDebug.(get_flag misc)
121
122 type action_stack_entry = Mark of Gtk.text_mark | Begin
123
124 type action_stack = action_stack_entry list option
125
126 let call_rocq_or_cancel_action rocqtop rocqops (buffer : GText.buffer) it =
127 let () = try buffer#delete_mark (`NAME "target") with GText.No_such_mark _ -> () in
128 let mark = buffer#create_mark ~name:"target" it in
129 let action = rocqops#go_to_mark (`MARK mark) in
130 ignore @@ RocqDriver.try_grab rocqtop action (fun () -> ())
131
132 let init_user_action (stack : action_stack ref) = match !stack with
133 | None -> stack := Some []
134 | Some _ -> assert false
135
136 let close_user_action (stack : action_stack ref) = match !stack with
137 | None -> assert false
138 | Some marks ->
139 let () = stack := None in
140 marks
141
142 let handle_iter rocqtop rocqops (buffer : GText.buffer) it (stack : action_stack ref) =
143 match it with
144 | None -> ()
145 | Some it ->
146 match !stack with
147 | Some marks ->
148 (* We are inside an user action, deferring to its end *)
149 let ent = if it#offset > 0 then Mark (buffer#create_mark it) else Begin in
150 stack := Some (ent :: marks)
151 | None ->
152 (* Otherwise we move to the mark now *)
153 call_rocq_or_cancel_action rocqtop rocqops buffer it
154
155 let set_buffer_handlers
156 (buffer : GText.buffer) script (rocqops : RocqOps.ops) rocqtop
157 =
158 let action_stack : action_stack ref = ref None in
159 let get_start () = buffer#get_iter_at_mark (`NAME "start_of_input") in
160 let get_stop () = buffer#get_iter_at_mark (`NAME "stop_of_input") in
161 let ensure_marks_exist () =
162 try ignore(buffer#get_mark (`NAME "stop_of_input"))
163 with GText.No_such_mark _ -> assert false in
164 let get_insert () = buffer#get_iter_at_mark `INSERT in
165 let update_prev it =
166 let prev = buffer#get_iter_at_mark (`NAME "prev_insert") in
167 if it#offset < prev#offset then
168 buffer#move_mark (`NAME "prev_insert") ~where:it
169 in
170 let debug_edit_zone () = if false (*!Minilib.debug*) then begin
171 buffer#remove_tag Tags.Script.edit_zone
172 ~start:buffer#start_iter ~stop:buffer#end_iter;
173 buffer#apply_tag Tags.Script.edit_zone
174 ~start:(get_start()) ~stop:(get_stop())
175 end in
176 let processed_sentence_just_before_error it =
177 let rec aux old it =
178 if it#is_start then None
179 else if it#has_tag Tags.Script.processed then Some old
180 else if it#has_tag Tags.Script.error_bg then aux it it#backward_char
181 else None in
182 aux it it#copy in
183 let insert_cb it s = if String.length s = 0 then () else begin
184 if misc () then Minilib.log ("insert_cb " ^ string_of_int it#offset);
185 let () = update_prev it in
186 let iter =
187 if it#has_tag Tags.Script.processed then Some it
188 else if it#has_tag Tags.Script.error_bg then
189 processed_sentence_just_before_error it
190 else None
191 in
192 handle_iter rocqtop rocqops buffer iter action_stack
193 end
194 in
195 let delete_cb ~start ~stop =
196 if misc () then Minilib.log (Printf.sprintf "delete_cb %d %d" start#offset stop#offset);
197 let min_iter, max_iter =
198 if start#compare stop < 0 then start, stop else stop, start in
199 let () = update_prev min_iter in
200 let rec aux iter =
201 if iter#equal max_iter then None
202 else if iter#has_tag Tags.Script.processed then
203 Some min_iter#backward_char
204 else if iter#has_tag Tags.Script.error_bg then
205 processed_sentence_just_before_error iter
206 else aux iter#forward_char
207 in
208 let iter = aux min_iter in
209 handle_iter rocqtop rocqops buffer iter action_stack
210 in
211 let begin_action_cb () =
212 let () = if misc () then Minilib.log "begin_action_cb" in
213 let () = init_user_action action_stack in
214 let where = get_insert () in
215 buffer#move_mark (`NAME "prev_insert") ~where
216 in
217 let end_action_cb () =
218 let () = if misc () then Minilib.log "end_action_cb" in
219 let marks = close_user_action action_stack in
220 let () = ensure_marks_exist () in
221 if CList.is_empty marks then
222 let start, stop = get_start (), get_stop () in
223 let () = List.iter (fun tag -> buffer#remove_tag tag ~start ~stop) Tags.Script.ephemere in
224 Sentence.tag_on_insert buffer
225 else
226 (* If Rocq was asked to backtrack, the cleanup must be done by the
227 backtrack_until function, since it may move the stop_of_input
228 to a point indicated by RocqDriver. *)
229 let iters = List.map (fun mark ->
230 match mark with
231 | Mark mark -> buffer#get_iter_at_mark (`MARK mark)
232 | Begin -> buffer#start_iter
233 ) marks in
234 let iter = List.hd @@ List.sort (fun it1 it2 -> it1#compare it2) iters in
235 let () = List.iter (fun mark ->
236 try match mark with
237 | Mark mark -> buffer#delete_mark (`MARK mark)
238 | Begin -> let action = RocqDriver.seq (rocqops#backtrack_to_begin ())
239 (RocqDriver.lift (fun () -> Sentence.tag_on_insert buffer)) in
240 ignore @@ RocqDriver.try_grab rocqtop action (fun () -> ())
241 with GText.No_such_mark _ -> ()) marks in
242 call_rocq_or_cancel_action rocqtop rocqops buffer iter
243 in
244 let mark_deleted_cb m =
245 match GtkText.Mark.get_name m with
246 | Some "insert" -> ()
247 | Some s -> if misc () then Minilib.log (s^" deleted")
248 | None -> ()
249 in
250 let mark_set_cb it m =
251 debug_edit_zone ();
252 let ins = get_insert () in
253 let () = Ideutils.display_location ins in
254 match GtkText.Mark.get_name m with
255 | Some "insert" -> ()
256 | Some s -> if misc () then Minilib.log (s^" moved")
257 | None -> ()
258 in
259 let set_busy b =
260 let prop = `EDITABLE b in
261 let tags = [Tags.Script.processed] in
262 List.iter (fun tag -> tag#set_property prop) tags
263 in
264 (* Pluging callbacks *)
265 let () = RocqDriver.setup_script_editable rocqtop set_busy in
266 let _ = buffer#connect#insert_text ~callback:insert_cb in
267 let _ = buffer#connect#delete_range ~callback:delete_cb in
268 let _ = buffer#connect#begin_user_action ~callback:begin_action_cb in
269 let _ = buffer#connect#end_user_action ~callback:end_action_cb in
270 let _ = buffer#connect#after#mark_set ~callback:mark_set_cb in
271 let _ = buffer#connect#after#mark_deleted ~callback:mark_deleted_cb in
272 ()
273
274 let find_int_col s l =
275 match List.assoc s l with `IntC c -> c | _ -> assert false
276
277 let find_string_col s l =
278 match List.assoc s l with `StringC c -> c | _ -> assert false
279
280 let make_table_widget ?sort cd cb =
281 let frame = GBin.scrolled_window ~hpolicy:`NEVER ~vpolicy:`AUTOMATIC () in
282 let columns, store =
283 let cols = new GTree.column_list in
284 let columns = List.map (function
285 | (`Int,n,_) -> n, `IntC (cols#add Gobject.Data.int)
286 | (`String,n,_) -> n, `StringC (cols#add Gobject.Data.string))
287 cd in
288 columns, GTree.list_store cols in
289 let data = GTree.view
290 ~vadjustment:frame#vadjustment ~hadjustment:frame#hadjustment
291 ~rules_hint:true ~headers_visible:false
292 ~model:store ~packing:frame#add () in
293 let () = data#set_headers_visible true in
294 let () = data#set_headers_clickable true in
295 (* FIXME: handle this using CSS *)
296 (* let refresh clr = data#misc#modify_bg [`NORMAL, `NAME clr] in *)
297 (* let _ = background_color#connect#changed ~callback:refresh in *)
298 (* let _ = data#misc#connect#realize ~callback:(fun () -> refresh background_color#get) in *)
299 let button_cb () =
300 let path, col = data#get_cursor () in
301 match path, col with
302 | Some path, Some col ->
303 let iter = store#get_iter path in
304 let map (_, c) = match c with
305 | `IntC c -> string_of_int (store#get ~row:iter ~column:c)
306 | `StringC c -> store#get ~row:iter ~column:c
307 in
308 let data = String.concat " " (List.map map columns) in
309 GMain.clipboard#set_text data
310 | _ -> ()
311 in
312 let callback ev =
313 let button = GdkEvent.Button.button ev in
314 if Int.equal button 3 then
315 let menu = GMenu.menu () in
316 let item = GMenu.menu_item ~label:"Copy" () in
317 let (_ : GtkSignal.id) = item#connect#activate ~callback:button_cb in
318 let () = menu#add item in
319 let _ = menu#popup ~button ~time:(GdkEvent.Button.time ev) in
320 false
321 else false
322 in
323 let (_ : GtkSignal.id) = data#event#connect#button_press ~callback in
324 let mk_rend c = GTree.cell_renderer_text [], ["text",c] in
325 let cols =
326 List.map2 (fun (_,c) (_,n,v) ->
327 let c = match c with
328 | `IntC c -> GTree.view_column ~renderer:(mk_rend c) ()
329 | `StringC c -> GTree.view_column ~renderer:(mk_rend c) () in
330 c#set_title n;
331 c#set_visible v;
332 c#set_sizing `AUTOSIZE;
333 c)
334 columns cd in
335 let make_sorting i (_, c) =
336 let sort (store : GTree.model) it1 it2 = match c with
337 | `IntC c ->
338 compare (store#get ~row:it1 ~column:c) (store#get ~row:it2 ~column:c)
339 | `StringC c ->
340 compare (store#get ~row:it1 ~column:c) (store#get ~row:it2 ~column:c)
341 in
342 store#set_sort_func i sort
343 in
344 CList.iteri make_sorting columns;
345 CList.iteri (fun i c -> c#set_sort_column_id i) cols;
346 List.iter (fun c -> ignore(data#append_column c)) cols;
347 ignore(
348 data#connect#row_activated ~callback:(fun tp vc -> cb columns store tp vc)
349 );
350 let () = match sort with None -> () | Some (i, t) -> store#set_sort_column_id i t in
351 frame, (fun f -> f columns store)
352
353 let create_errpage ~kind (script : Wg_ScriptView.script_view) : errpage =
354 let table, access =
355 make_table_widget ~sort:(0, `ASCENDING)
356 [`Int,"Line",true; `String, kind, true]
357 (fun columns store tp vc ->
358 let row = store#get_iter tp in
359 let lno = store#get ~row ~column:(find_int_col "Line" columns) in
360 let where = script#buffer#get_iter (`LINE (lno-1)) in
361 script#buffer#place_cursor ~where;
362 script#misc#grab_focus ();
363 ignore (script#scroll_to_iter
364 ~use_align:false ~yalign:0.75 ~within_margin:0.25 where)) in
365 let tip = GMisc.label ~text:"Double click to jump to line" () in
366 let box = GPack.vbox ~homogeneous:false () in
367 let () = box#pack ~expand:true table#coerce in
368 let () = box#pack ~expand:false ~padding:2 tip#coerce in
369 let last_update = ref [] in
370 let callback = ref (fun _ -> ()) in
371 object (self)
372 inherit GObj.widget box#as_widget
373 method update errs =
374 if !last_update = errs then ()
375 else begin
376 last_update := errs;
377 access (fun _ store -> store#clear ());
378 !callback errs;
379 List.iter (fun (lno, msg) -> access (fun columns store ->
380 let line = store#append () in
381 store#set ~row:line ~column:(find_int_col "Line" columns) lno;
382 store#set ~row:line ~column:(find_string_col kind columns) msg))
383 errs
384 end
385 method on_update ~callback:cb = callback := cb
386 method data = !last_update
387 end
388
389 let create_jobpage rocqtop rocqops : jobpage =
390 let table, access =
391 make_table_widget ~sort:(0, `ASCENDING)
392 [`String,"Worker",true; `String,"Job name",true]
393 (fun columns store tp vc ->
394 let row = store#get_iter tp in
395 let w = store#get ~row ~column:(find_string_col "Worker" columns) in
396 let info () = Minilib.log ("Rocq busy, discarding query") in
397 ignore @@ RocqDriver.try_grab rocqtop (rocqops#stop_worker w) info
398 ) in
399 let tip = GMisc.label ~text:"Double click to interrupt worker" () in
400 let box = GPack.vbox ~homogeneous:false () in
401 let () = box#pack ~expand:true table#coerce in
402 let () = box#pack ~expand:false ~padding:2 tip#coerce in
403 let last_update = ref CString.Map.empty in
404 let callback = ref (fun _ -> ()) in
405 object (self)
406 inherit GObj.widget box#as_widget
407 method update jobs =
408 if !last_update = jobs then ()
409 else begin
410 last_update := jobs;
411 access (fun _ store -> store#clear ());
412 !callback jobs;
413 CString.Map.iter (fun id job -> access (fun columns store ->
414 let column = find_string_col "Worker" columns in
415 if job = "Dead" then
416 store#foreach (fun _ row ->
417 if store#get ~row ~column = id then store#remove row || true
418 else false)
419 else
420 let line = store#append () in
421 store#set ~row:line ~column id;
422 store#set ~row:line ~column:(find_string_col "Job name" columns) job))
423 jobs
424 end
425 method on_update ~callback:cb = callback := cb
426 method data = !last_update
427 end
428
429 let create_proof () =
430 let proof = Wg_ProofView.proof_view () in
431 let _ = proof#misc#set_can_focus true in
432 let _ = GtkBase.Widget.add_events proof#as_widget
433 [`ENTER_NOTIFY;`POINTER_MOTION]
434 in
435 proof
436
437 let dummy_control : control =
438 object
439 method detach () = ()
440 end
441
442 let to_abs_file_name f =
443 if Filename.is_relative f then Filename.concat (Unix.getcwd ()) f else f
444
445 let create file rocqtop_args =
446 let (basename, abs_file_name) = match file with
447 | None -> ("*scratch*", None)
448 | Some f -> (Glib.Convert.filename_to_utf8 Filename.(remove_extension (basename f)),
449 Some (to_abs_file_name f))
450 in
451 let rocqtop = RocqDriver.spawn_rocqtop basename rocqtop_args in
452 let reset () = RocqDriver.reset_rocqtop rocqtop in
453 let buffer = create_buffer () in
454 let script = create_script rocqtop buffer in
455 let proof = create_proof () in
456 incr next_sid;
457 let sid = !next_sid in
458 let create_messages () =
459 let messages = Wg_MessageView.message_view sid in
460 let _ = messages#misc#set_can_focus true in
461 Wg_RoutedMessageViews.message_views ~route_0:messages
462 in
463 let messages = create_messages () in
464 let segment = new Wg_Segment.segment () in
465 let finder = new Wg_Find.finder basename (script :> GText.view) in
466 let debugger = Wg_Debugger.debugger (Printf.sprintf "Debugger (%s)" basename) sid in
467 let fops = new FileOps.fileops (buffer :> GText.buffer) file reset in
468 let _ = fops#update_stats in
469 let rops =
470 new RocqOps.rocqops script proof messages segment rocqtop (fun () -> fops#filename) in
471 let command = new Wg_Command.command_window basename rocqtop rops messages sid in
472 let errpage = create_errpage ~kind:"Error" script in
473 let warnpage = create_errpage ~kind:"Warning" script in
474 let jobpage = create_jobpage rocqtop rops in
475 let _ = set_buffer_handlers (buffer :> GText.buffer) script rops rocqtop in
476 let _ = RocqDriver.set_reset_handler rocqtop rops#handle_reset_initial in
477 let _ = RocqDriver.init_rocqtop rocqtop rops#initialize in
478 let tab_label = GMisc.label ~text:basename () in
479 (* todo: ugly custom tooltips...*)
480 (*
481 tab_label#misc#set_size_request ~height:100 ~width:200 ();
482 tab_label#misc#modify_bg [`NORMAL, `NAME "#FF0000"];
483 (match abs_file_name with
484 | Some f ->
485 GtkBase.Widget.Tooltip.set_markup tab_label#as_widget
486 ("<span background=\"yellow\" foreground=\"black\">" ^ f ^ "</span>");
487 let label2 = GMisc.label ~text:"hello?" () in
488 GtkBase.Tooltip.set_custom (label2#coerce : Gtk.tooltip) label
489 | None -> ());
490 *)
491 {
492 buffer = (buffer :> GText.buffer);
493 script=script;
494 proof=proof;
495 messages=messages;
496 segment=segment;
497 fileops=fops;
498 rocqops=rops;
499 rocqtop=rocqtop;
500 command=command;
501 finder=finder;
502 debugger=debugger;
503 tab_label= tab_label;
504 errpage;
505 warnpage;
506 jobpage=jobpage;
507 sid=sid;
508 basename = basename;
509 control = dummy_control;
510 abs_file_name = abs_file_name;
511 debug_stop_pt = None;
512 breakpoints = [];
513 last_db_goals = Pp.mt ()
514 }
515
516 let kill (sn:session) =
517 (* To close the detached views of this script, we call manually
518 [destroy] on it, triggering some callbacks in [detach_view].
519 In a more modern lablgtk, rather use the page-removed signal ? *)
520 sn.rocqops#destroy ();
521 sn.script#destroy ();
522 RocqDriver.close_rocqtop sn.rocqtop
523
524 let window_size = ref (window_width#get, window_height#get)
525
526 let build_layout (sn:session) =
527 let debugger_paned = GPack.paned `VERTICAL () in
528 let debugger_box =
529 GPack.vbox ~packing:(debugger_paned#pack2 ~shrink:false ~resize:true) ()
530 in
531
532 let session_paned = GPack.paned `VERTICAL
533 ~packing:(debugger_paned#pack1 ~shrink:false ~resize:true) () in
534 let session_box =
535 GPack.vbox ~packing:(session_paned#pack1 ~shrink:false ~resize:true) ()
536 in
537
538 (* Left part of the window. *)
539
540 let eval_paned = GPack.paned `HORIZONTAL ~border_width:5
541 ~packing:(session_box#pack ~expand:true) () in
542 let script_frame = GBin.frame ~shadow_type:`IN
543 ~packing:(eval_paned#pack1 ~shrink:false) () in
544 let script_scroll = GBin.scrolled_window
545 ~vpolicy:`AUTOMATIC ~hpolicy:`AUTOMATIC ~packing:script_frame#add () in
546
547 (* Right part of the window *)
548
549 let state_paned = GPack.paned `VERTICAL
550 ~packing:(eval_paned#pack2 ~shrink:true) () in
551
552 (* Proof buffer. *)
553
554 let title = Printf.sprintf "Proof (%s)" sn.tab_label#text in
555 let proof_detachable = Wg_Detachable.detachable ~title () in
556 let () = proof_detachable#button#misc#hide () in
557 let () = proof_detachable#frame#set_shadow_type `IN in
558 let () = state_paned#pack1 ~shrink:true proof_detachable#coerce in
559 let proof_scroll = GBin.scrolled_window
560 ~vpolicy:`AUTOMATIC ~hpolicy:`AUTOMATIC ~packing:proof_detachable#pack () in
561 let callback _ = proof_detachable#show;
562 proof_scroll#coerce#misc#set_size_request ~width:0 ~height:0 ()
563 in
564 let () = proof_detachable#connect#attached ~callback in
565 let callback _ =
566 proof_scroll#coerce#misc#set_size_request ~width:500 ~height:400 ()
567 in
568 let () = proof_detachable#connect#detached ~callback in
569
570 (* Message buffer. *)
571
572 let message_frame = GPack.notebook ~packing:(state_paned#pack2 ~shrink:true) () in
573 let add_msg_page pos name text (w : GObj.widget) =
574 let detachable =
575 Wg_Detachable.detachable ~title:(text^" ("^name^")") () in
576 detachable#add w#coerce;
577 let label = GPack.hbox ~spacing:5 () in
578 let lbl = GMisc.label ~text ~packing:label#add () in
579 let but = GButton.button () in
580 but#add (GMisc.label ~markup:"<small>↗</small>" ())#coerce;
581 label#add but#coerce;
582 ignore(message_frame#insert_page ~pos
583 ~tab_label:label#coerce detachable#coerce);
584 ignore(but#connect#clicked ~callback:(fun _ ->
585 message_frame#remove_page (message_frame#page_num detachable#coerce);
586 detachable#button#clicked ()));
587 detachable#connect#detached ~callback:(fun _ ->
588 if message_frame#all_children = [] then message_frame#misc#hide ();
589 w#misc#set_size_request ~width:500 ~height:400 ());
590 detachable#connect#attached ~callback:(fun _ ->
591 w#misc#set_size_request ~width:1 ~height:1 (); (* force resize *)
592 ignore(message_frame#insert_page ~pos
593 ~tab_label:label#coerce detachable#coerce);
594 message_frame#misc#show ();
595 detachable#show);
596 detachable#button#misc#hide ();
597 detachable, lbl in
598 let session_tab = GPack.hbox ~homogeneous:false () in
599 let img = GMisc.image ~icon_size:`SMALL_TOOLBAR
600 ~packing:session_tab#pack () in
601 let _ =
602 sn.buffer#connect#modified_changed
603 ~callback:(fun () -> if sn.buffer#modified
604 then img#set_stock `SAVE
605 else img#set_stock `YES) in
606 (* There was an issue in the previous implementation for setting the
607 position of the handle. It was using the size_allocate event but
608 there is an issue with size_allocate. G. Melquiond analyzed that
609 at starting time, the size_allocate event is only issued in
610 Layout phase of the gtk loop so that it is actually processed
611 only in the next iteration of the event-update-layout-paint loop,
612 after the user does something and trigger an effective new event
613 (see #10578). So we preventively enforce an estimated position
614 for the handles to be used in the very first initializing
615 iteration of the loop *)
616 let () =
617 (* 14 is the estimated size for vertical borders *)
618 let estimated_vertical_handle_position = (fst !window_size - 14) / 2 in
619 (* 169 is the estimated size for menus, command line, horizontal border *)
620 let estimated_horizontal_handle_position = (snd !window_size - 169) / 2 in
621 if estimated_vertical_handle_position > 0 then
622 eval_paned#set_position estimated_vertical_handle_position;
623 if estimated_horizontal_handle_position > 0 then
624 state_paned#set_position estimated_horizontal_handle_position in
625 session_box#pack sn.finder#coerce;
626 debugger_box#add sn.debugger#coerce;
627 sn.debugger#hide ();
628 (sn.messages#route 0)#set_forward_show_debugger sn.debugger#show;
629 sn.debugger#set_forward_paned_pos (fun pos -> debugger_paned#set_position pos);
630 (* segment should not be in the debugger box *)
631 debugger_box#pack ~expand:false ~fill:false sn.segment#coerce;
632 debugger_paned#set_position 1000000;
633 sn.command#pack_in (session_paned#pack2 ~shrink:false ~resize:false);
634 script_scroll#add sn.script#coerce;
635 proof_scroll#add sn.proof#coerce;
636 let detach, _ = add_msg_page 0 sn.tab_label#text "Messages" sn.messages#default_route#coerce in
637 let _, errlabel = add_msg_page 1 sn.tab_label#text "Errors" sn.errpage#coerce in
638 let _, warnlabel = add_msg_page 2 sn.tab_label#text "Warnings" sn.warnpage#coerce in
639 let _, _ = add_msg_page 3 sn.tab_label#text "Jobs" sn.jobpage#coerce in
640 (* When a message is received, focus on the message pane *)
641 let _ =
642 sn.messages#default_route#connect#pushed ~callback:(fun _ _ ->
643 let num = message_frame#page_num detach#coerce in
644 if 0 <= num then message_frame#goto_page num
645 )
646 in
647 let set_label_color_on_update color page label =
648 let txt = label#text in
649 let red s = Printf.sprintf "<span foreground=\"%s\">%s</span>" color s in
650 page#on_update ~callback:(fun l ->
651 if l = [] then (label#set_use_markup false; label#set_text txt)
652 else (label#set_text (red txt);label#set_use_markup true));
653 in
654 (* When an error occurs, paint the error label in red *)
655 let () = set_label_color_on_update "#FF0000" sn.errpage errlabel in
656 (* When a warning occurs, paint the warning label in orange *)
657 let () = set_label_color_on_update "#FFA500" sn.warnpage warnlabel in
658 session_tab#pack sn.tab_label#coerce;
659 img#set_stock `YES;
660 let control =
661 object
662 method detach () = proof_detachable#detach ()
663 end
664 in
665 let () = sn.control <- control in
666 (Some session_tab#coerce,None,debugger_paned#coerce)