{-# LANGUAGE FlexibleContexts #-}moduleGraphics.UI.Gtk.BindingwhereimportControl.MonadimportControl.Monad.TransimportGraphics.UI.GtkimportData.Binding.ListasB-- | Bind a 'Source' to a control.bindToControl::Bindableb=>ba-- ^ the binding source->(a->d)-- ^ a function that extracts data from the source->c-- ^ the target control->Attrcd-- ^ the attribute of the control to bind to->IO()bindToControlsourceextractcontrolattribute=bindsourceextractcontrol(\cd->setc[attribute:=d])-- | Bind from a control to a 'Source'.-- The source is updated when the control loses focus.bindFromControl::(WidgetClassc,Bindableb)=>c-- ^ the control->Attrcd-- ^ the attribute of the control to bind from->(a->d->a)-- ^ a function that applies data from the control to the source->ba-- ^ the binding source->IO(ConnectIdc)bindFromControlcontrolattributeapplysource=control`on`focusOutEvent$liftIO$dod<-getcontrolattributea<-readVarsourcewriteVarsource(applyad)returnFalse-- | Create a two-way data binding.bindControl::(WidgetClassc,Bindableb)=>ba-- ^ the binding source->(a->d)-- ^ a function that extracts data from the source->c-- ^ the control->Attrcd-- ^ the attribute of the control to bind to->(a->d->a)-- ^ a function that applies data from the control to the source->IO(ConnectIdc)bindControlsourceextractcontrolattributeapply=dobindToControlsourceextractcontrolattributebindFromControlcontrolattributeapplysource-- | Create a simple two-way data binding for a 'Textual' control.bindTextEntry::(Showa,Reada,EntryClassc,WidgetClassc,Bindableb)=>ba-- ^ the binding source->c-- ^ the control->IO(ConnectIdc)bindTextEntrysourcecontrol=dobindToControlsourceshowcontrolentryTextcontrol`on`focusOutEvent$liftIO$dod<-getcontrolentryTextwriteVarsource(readd)returnFalse-- | Create a set of navigation buttons for a binding list.navigation::Variablev=>BindingListva-- ^ the binding list->a-- ^ the default value for inserts->IOHButtonBoxnavigationblnew=dospin<-spinButtonNewWithRange011letsetRange=B.lengthbl>>=spinButtonSetRangespin0.fromIntegral.predsetRangeafterValueSpinnedspin$spinButtonGetValueAsIntspin>>=seekbl>>return()buttons<-forM[("<<",spinButtonSetValuespin0),(">>",spinButtonSpinspinSpinEnd0),("+",insertblnew>>=spinButtonSetValuespin.fromIntegral>>setRange),("-",B.removebl>>=spinButtonSetValuespin.fromIntegral>>setRange)]$\(l,c)->dob<-buttonNewWithLabellonbbuttonActivatedcreturnb--disable the delete button when there's only one elementletdel=lastbuttonsdel`on`buttonActivated$dol<-B.lengthbldel`set`[widgetSensitive:=l>1]--inserting enables the delete button(buttons!!2)`on`buttonActivated$del`set`[widgetSensitive:=True]box<-hButtonBoxNewcontainerAddboxspinmapM_(containerAddbox)buttonsreturnbox