From 31255128ff4c35afe5b0b71c1f2b70092ee2c089 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Thu, 25 Feb 2021 23:31:49 -0500 Subject: [PATCH] Bug fix - close the filter goroutines when the columns dialog closes The columns config dialog shows a display filter validation widget for each custom column displayed. This launches two goroutines per filter. These should be cleaned up when the dialog closes, so as not to leak resources. But if the dialog is closed via the escape key, for example, the Close button logic doesn't run. The solution is to set a callback via OnOpenClose() and shut down the filter goroutines there. --- ui/psmlcols.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ui/psmlcols.go b/ui/psmlcols.go index eda2690..da2c199 100644 --- a/ui/psmlcols.go +++ b/ui/psmlcols.go @@ -317,24 +317,12 @@ func openEditColumns(app gowid.IApp) { }), } - cancelButton := dialog.Button{ - Msg: "Cancel", - Action: gowid.WidgetChangedFunction(func(app gowid.IApp, widget gowid.IWidget) { - err := pcols.Close() - if err != nil { - log.Warnf("Unexpected result closing PSML columns dialog: %v", err) - } - - editColsDialog.Close(app) - }), - } - editColsDialog = dialog.New( framed.NewSpace( mainw, ), dialog.Options{ - Buttons: []dialog.Button{okButton, cancelButton}, + Buttons: []dialog.Button{okButton, dialog.Cancel}, NoShadow: true, BackgroundStyle: gowid.MakePaletteRef("dialog"), BorderStyle: gowid.MakePaletteRef("dialog"), @@ -342,6 +330,18 @@ func openEditColumns(app gowid.IApp) { }, ) + dialogOpen := false + editColsDialog.OnOpenClose(gowid.MakeWidgetCallback("cb", func(app gowid.IApp, widget gowid.IWidget) { + dialogOpen = !dialogOpen + if !dialogOpen { + err := pcols.Close() + if err != nil { + log.Warnf("Unexpected result closing PSML columns dialog: %v", err) + } + + } + })) + editColsDialog.Open(appView, ratio(0.7), app) }