Debian Codegraph @

ide/rocqide/wg_Detachable.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 class type detachable_signals =
12 object
13 inherit GContainer.container_signals
14 method attached : callback:(GObj.widget -> unit) -> unit
15 method detached : callback:(GObj.widget -> unit) -> unit
16 end
17
18 class detachable (obj : [> Gtk.box] Gobject.obj) =
19
20 object(self)
21 inherit GPack.box_skel (obj :> Gtk.box Gobject.obj) as super
22
23 val but = GButton.button ()
24 val close_but = GButton.button ()
25 val win = GWindow.window ~type_hint:`DIALOG ()
26 val frame = GBin.frame ~shadow_type:`NONE ()
27 val mutable detached = false
28 val mutable detached_cb = (fun _ -> ())
29 val mutable attached_cb = (fun _ -> ())
30
31 method child = frame#child
32 method! add = frame#add
33 method! pack ?from ?expand ?fill ?padding w =
34 if frame#all_children = [] then self#add w
35 else raise (Invalid_argument "detachable#pack")
36
37 method title = win#title
38 method set_title = win#set_title
39
40 method connect : detachable_signals = object
41 inherit GContainer.container_signals_impl obj
42 method attached ~callback = attached_cb <- callback
43 method detached ~callback = detached_cb <- callback
44 end
45
46 method show =
47 if detached then win#present ()
48 else self#misc#show ();
49
50 method hide =
51 if detached then win#misc#hide ()
52 else self#misc#hide ()
53
54 method! visible = win#misc#visible || self#misc#visible
55
56 method win = win
57
58 method frame = frame
59
60 method button = but
61
62 method close_button = close_but
63
64 method attach () =
65 win#misc#hide ();
66 frame#misc#reparent self#coerce;
67 detached <- false;
68 attached_cb self#child
69
70 method detach () =
71 frame#misc#reparent win#coerce;
72 self#misc#hide ();
73 win#present ();
74 detached <- true;
75 detached_cb self#child
76
77 initializer
78 let vb = GPack.vbox ~packing:(super#pack ~expand:false ~fill:false) () in
79 close_but#add (Ideutils.stock_to_widget ~size:(`CUSTOM(12,12)) `CLOSE);
80 close_but#misc#hide ();
81 ignore(close_but#connect#clicked ~callback:(fun _ -> self#misc#hide (); win#misc#hide ()));
82 self#set_homogeneous false;
83 vb#pack ~expand:false close_but#coerce;
84 vb#pack ~expand:false but#coerce;
85 super#pack ~expand:true ~fill:true frame#coerce;
86 win#misc#hide ();
87 but#add (GMisc.label
88 ~markup:"<span size='x-small'>D\nE\nT\nA\nC\nH</span>" ())#coerce;
89 ignore(win#event#connect#delete ~callback:(fun _ -> self#attach (); true));
90 ignore(but#connect#clicked ~callback:(fun _ -> self#detach ()))
91
92 end
93
94 let detachable ?title =
95 GtkPack.Box.make_params [] ~cont:(
96 GContainer.pack_container
97 ~create:(fun p ->
98 let d = new detachable (GtkPack.Box.create `HORIZONTAL p) in
99 Option.iter d#set_title title;
100 d))