Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix view's dialogs focus issue #583

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func NewApp(name string, version string) *App {
app.system.SetConnectionDisconnectFunc(app.health.Disconnect)
app.system.SetConnectionAddFunc(app.config.Add)
app.system.SetConnectionRemoveFunc(app.config.Remove)
app.system.SetAppFocusHandler(func() {
app.Application.SetFocus(app.system)
app.fastRefreshChan <- true
})

app.help = help.NewHelp(name, version)

Expand All @@ -96,6 +100,37 @@ func NewApp(name string, version string) *App {
// its required for image build dialog.
app.images.SetFastRefreshChannel(app.fastRefreshChan)

// set app set focus
app.containers.SetAppFocusHandler(func() {
app.Application.SetFocus(app.containers)
app.fastRefreshChan <- true
})

app.pods.SetAppFocusHandler(func() {
app.Application.SetFocus(app.pods)
app.fastRefreshChan <- true
})

app.images.SetAppFocusHandler(func() {
app.Application.SetFocus(app.images)
app.fastRefreshChan <- true
})

app.volumes.SetAppFocusHandler(func() {
app.Application.SetFocus(app.volumes)
app.fastRefreshChan <- true
})

app.networks.SetAppFocusHandler(func() {
app.Application.SetFocus(app.networks)
app.fastRefreshChan <- true
})

app.secrets.SetAppFocusHandler(func() {
app.Application.SetFocus(app.secrets)
app.fastRefreshChan <- true
})

// menu items
menuItems := [][]string{
{utils.HelpScreenKey.Label(), app.help.GetTitle()},
Expand Down
31 changes: 31 additions & 0 deletions ui/containers/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (cnt *Containers) attach() {

cnt.progressDialog.Hide()
cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -103,6 +104,7 @@ func (cnt *Containers) attach() {
cnt.progressDialog.Hide()
cnt.terminalDialog.SetContainerInfo(cntID, cntName)
cnt.terminalDialog.Display()
cnt.appFocusHandler()
}
}

Expand Down Expand Up @@ -130,6 +132,7 @@ func (cnt *Containers) preHealthcheck() {
title := fmt.Sprintf("CONTAINER (%s) HEALTHCHECK ERROR", cntID)

cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -139,6 +142,7 @@ func (cnt *Containers) preHealthcheck() {
cnt.messageDialog.SetTitle("podman container healthcheck")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, report)
cnt.messageDialog.Display()
cnt.appFocusHandler()
}

go cntHealthCheck()
Expand Down Expand Up @@ -207,6 +211,7 @@ func (cnt *Containers) restore() {

cnt.progressDialog.Hide()
cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -217,6 +222,7 @@ func (cnt *Containers) restore() {
cnt.messageDialog.SetTitle("podman container restore")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, report)
cnt.messageDialog.Display()
cnt.appFocusHandler()
}

go restore()
Expand Down Expand Up @@ -248,6 +254,7 @@ func (cnt *Containers) checkpoint() {

cnt.progressDialog.Hide()
cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -258,6 +265,7 @@ func (cnt *Containers) checkpoint() {
cnt.messageDialog.SetTitle("podman container checkpoint")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, report)
cnt.messageDialog.Display()
cnt.appFocusHandler()
}

go checkpoint()
Expand Down Expand Up @@ -291,6 +299,7 @@ func (cnt *Containers) commit() {
title := fmt.Sprintf("CONTAINER (%s) COMMIT ERROR", cnt.selectedID)

cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -301,6 +310,7 @@ func (cnt *Containers) commit() {
cnt.messageDialog.SetTitle("podman container commit")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, response)
cnt.messageDialog.Display()
cnt.appFocusHandler()
}

go cntCommit()
Expand Down Expand Up @@ -422,6 +432,7 @@ func (cnt *Containers) runDetach(runOpts containers.CreateOptions) {
if err != nil {
cnt.progressDialog.Hide()
cnt.displayError("CONTAINER RUN ERROR", err)
cnt.appFocusHandler()

return
}
Expand All @@ -434,13 +445,15 @@ func (cnt *Containers) runDetach(runOpts containers.CreateOptions) {
cnt.messageDialog.SetTitle("CONTAINER RUN WARNINGS")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, strings.Join(warnings, "\n"))
cnt.messageDialog.Display()
cnt.appFocusHandler()

return
}

if err := containers.Start(cntID); err != nil {
cnt.progressDialog.Hide()
cnt.displayError("CONTAINER RUN ERROR", err)
cnt.appFocusHandler()

return
}
Expand All @@ -462,6 +475,7 @@ func (cnt *Containers) runAttach(runOpts containers.CreateOptions) {
runStatusChan <- false

cnt.displayError("CONTAINER RUN ERROR", err)
cnt.appFocusHandler()

return
}
Expand All @@ -474,6 +488,7 @@ func (cnt *Containers) runAttach(runOpts containers.CreateOptions) {
cnt.messageDialog.SetTitle("CONTAINER RUN WARNINGS")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, strings.Join(warnings, "\n"))
cnt.messageDialog.Display()
cnt.appFocusHandler()

return
}
Expand All @@ -485,6 +500,7 @@ func (cnt *Containers) runAttach(runOpts containers.CreateOptions) {
attachReady <- false

cnt.displayError("CONTAINER RUN ERROR", err)
cnt.appFocusHandler()

return
}
Expand All @@ -511,12 +527,14 @@ func (cnt *Containers) runAttach(runOpts containers.CreateOptions) {
if isReady {
if err := containers.Start(cntID); err != nil {
cnt.displayError("CONTAINER RUN ERROR", err)
cnt.appFocusHandler()

return
}

cnt.terminalDialog.SetContainerInfo(cntID, "")
cnt.terminalDialog.Display()
cnt.appFocusHandler()
}
}
}
Expand Down Expand Up @@ -544,6 +562,7 @@ func (cnt *Containers) create() {

if err != nil {
cnt.displayError("CONTAINER CREATE ERROR", err)
cnt.appFocusHandler()

return
}
Expand All @@ -554,6 +573,7 @@ func (cnt *Containers) create() {
cnt.messageDialog.SetTitle("CONTAINER CREATE WARNINGS")
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, strings.Join(warnings, "\n"))
cnt.messageDialog.Display()
cnt.appFocusHandler()
}
}

