Fix two highlighted fields in the add dialog when unmonitoring
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,3 +60,33 @@ func focusedDropDown(f *tview.Form, item int) (*tview.DropDown, bool) {
|
||||
dd, ok := f.GetFormItem(item).(*tview.DropDown)
|
||||
return dd, ok
|
||||
}
|
||||
|
||||
// bindSearchNow keeps a "Search now" checkbox consistent with whether a search
|
||||
// can find anything. While searchable() is false the box is unchecked, greyed
|
||||
// out and cannot be ticked (blocked is called instead); it returns to the
|
||||
// user's earlier choice afterwards. The returned function must be called
|
||||
// whenever the answer of searchable() may have changed.
|
||||
//
|
||||
// tview's SetDisabled is avoided on purpose: on a form item it re-triggers
|
||||
// the form's focus handling and leaves two fields highlighted.
|
||||
func bindSearchNow(box *tview.Checkbox, searchable func() bool, blocked func()) (sync func()) {
|
||||
want := true
|
||||
box.SetChangedFunc(func(checked bool) {
|
||||
switch {
|
||||
case searchable():
|
||||
want = checked
|
||||
case checked:
|
||||
box.SetChecked(false)
|
||||
blocked()
|
||||
}
|
||||
})
|
||||
return func() {
|
||||
if searchable() {
|
||||
box.SetLabelColor(tview.Styles.SecondaryTextColor)
|
||||
box.SetChecked(want)
|
||||
return
|
||||
}
|
||||
box.SetLabelColor(tcell.ColorGray)
|
||||
box.SetChecked(false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user