123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207(**************************************************************************)(* *)(* This file is part of WP plug-in of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* CEA (Commissariat a l'energie atomique et aux energies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)openConditionsopenLang.FopenPtipmoduleF=Lang.FmoduleEnv=Plang.EnvmoduleImap=Qed.Intmap(* -------------------------------------------------------------------------- *)(* --- Printer --- *)(* -------------------------------------------------------------------------- *)classfocused(wtext:Wtext.text)=letparts:partWtext.marker=wtext#markerinletterms:termWtext.marker=wtext#markerinletfocus:termWtext.marker=wtext#markerinletbutton:(unit->unit)Wtext.marker=wtext#markerinlettarget:termWtext.marker=wtext#markerinlettarget_part:partWtext.marker=wtext#markerinletautofocus=newautofocusinletplang=newplang~terms~focus~target~autofocusinletpcond=newpcond~parts~target:target_part~autofocus~planginletpopup=newWidget.popup()inobject(self)inheritpseq~autofocus~plang~pcondassupervalmutableitems=[]valmutabletargeted=[]valmutableallparts:partWtext.entrylist=[]initializerbeginwtext#set_font"Monospace";wtext#set_css["wp:clause",[`WEIGHT`BOLD];"wp:comment",[`FOREGROUND"darkgreen"];"wp:property",[`FOREGROUND"blue"];"wp:label",[`FOREGROUND"darkgreen"];"wp:stmt",[`WEIGHT`BOLD;`FOREGROUND"darkgreen"];"wp:var",[`STYLE`ITALIC];];terms#set_hover[`BACKGROUND"lightblue"];parts#set_hover[`BACKGROUND"lightgreen"];focus#set_style[`BACKGROUND"wheat"];button#set_style[`BACKGROUND"lightblue"];button#set_hover[`BACKGROUND"orange"];button#on_click(fun(_,_,cb)->cb());target_part#set_style[`BACKGROUND"orange"];target#set_style[`BACKGROUND"orange"];parts#on_clickself#on_part;parts#on_right_clickself#on_popup_part;terms#on_click(self#on_term~extend:false);terms#on_shift_click(self#on_term~extend:true);terms#on_right_clickself#on_popup_term;focus#on_clickself#on_select;focus#on_right_clickself#on_popup_term;target_part#on_right_clickself#on_popup_part;target#on_right_clickself#on_popup_term;target_part#on_add(fun(p,q,_)->self#added_zonepq);target#on_add(fun(p,q,_)->self#added_zonepq);parts#on_add(funentry->allparts<-entry::allparts)endmethod!reset=super#reset;targeted<-[]methodprivatepartpq=trylet(_,_,part)=List.find(fun(a,b,_)->a<=p&&q<=b)(List.revallparts)inpart(* find the tightest step, which was added first *)withNot_found->Termmethodprivateadded_zonepq=targeted<-(p,q)::targetedmethodprivatetarget_zone=tryletselected_part,_=self#targetinList.find(fun(p,q)->matchselected_part,self#partpqwith|Goal,Goal->true|Steps,Steps'->s.id=s'.id|_->false)targetedwithNot_found->0,0methodon_popup(f:Widget.popup->unit)=items<-items@[f]methodprivateitem~label~callback=letcallback()=let()=callback()inself#selectedinpopup#add_item~label~callbackmethodprivatepopup_terme=matchautofocus#get_termewith|`Auto->beginifautofocus#is_focusedethenself#item~label:"Un-focus Term"~callback:(fun()->autofocus#unfocuse);self#item~label:"Hide Term"~callback:(fun()->autofocus#set_terme`Hidden);self#item~label:"Don't Share"~callback:(fun()->autofocus#set_terme`Visible);end|`Hidden->self#item~label:"Show Term"~callback:(fun()->autofocus#set_terme`Auto)|`Visible|`Name_|`Shared->self#item~label:"Autofocus"~callback:(fun()->autofocus#set_terme`Auto)methodprivatepopup_part=function|Goal|Term->self#item~label:"Reset Autofocus"~callback:(fun()->autofocus#reset)|Stepstep->ifautofocus#is_visible_stepstepthenself#item~label:"Hide Clause"~callback:(fun()->autofocus#set_stepstep`Hidden)elseself#item~label:"Show Clause"~callback:(fun()->autofocus#set_stepstep`Visible)methodpopup=beginpopup#clear;letpart,term=self#targetinbeginmatchtermwith|Somee->self#popup_terme|None->self#popup_partpartend;popup#add_separator;List.iter(funf->fpopup)items;popup#run();endmethodprivateon_term~extend(p,q,e)=ifF.lc_closedethen(* defensive *)beginletpart=self#partpqinletfocus=ifextendthen`Extendelse`Focusinself#restore~focus(part,Somee)endmethodprivateon_select(p,q,e)=ifF.lc_closedethen(* defensive *)beginletpart=self#partpqinself#restore~focus:`Select(part,Somee);endmethodprivateon_part(_,_,part)=beginself#restore~focus:`Reset(part,None)endmethodprivateon_popup_term(p,q,e)=ifF.lc_closedethen(* defensive *)beginletpart=self#partpqinself#restore~focus:`Transient(part,Somee);self#popup;endmethodprivateon_popup_part(_,_,part)=beginself#restore~focus:`Transient(part,None);self#popup;endmethod!pp_sequentfmts=allparts<-[];targeted<-[];super#pp_sequentfmts;letp,q=self#target_zoneinifp>0&&q>pthen(Wutil.later(fun()->wtext#select~scroll:truepq))methodbutton~title~callbackfmt=letpp_titlefmttitle=Format.fprintffmt" %s "titleinFormat.fprintffmt"[%a]"(button#markcallbackpp_title)titleend