Expand Down Expand Up @@ -622,6 +642,7 @@ func (cnt *Containers) kill() {
if err != nil {
title := fmt.Sprintf("CONTAINER (%s) KILL ERROR", cnt.selectedID)
cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand Down Expand Up @@ -650,6 +671,7 @@ func (cnt *Containers) logs() {
title := fmt.Sprintf("CONTAINER (%s) DISPLAY LOG ERROR", cntID)

cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -664,6 +686,7 @@ func (cnt *Containers) logs() {
cnt.messageDialog.SetText(dialogs.MessageContainerInfo, headerLabel, cntLogs)
cnt.messageDialog.TextScrollToEnd()
cnt.messageDialog.DisplayFullSize()
cnt.appFocusHandler()
}

go getLogs()
Expand All @@ -687,6 +710,7 @@ func (cnt *Containers) pause() {
if err != nil {
title := fmt.Sprintf("CONTAINER (%s) PAUSE ERROR", cnt.selectedID)
cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand Down Expand Up @@ -738,6 +762,7 @@ func (cnt *Containers) prune() {

if err != nil {
cnt.displayError("CONTAINER PRUNE ERROR", err)
cnt.appFocusHandler()

return
}
Expand Down Expand Up @@ -790,6 +815,7 @@ func (cnt *Containers) renameContainer(id string, newName string) {
if err != nil {
title := fmt.Sprintf("CONTAINER (%s) RENAME ERROR", cnt.selectedID)
cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand Down Expand Up @@ -833,6 +859,7 @@ func (cnt *Containers) remove() {
title := fmt.Sprintf("CONTAINER (%s) REMOVE ERROR", cnt.selectedID)

cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -841,6 +868,7 @@ func (cnt *Containers) remove() {
title := fmt.Sprintf("CONTAINER (%s) REMOVE ERROR", cnt.selectedID)

cnt.displayError(title, fmt.Errorf("%v", errData)) //nolint:goerr113
cnt.appFocusHandler()
}
}

Expand All @@ -866,6 +894,7 @@ func (cnt *Containers) start() {
title := fmt.Sprintf("CONTAINER (%s) START ERROR", cnt.selectedID)

cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand All @@ -892,6 +921,7 @@ func (cnt *Containers) stop() {
title := fmt.Sprintf("CONTAINER (%s) STOP ERROR", cnt.selectedID)

cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand Down Expand Up @@ -941,6 +971,7 @@ func (cnt *Containers) unpause() {
title := fmt.Sprintf("CONTAINER (%s) UNPAUSE ERROR", cnt.selectedID)

cnt.displayError(title, err)
cnt.appFocusHandler()

return
}
Expand Down
6 changes: 6 additions & 0 deletions ui/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Containers struct {
selectedName string
confirmData string
fastRefreshChan chan bool
appFocusHandler func()
}

type containerListReport struct {
Expand Down Expand Up @@ -226,6 +227,11 @@ func NewContainers() *Containers {
return containers
}

// SetAppFocusHandler sets application focus handler.
func (cnt *Containers) SetAppFocusHandler(handler func()) {
cnt.appFocusHandler = handler
}

// GetTitle returns primitive title.
func (cnt *Containers) GetTitle() string {
return cnt.title
Expand Down
Loading
Loading