Close assignment window with main window

This commit is contained in:
Dieter Lang 2026-08-11 19:20:58 +02:00
parent 8d98e85453
commit 5e595fe460

View file

@ -60,6 +60,8 @@ type App struct {
errorLabel *widget.Label
reconnectButton *widget.Button
assignmentButton *widget.Button
assignmentWindow fyne.Window
}
// NewApp creates the graphical rs2322tcp client application.
@ -232,6 +234,12 @@ func (a *App) showAssignments() {
return
}
// Do not create another assignment window when one is already open.
if a.assignmentWindow != nil {
a.assignmentWindow.Show()
return
}
cfg := a.clientApplication.Config()
devices := a.clientApplication.Devices()
@ -295,6 +303,19 @@ func (a *App) showAssignments() {
"Gerätezuordnung",
)
assignmentWindow.Resize(fyne.NewSize(650, 450))
// Remember the child window so it can be closed together with
// the main window.
a.assignmentWindow = assignmentWindow
assignmentWindow.SetOnClosed(func() {
// Only clear the reference if this is still the current
// assignment window.
if a.assignmentWindow == assignmentWindow {
a.assignmentWindow = nil
}
})
assignmentWindow.SetContent(
container.NewBorder(
nil,
@ -309,18 +330,40 @@ func (a *App) showAssignments() {
container.NewVScroll(content),
),
)
assignmentWindow.Show()
}
// closeAssignmentWindow closes the currently open device-assignment window.
//
// This is deliberately kept separate from Close() so that the child window
// can be closed without changing any configuration or technical client
// state.
func (a *App) closeAssignmentWindow() {
if a == nil {
return
}
if a.assignmentWindow == nil {
return
}
window := a.assignmentWindow
a.assignmentWindow = nil
window.Close()
}
// Close closes the technical client application.
//
// The Runtime and the server connection are closed before the GUI window
// itself is closed.
// Any open child GUI window is closed first. The technical client is then
// shut down.
func (a *App) Close() {
if a == nil {
return
}
a.closeAssignmentWindow()
_ = a.clientApplication.Close()
}