123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* 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). *)(* *)(**************************************************************************)(* -------------------------------------------------------------------------- *)(* --- File Chooser --- *)(* -------------------------------------------------------------------------- *)typefilekind=[`FILE|`DIR]classdialog?(kind=`FILE)?(title="Select File")?(select="Select")?parent()=letdialog=GWindow.dialog~title?parent~modal:true()inletpacking=dialog#vbox#pack~expand:trueinletaction=matchkindwith`FILE->`SAVE|`DIR->`CREATE_FOLDERinletchooser=GFile.chooser_widget~action~packing()inobjectinherit[string]Wutil.signalassignalinitializerbeginignore(dialog#event#connect#delete~callback:(fun_->true));dialog#add_button"Cancel"`DELETE_EVENT;dialog#add_buttonselect`SELECT;ignore(GMisc.label~packing:(dialog#action_area#pack~expand:true)());endmethodadd_filter~descr~patterns=ifkind=`FILEthenchooser#add_filter(GFile.filter~name:descr~patterns())methodselect?dir?file()=beginmatchdir,filewith|None,None->ignore(chooser#set_filename"")|None,Somepath->ignore(chooser#set_filenamepath)|Somedir,None->ignore(chooser#set_current_folderdir);ignore(chooser#set_current_name"")|Somedir,Somefile->ignore(chooser#set_current_folderdir);ignore(chooser#set_current_namefile)end;letresult=dialog#run()indialog#misc#hide();matchresultwith|`DELETE_EVENT->()|`SELECT->matchchooser#get_filenameswith|f::_->signal#firef|_->()endclassbutton?kind?title?select?tooltip?parent()=letbox=GPack.hbox~homogeneous:false~spacing:0~border_width:0()inletfld=GMisc.label~text:"(none)"~xalign:0.0~packing:(box#pack~expand:true)()inlet_=GMisc.separator`VERTICAL~packing:(box#pack~expand:false~padding:2)~show:true()inlet_=GMisc.image~packing:(box#pack~expand:false)~stock:`OPEN()inletbutton=GButton.button()inletdialog=newdialog?kind?title?select?parent()inobject(self)inheritWutil.gobj_widgetbuttoninherit![string]Wutil.selector""ascurrentvalmutabledisptip=funf->matchtooltip,fwith|None,""->"(none)"|None,_->f|Somed,""->d|Somed,f->Printf.sprintf"%s: %s"dfvalmutabledisplay=function|""->"(none)"|path->Filename.basenamepathinitializerbeginbutton#addbox#coerce;button#set_focus_on_clickfalse;ignore(button#connect#clicked~callback:self#select);dialog#connectcurrent#set;Wutil.set_tooltipbuttontooltip;current#connect(funf->button#misc#set_tooltip_text(disptipf);fld#set_text(displayf));endmethodset_tooltipp=disptip<-p;fld#misc#set_tooltip_text(pcurrent#get)methodset_displayp=display<-p;fld#set_text(pcurrent#get)methodadd_filter=dialog#add_filtermethodselect?dir?file()=letfile=matchfilewithNone->current#get|Somef->findialog#select?dir~file()end