| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Util |
| 12 |
open Preferences |
| 13 |
open Ideutils |
| 14 |
|
| 15 |
type goals = |
| 16 |
| NoGoals |
| 17 |
| FocusGoals of { fg : Interface.goal list; bg : Interface.goal list } |
| 18 |
| NoFocusGoals of { |
| 19 |
bg : Interface.goal list; |
| 20 |
shelved : Interface.goal list; |
| 21 |
given_up : Interface.goal list; |
| 22 |
} |
| 23 |
|
| 24 |
class type proof_view = |
| 25 |
object |
| 26 |
inherit GObj.widget |
| 27 |
method source_buffer : GSourceView3.source_buffer |
| 28 |
method buffer : GText.buffer |
| 29 |
method select_all : unit -> unit |
| 30 |
method refresh : force:bool -> unit |
| 31 |
method clear : unit -> unit |
| 32 |
method set_goals : goals -> unit |
| 33 |
method set_debug_goal : Pp.t -> unit |
| 34 |
end |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
let hook_tag_cb tag menu_content sel_cb hover_cb = |
| 42 |
ignore (tag#connect#event ~callback: |
| 43 |
(fun ~origin evt it -> |
| 44 |
let iter = new GText.iter it in |
| 45 |
let start = iter#backward_to_tag_toggle (Some tag) in |
| 46 |
let stop = iter#forward_to_tag_toggle (Some tag) in |
| 47 |
match GdkEvent.get_type evt with |
| 48 |
| `BUTTON_PRESS -> |
| 49 |
let ev = GdkEvent.Button.cast evt in |
| 50 |
if (GdkEvent.Button.button ev) <> 3 then false else begin |
| 51 |
let ctxt_menu = GMenu.menu () in |
| 52 |
let factory = new GMenu.factory ctxt_menu in |
| 53 |
List.iter |
| 54 |
(fun (text,cmd) -> ignore (factory#add_item text ~callback:(sel_cb cmd))) |
| 55 |
menu_content; |
| 56 |
ctxt_menu#popup ~button:3 ~time:(GdkEvent.Button.time ev); |
| 57 |
true |
| 58 |
end |
| 59 |
| `MOTION_NOTIFY -> |
| 60 |
hover_cb start stop; false |
| 61 |
| _ -> false)) |
| 62 |
|
| 63 |
let mode_tactic sel_cb (proof : #GText.view_skel) goals ~unfoc_goals hints = match goals with |
| 64 |
| [] -> assert false |
| 65 |
| { Interface.goal_hyp = hyps; Interface.goal_ccl = cur_goal; Interface.goal_name = cur_name } :: rem_goals -> |
| 66 |
let on_hover sel_start sel_stop = |
| 67 |
proof#buffer#remove_tag |
| 68 |
~start:proof#buffer#start_iter |
| 69 |
~stop:sel_start |
| 70 |
Tags.Proof.highlight; |
| 71 |
proof#buffer#remove_tag |
| 72 |
~start:sel_stop |
| 73 |
~stop:proof#buffer#end_iter |
| 74 |
Tags.Proof.highlight; |
| 75 |
proof#buffer#apply_tag ~start:sel_start ~stop:sel_stop Tags.Proof.highlight |
| 76 |
in |
| 77 |
let goals_cnt = List.length rem_goals + 1 in |
| 78 |
let head_str = Printf.sprintf |
| 79 |
"%d goal%s\n" goals_cnt (if 1 < goals_cnt then "s" else "") |
| 80 |
in |
| 81 |
let goal_str ?(shownum=false) index total name = |
| 82 |
let annot = |
| 83 |
match name with |
| 84 |
| Some id -> Printf.sprintf "(?%s)" id |
| 85 |
| None -> if shownum then Printf.sprintf "(%d/%d)" index total else "" in |
| 86 |
Printf.sprintf "______________________________________%s\n" annot |
| 87 |
in |
| 88 |
|
| 89 |
let hyps_hints, goal_hints = match hints with |
| 90 |
| None -> [], [] |
| 91 |
| Some (hl, h) -> (hl, h) |
| 92 |
in |
| 93 |
let width = Ideutils.textview_width proof in |
| 94 |
let rec insert_hyp hints hs = match hs with |
| 95 |
| [] -> () |
| 96 |
| hyp :: hs -> |
| 97 |
let tags, rem_hints = match hints with |
| 98 |
| [] -> [], [] |
| 99 |
| hint :: hints -> |
| 100 |
let tag = proof#buffer#create_tag [] in |
| 101 |
let () = hook_tag_cb tag hint sel_cb on_hover in |
| 102 |
[tag], hints |
| 103 |
in |
| 104 |
let () = insert_xml ~tags proof#buffer (Richpp.richpp_of_pp ~width hyp) in |
| 105 |
proof#buffer#insert "\n"; |
| 106 |
insert_hyp rem_hints hs |
| 107 |
in |
| 108 |
let () = proof#buffer#insert head_str in |
| 109 |
let () = insert_hyp hyps_hints hyps in |
| 110 |
let () = |
| 111 |
let _ = if goal_hints <> [] then |
| 112 |
let tag = proof#buffer#create_tag [] in |
| 113 |
let () = hook_tag_cb tag goal_hints sel_cb on_hover in |
| 114 |
[tag] |
| 115 |
else [] |
| 116 |
in |
| 117 |
proof#buffer#insert (goal_str ~shownum:true 1 goals_cnt cur_name); |
| 118 |
insert_xml ~tags:[Tags.Proof.goal] proof#buffer (Richpp.richpp_of_pp ~width cur_goal); |
| 119 |
proof#buffer#insert "\n" |
| 120 |
in |
| 121 |
|
| 122 |
let fold_goal ?(shownum=false) i _ { Interface.goal_ccl = g; Interface.goal_name = name } = |
| 123 |
proof#buffer#insert (goal_str ~shownum i goals_cnt name); |
| 124 |
insert_xml proof#buffer (Richpp.richpp_of_pp ~width g); |
| 125 |
proof#buffer#insert "\n" |
| 126 |
in |
| 127 |
let () = Util.List.fold_left_i (fold_goal ~shownum:true) 2 () rem_goals in |
| 128 |
|
| 129 |
|
| 130 |
if RocqDriver.PrintOpt.printing_unfocused () then |
| 131 |
begin |
| 132 |
ignore(proof#buffer#place_cursor ~where:(proof#buffer#end_iter)); |
| 133 |
if unfoc_goals<>[] then |
| 134 |
begin |
| 135 |
proof#buffer#insert "\nUnfocused Goals:\n"; |
| 136 |
Util.List.fold_left_i (fold_goal ~shownum:false) 0 () unfoc_goals |
| 137 |
end |
| 138 |
end; |
| 139 |
ignore(proof#buffer#place_cursor |
| 140 |
~where:(proof#buffer#end_iter#backward_to_tag_toggle |
| 141 |
(Some Tags.Proof.goal))); |
| 142 |
ignore(proof#scroll_to_mark `INSERT) |
| 143 |
|
| 144 |
let display mode (view : #GText.view_skel) goals hints = |
| 145 |
let () = view#buffer#set_text "" in |
| 146 |
let width = Ideutils.textview_width view in |
| 147 |
match goals with |
| 148 |
| NoGoals -> () |
| 149 |
|
| 150 |
| FocusGoals { fg; bg } -> |
| 151 |
mode view fg ~unfoc_goals:bg hints |
| 152 |
| NoFocusGoals { bg; shelved; given_up } -> |
| 153 |
begin match (bg, shelved, given_up) with |
| 154 |
| [], [], [] -> |
| 155 |
view#buffer#insert "All goals completed." |
| 156 |
| [], [], _ -> |
| 157 |
|
| 158 |
view#buffer#insert "All goals completed except some admitted goals:\n\n"; |
| 159 |
let iter goal = |
| 160 |
insert_xml view#buffer (Richpp.richpp_of_pp ~width goal.Interface.goal_ccl); |
| 161 |
view#buffer#insert "\n" |
| 162 |
in |
| 163 |
List.iter iter given_up; |
| 164 |
view#buffer#insert "\nYou need to go back and solve them." |
| 165 |
| [], _, _ -> |
| 166 |
|
| 167 |
view#buffer#insert "All the remaining goals are on the shelf:\n\n"; |
| 168 |
let iter goal = |
| 169 |
insert_xml view#buffer (Richpp.richpp_of_pp ~width goal.Interface.goal_ccl); |
| 170 |
view#buffer#insert "\n" |
| 171 |
in |
| 172 |
List.iter iter shelved |
| 173 |
| _, _, _ -> |
| 174 |
|
| 175 |
let total = List.length bg in |
| 176 |
let goal_str index id = |
| 177 |
let annot = |
| 178 |
if Option.has_some (int_of_string_opt id) then Printf.sprintf "(%d/%d)" index total |
| 179 |
else Printf.sprintf "(?%s)" id in |
| 180 |
Printf.sprintf |
| 181 |
"______________________________________%s\n" annot |
| 182 |
in |
| 183 |
view#buffer#insert "This subproof is complete, but there are some unfocused goals:\n\n"; |
| 184 |
let iter i goal = |
| 185 |
let () = view#buffer#insert (goal_str (succ i) goal.Interface.goal_id) in |
| 186 |
insert_xml view#buffer (Richpp.richpp_of_pp ~width goal.Interface.goal_ccl); |
| 187 |
view#buffer#insert "\n" |
| 188 |
in |
| 189 |
List.iteri iter bg |
| 190 |
end |
| 191 |
|
| 192 |
|
| 193 |
let proof_view () = |
| 194 |
let buffer = GSourceView3.source_buffer |
| 195 |
~highlight_matching_brackets:true |
| 196 |
~tag_table:Tags.Proof.table |
| 197 |
?style_scheme:(style_manager#style_scheme source_style#get) () |
| 198 |
in |
| 199 |
let text_buffer = new GText.buffer buffer#as_buffer in |
| 200 |
let view = GSourceView3.source_view |
| 201 |
~source_buffer:buffer ~editable:false ~wrap_mode:`WORD () |
| 202 |
in |
| 203 |
let () = Gtk_parsing.fix_double_click view in |
| 204 |
let default_clipboard = GData.clipboard Gdk.Atom.primary in |
| 205 |
let _ = buffer#add_selection_clipboard default_clipboard in |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
let cb ft = view#misc#modify_font (GPango.font_description_from_string ft) in |
| 211 |
stick text_font view cb; |
| 212 |
|
| 213 |
let pf = object(self) |
| 214 |
inherit GObj.widget view#as_widget |
| 215 |
val mutable goals = NoGoals |
| 216 |
val mutable debug_goal = None |
| 217 |
val mutable last_width = -1 |
| 218 |
|
| 219 |
method source_buffer = buffer |
| 220 |
|
| 221 |
method buffer = text_buffer |
| 222 |
|
| 223 |
method select_all () = |
| 224 |
if self#is_focus then |
| 225 |
self#buffer#select_range self#buffer#start_iter self#buffer#end_iter; |
| 226 |
|
| 227 |
method clear () = buffer#set_text "" |
| 228 |
|
| 229 |
method set_goals gls = goals <- gls; debug_goal <- None |
| 230 |
|
| 231 |
method set_debug_goal msg = |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
self#clear (); |
| 236 |
debug_goal <- Some msg; |
| 237 |
let tags = [] in |
| 238 |
let width = Ideutils.textview_width view in |
| 239 |
Ideutils.insert_xml buffer ~tags (Richpp.richpp_of_pp ~width msg); |
| 240 |
|
| 241 |
method refresh ~force = |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
let width = Ideutils.textview_width view in |
| 247 |
|
| 248 |
|
| 249 |
let needed = force || last_width <> width in |
| 250 |
if needed then begin |
| 251 |
last_width <- width; |
| 252 |
match debug_goal with |
| 253 |
| None -> |
| 254 |
let dummy _ () = () in |
| 255 |
display (mode_tactic dummy) view goals None |
| 256 |
| Some msg -> self#set_debug_goal msg |
| 257 |
end |
| 258 |
end |
| 259 |
in |
| 260 |
|
| 261 |
|
| 262 |
let w_cb _ = pf#refresh ~force:false in |
| 263 |
ignore (view#misc#connect#size_allocate ~callback:w_cb); |
| 264 |
pf |