From f06e2ef927d3f80de5beacb0df7f0bcde4cea9b1 Mon Sep 17 00:00:00 2001 From: Navid Yaghoobi Date: Sat, 8 Mar 2025 20:23:05 +1100 Subject: [PATCH] Fix view's dialogs focus issue Signed-off-by: Navid Yaghoobi --- app/app.go | 35 +++++++++++++++++++++++++++++++++++ ui/containers/commands.go | 31 +++++++++++++++++++++++++++++++ ui/containers/containers.go | 6 ++++++ ui/images/commands.go | 22 ++++++++++++++++++++++ ui/images/images.go | 6 ++++++ ui/networks/commands.go | 9 +++++++++ ui/networks/networks.go | 6 ++++++ ui/pods/commands.go | 17 +++++++++++++++++ ui/pods/pods.go | 34 ++++++++++++++++++++-------------- ui/secrets/commands.go | 1 + ui/secrets/secrets.go | 24 +++++++++++++++--------- ui/system/command.go | 7 +++++++ ui/system/system.go | 6 ++++++ ui/volumes/commands.go | 3 +++ ui/volumes/volumes.go | 28 +++++++++++++++++----------- 15 files changed, 201 insertions(+), 34 deletions(-) diff --git a/app/app.go b/app/app.go index 7f5268a4e..a13d967ff 100644 --- a/app/app.go +++ b/app/app.go @@ -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) @@ -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()}, diff --git a/ui/containers/commands.go b/ui/containers/commands.go index a05fe736c..686969bdb 100644 --- a/ui/containers/commands.go +++ b/ui/containers/commands.go @@ -92,6 +92,7 @@ func (cnt *Containers) attach() { cnt.progressDialog.Hide() cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -103,6 +104,7 @@ func (cnt *Containers) attach() { cnt.progressDialog.Hide() cnt.terminalDialog.SetContainerInfo(cntID, cntName) cnt.terminalDialog.Display() + cnt.appFocusHandler() } } @@ -130,6 +132,7 @@ func (cnt *Containers) preHealthcheck() { title := fmt.Sprintf("CONTAINER (%s) HEALTHCHECK ERROR", cntID) cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -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() @@ -207,6 +211,7 @@ func (cnt *Containers) restore() { cnt.progressDialog.Hide() cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -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() @@ -248,6 +254,7 @@ func (cnt *Containers) checkpoint() { cnt.progressDialog.Hide() cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -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() @@ -291,6 +299,7 @@ func (cnt *Containers) commit() { title := fmt.Sprintf("CONTAINER (%s) COMMIT ERROR", cnt.selectedID) cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -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() @@ -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 } @@ -434,6 +445,7 @@ 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 } @@ -441,6 +453,7 @@ func (cnt *Containers) runDetach(runOpts containers.CreateOptions) { if err := containers.Start(cntID); err != nil { cnt.progressDialog.Hide() cnt.displayError("CONTAINER RUN ERROR", err) + cnt.appFocusHandler() return } @@ -462,6 +475,7 @@ func (cnt *Containers) runAttach(runOpts containers.CreateOptions) { runStatusChan <- false cnt.displayError("CONTAINER RUN ERROR", err) + cnt.appFocusHandler() return } @@ -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 } @@ -485,6 +500,7 @@ func (cnt *Containers) runAttach(runOpts containers.CreateOptions) { attachReady <- false cnt.displayError("CONTAINER RUN ERROR", err) + cnt.appFocusHandler() return } @@ -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() } } } @@ -544,6 +562,7 @@ func (cnt *Containers) create() { if err != nil { cnt.displayError("CONTAINER CREATE ERROR", err) + cnt.appFocusHandler() return } @@ -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() } } @@ -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 } @@ -650,6 +671,7 @@ func (cnt *Containers) logs() { title := fmt.Sprintf("CONTAINER (%s) DISPLAY LOG ERROR", cntID) cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -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() @@ -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 } @@ -738,6 +762,7 @@ func (cnt *Containers) prune() { if err != nil { cnt.displayError("CONTAINER PRUNE ERROR", err) + cnt.appFocusHandler() return } @@ -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 } @@ -833,6 +859,7 @@ func (cnt *Containers) remove() { title := fmt.Sprintf("CONTAINER (%s) REMOVE ERROR", cnt.selectedID) cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -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() } } @@ -866,6 +894,7 @@ func (cnt *Containers) start() { title := fmt.Sprintf("CONTAINER (%s) START ERROR", cnt.selectedID) cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -892,6 +921,7 @@ func (cnt *Containers) stop() { title := fmt.Sprintf("CONTAINER (%s) STOP ERROR", cnt.selectedID) cnt.displayError(title, err) + cnt.appFocusHandler() return } @@ -941,6 +971,7 @@ func (cnt *Containers) unpause() { title := fmt.Sprintf("CONTAINER (%s) UNPAUSE ERROR", cnt.selectedID) cnt.displayError(title, err) + cnt.appFocusHandler() return } diff --git a/ui/containers/containers.go b/ui/containers/containers.go index 655a36ee3..5de3c828a 100644 --- a/ui/containers/containers.go +++ b/ui/containers/containers.go @@ -72,6 +72,7 @@ type Containers struct { selectedName string confirmData string fastRefreshChan chan bool + appFocusHandler func() } type containerListReport struct { @@ -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 diff --git a/ui/images/commands.go b/ui/images/commands.go index f4664c9c1..d12ee5432 100644 --- a/ui/images/commands.go +++ b/ui/images/commands.go @@ -77,6 +77,7 @@ func (img *Images) build() { if err != nil { img.displayError("IMAGE BUILD ERROR", err) + img.appFocusHandler() return } @@ -84,6 +85,7 @@ func (img *Images) build() { img.messageDialog.SetTitle("podman image build") img.messageDialog.SetText(dialogs.MessageImageInfo, report, "") img.messageDialog.Display() + img.appFocusHandler() } go buildFunc() @@ -108,7 +110,9 @@ func (img *Images) diff() { if err != nil { title := fmt.Sprintf("IMAGE (%s) DIFF ERROR", imageID) + img.displayError(title, err) + img.appFocusHandler() return } @@ -118,6 +122,7 @@ func (img *Images) diff() { img.messageDialog.SetTitle("podman image diff") img.messageDialog.SetText(dialogs.MessageImageInfo, headerLabel, strings.Join(data, "\n")) img.messageDialog.DisplayFullSize() + img.appFocusHandler() } go diff() @@ -160,6 +165,7 @@ func (img *Images) imageImport() { if err != nil { img.displayError("IMAGE IMPORT ERROR", err) + img.appFocusHandler() return } @@ -167,6 +173,7 @@ func (img *Images) imageImport() { img.messageDialog.SetTitle("podman image import") img.messageDialog.SetText(dialogs.MessageImageInfo, newImageID, "") img.messageDialog.Display() + img.appFocusHandler() } go importFunc() @@ -213,6 +220,7 @@ func (img *Images) prune() { if err != nil { img.displayError("IMAGE PRUNE ERROR", err) + img.appFocusHandler() return } @@ -243,7 +251,9 @@ func (img *Images) push() { if err := images.Push(img.selectedID, pushOptions); err != nil { img.progressDialog.Hide() title := fmt.Sprintf("IMAGE (%s) PUSH ERROR", img.selectedID) + img.displayError(title, err) + img.appFocusHandler() return } @@ -285,13 +295,16 @@ func (img *Images) remove() { if err != nil { title := fmt.Sprintf("IMAGE (%s) REMOVE ERROR", imageID) + img.displayError(title, err) + img.appFocusHandler() } else { headerLabel := fmt.Sprintf("%12s (%s)", imageID, imageName) img.messageDialog.SetTitle("podman image remove") img.messageDialog.SetText(dialogs.MessageImageInfo, headerLabel, strings.Join(data, "\n")) img.messageDialog.Display() + img.appFocusHandler() } } @@ -330,7 +343,9 @@ func (img *Images) save() { if err != nil { title := fmt.Sprintf("IMAGE (%s) SAVE ERROR", img.selectedID) + img.displayError(title, err) + img.appFocusHandler() return } @@ -348,7 +363,9 @@ func (img *Images) search(term string) { result, err := images.Search(term) if err != nil { title := fmt.Sprintf("IMAGE (%s) SEARCH ERROR", img.selectedID) + img.displayError(title, err) + img.appFocusHandler() } img.searchDialog.UpdateResults(result) @@ -423,7 +440,9 @@ func (img *Images) tree() { tree, err := images.Tree(imageID) if err != nil { title := fmt.Sprintf("IMAGE (%s) TREE ERROR", imageID) + img.displayError(title, err) + img.appFocusHandler() return } @@ -434,6 +453,7 @@ func (img *Images) tree() { img.messageDialog.SetTitle("podman image tree") img.messageDialog.SetText(dialogs.MessageImageInfo, headerLabel, tree) img.messageDialog.Display() + img.appFocusHandler() } img.progressDialog.SetTitle("image tree in progress") @@ -459,7 +479,9 @@ func (img *Images) pull(image string) { err := images.Pull(name) if err != nil { title := fmt.Sprintf("IMAGE (%s) PULL ERROR", img.selectedID) + img.displayError(title, err) + img.appFocusHandler() } img.progressDialog.Hide() diff --git a/ui/images/images.go b/ui/images/images.go index 46765523f..99bcffcd2 100644 --- a/ui/images/images.go +++ b/ui/images/images.go @@ -58,6 +58,7 @@ type Images struct { selectedName string confirmData string fastRefreshChan chan bool + appFocusHandler func() } type imageListReport struct { @@ -207,6 +208,11 @@ func NewImages() *Images { return images } +// SetAppFocusHandler sets application focus handler. +func (img *Images) SetAppFocusHandler(handler func()) { + img.appFocusHandler = handler +} + // GetTitle returns primitive title. func (img *Images) GetTitle() string { return img.title diff --git a/ui/networks/commands.go b/ui/networks/commands.go index fe28ee45f..04fadfb1a 100644 --- a/ui/networks/commands.go +++ b/ui/networks/commands.go @@ -50,6 +50,7 @@ func (nets *Networks) cconnect() { if err != nil { nets.progressDialog.Hide() nets.displayError("NETWORK CONNECT ERROR", err) + nets.appFocusHandler() return } @@ -60,6 +61,7 @@ func (nets *Networks) cconnect() { nets.connectDialog.SetContainers(cntListReport) nets.progressDialog.Hide() nets.connectDialog.Display() + nets.appFocusHandler() } go initData() @@ -76,6 +78,7 @@ func (nets *Networks) connect() { if err := networks.Connect(connectOptions); err != nil { nets.progressDialog.Hide() nets.displayError("NETWORK CONNECT ERROR", err) + nets.appFocusHandler() return } @@ -101,6 +104,7 @@ func (nets *Networks) cdisconnect() { if err != nil { nets.progressDialog.Hide() nets.displayError("NETWORK DISCONNECT ERROR", err) + nets.appFocusHandler() return } @@ -111,6 +115,7 @@ func (nets *Networks) cdisconnect() { nets.disconnectDialog.SetContainers(cntListReport) nets.progressDialog.Hide() nets.disconnectDialog.Display() + nets.appFocusHandler() } go initData() @@ -127,6 +132,7 @@ func (nets *Networks) disconnect() { if err := networks.Disconnect(networkName, containerID); err != nil { nets.progressDialog.Hide() nets.displayError("NETWORK DISCONNECT ERROR", err) + nets.appFocusHandler() return } @@ -190,6 +196,7 @@ func (nets *Networks) prune() { if err := networks.Prune(); err != nil { nets.progressDialog.Hide() nets.displayError("NETWORK PRUNE ERROR", err) + nets.appFocusHandler() return } @@ -233,7 +240,9 @@ func (nets *Networks) remove() { if err != nil { title := fmt.Sprintf("NETWORK (%s) REMOVE ERROR", nets.selectedID) + nets.displayError(title, err) + nets.appFocusHandler() return } diff --git a/ui/networks/networks.go b/ui/networks/networks.go index da86008f2..8c2cc3053 100644 --- a/ui/networks/networks.go +++ b/ui/networks/networks.go @@ -40,6 +40,7 @@ type Networks struct { disconnectDialog *netdialogs.NetworkDisconnectDialog selectedID string confirmData string + appFocusHandler func() } // NewNetworks returns nets page view. @@ -138,6 +139,11 @@ func NewNetworks() *Networks { return nets } +// SetAppFocusHandler sets application focus handler. +func (nets *Networks) SetAppFocusHandler(handler func()) { + nets.appFocusHandler = handler +} + // GetTitle returns primitive title. func (nets *Networks) GetTitle() string { return nets.title diff --git a/ui/pods/commands.go b/ui/pods/commands.go index d39e1fc25..545909775 100644 --- a/ui/pods/commands.go +++ b/ui/pods/commands.go @@ -75,6 +75,7 @@ func (p *Pods) create() { if err != nil { p.displayError("POD CREATE ERROR", err) + p.appFocusHandler() return } @@ -126,6 +127,7 @@ func (p *Pods) kill() { title := fmt.Sprintf("POD (%s) KILL ERROR", p.selectedID) p.displayError(title, err) + p.appFocusHandler() return } @@ -153,6 +155,7 @@ func (p *Pods) pause() { title := fmt.Sprintf("POD (%s) PAUSE ERROR", p.selectedID) p.displayError(title, err) + p.appFocusHandler() return } @@ -172,6 +175,7 @@ func (p *Pods) prune() { if err != nil { p.displayError("PODS PRUNE ERROR", err) + p.appFocusHandler() return } @@ -180,6 +184,7 @@ func (p *Pods) prune() { errMessages := fmt.Errorf("%w %v", errPodPrune, errData) p.displayError("PODS PRUNE ERROR", errMessages) + p.appFocusHandler() } } @@ -203,7 +208,9 @@ func (p *Pods) restart() { if err != nil { title := fmt.Sprintf("POD (%s) RESTART ERROR", p.selectedID) + p.displayError(title, err) + p.appFocusHandler() return } @@ -244,14 +251,18 @@ func (p *Pods) remove() { if err != nil { title := fmt.Sprintf("POD (%s) REMOVE ERROR", p.selectedID) + p.displayError(title, err) + p.appFocusHandler() return } if len(errData) > 0 { title := fmt.Sprintf("POD (%s) REMOVE ERROR", p.selectedID) + p.displayError(title, fmt.Errorf("%w %v", errPodRemove, errData)) + p.appFocusHandler() } } @@ -275,7 +286,9 @@ func (p *Pods) start() { if err != nil { title := fmt.Sprintf("POD (%s) START ERROR", p.selectedID) + p.displayError(title, err) + p.appFocusHandler() return } @@ -301,7 +314,9 @@ func (p *Pods) stop() { if err != nil { title := fmt.Sprintf("POD (%s) STOP ERROR", p.selectedID) + p.displayError(title, err) + p.appFocusHandler() return } @@ -347,7 +362,9 @@ func (p *Pods) unpause() { if err != nil { title := fmt.Sprintf("POD (%s) UNPAUSE ERROR", p.selectedID) + p.displayError(title, err) + p.appFocusHandler() return } diff --git a/ui/pods/pods.go b/ui/pods/pods.go index fbfd3c5a4..ab5e08d16 100644 --- a/ui/pods/pods.go +++ b/ui/pods/pods.go @@ -40,20 +40,21 @@ var ( // Pods implemnents the pods page primitive. type Pods struct { *tview.Box - title string - headers []string - table *tview.Table - errorDialog *dialogs.ErrorDialog - progressDialog *dialogs.ProgressDialog - confirmDialog *dialogs.ConfirmDialog - cmdDialog *dialogs.CommandDialog - messageDialog *dialogs.MessageDialog - topDialog *dialogs.TopDialog - createDialog *poddialogs.PodCreateDialog - statsDialog *poddialogs.PodStatsDialog - podsList podsListReport - selectedID string - confirmData string + title string + headers []string + table *tview.Table + errorDialog *dialogs.ErrorDialog + progressDialog *dialogs.ProgressDialog + confirmDialog *dialogs.ConfirmDialog + cmdDialog *dialogs.CommandDialog + messageDialog *dialogs.MessageDialog + topDialog *dialogs.TopDialog + createDialog *poddialogs.PodCreateDialog + statsDialog *poddialogs.PodStatsDialog + podsList podsListReport + selectedID string + confirmData string + appFocusHandler func() } type podsListReport struct { @@ -164,6 +165,11 @@ func NewPods() *Pods { return pods } +// SetAppFocusHandler sets application focus handler. +func (pods *Pods) SetAppFocusHandler(handler func()) { + pods.appFocusHandler = handler +} + // GetTitle returns primitive title. func (pods *Pods) GetTitle() string { return pods.title diff --git a/ui/secrets/commands.go b/ui/secrets/commands.go index 2510490ac..33e5323d7 100644 --- a/ui/secrets/commands.go +++ b/ui/secrets/commands.go @@ -114,6 +114,7 @@ func (s *Secrets) remove() { if err != nil { title := fmt.Sprintf("SECRET (%s) REMOVE ERROR", secID) s.displayError(title, err) + s.appFocusHandler() return } diff --git a/ui/secrets/secrets.go b/ui/secrets/secrets.go index e24d3fb58..1c37c479e 100644 --- a/ui/secrets/secrets.go +++ b/ui/secrets/secrets.go @@ -29,15 +29,16 @@ var ( // Secrets implements the secrets page primitive. type Secrets struct { *tview.Box - title string - headers []string - table *tview.Table - cmdDialog *dialogs.CommandDialog - messageDialog *dialogs.MessageDialog - errorDialog *dialogs.ErrorDialog - progressDialog *dialogs.ProgressDialog - confirmDialog *dialogs.ConfirmDialog - createDialog *secdialogs.SecretCreateDialog + title string + headers []string + table *tview.Table + cmdDialog *dialogs.CommandDialog + messageDialog *dialogs.MessageDialog + errorDialog *dialogs.ErrorDialog + progressDialog *dialogs.ProgressDialog + confirmDialog *dialogs.ConfirmDialog + createDialog *secdialogs.SecretCreateDialog + appFocusHandler func() } // NewSecrets returns secrets page view. @@ -108,6 +109,11 @@ func NewSecrets() *Secrets { return secrets } +// SetAppFocusHandler sets application focus handler. +func (s *Secrets) SetAppFocusHandler(handler func()) { + s.appFocusHandler = handler +} + // GetTitle returns primitive title. func (s *Secrets) GetTitle() string { return s.title diff --git a/ui/system/command.go b/ui/system/command.go index 1c3b7312c..c5dcb22f7 100644 --- a/ui/system/command.go +++ b/ui/system/command.go @@ -54,6 +54,7 @@ func (sys *System) addConnection() { if err != nil { sys.displayError("ADD NEW CONNECTION ERROR", err) + sys.appFocusHandler() return } @@ -99,6 +100,7 @@ func (sys *System) df() { if err != nil { sys.displayError("SYSTEM DISK USAGE ERROR", err) + sys.appFocusHandler() return } @@ -107,6 +109,7 @@ func (sys *System) df() { sys.dfDialog.SetServiceName(connName) sys.dfDialog.UpdateDiskSummary(response) sys.dfDialog.Display() + sys.appFocusHandler() } go diskUsage() @@ -168,6 +171,7 @@ func (sys *System) prune() { if err != nil { sys.displayError("SYSTEM PRUNE ERROR", err) + sys.appFocusHandler() return } @@ -175,6 +179,7 @@ func (sys *System) prune() { sys.messageDialog.SetTitle("PODMAN SYSTEM PRUNE") sys.messageDialog.SetText(dialogs.MessageSystemInfo, registry.ConnectionName(), report) sys.messageDialog.Display() + sys.appFocusHandler() } go prune() @@ -219,6 +224,7 @@ func (sys *System) remove() { if err != nil { sys.displayError("SYSTEM CONNECTION REMOVE ERROR", err) + sys.appFocusHandler() return } @@ -234,6 +240,7 @@ func (sys *System) setDefault() { if err := sys.connectionSetDefaultFunc(selectedItem.name); err != nil { sys.displayError("SYSTEM CONNECTION SET DEFAULT ERROR", err) + sys.appFocusHandler() return } diff --git a/ui/system/system.go b/ui/system/system.go index d2ee316a1..ea662fd41 100644 --- a/ui/system/system.go +++ b/ui/system/system.go @@ -38,6 +38,7 @@ type System struct { connectionSetDefaultFunc func(string) error connectionConnectFunc func(registry.Connection) connectionDisconnectFunc func() + appFocusHandler func() } type connectionListReport struct { @@ -159,6 +160,11 @@ func NewSystem() *System { return sys } +// SetAppFocusHandler sets application focus handler. +func (sys *System) SetAppFocusHandler(handler func()) { + sys.appFocusHandler = handler +} + // GetTitle returns primitive title. func (sys *System) GetTitle() string { return sys.title diff --git a/ui/volumes/commands.go b/ui/volumes/commands.go index b7bc3fa0f..5a0af4961 100644 --- a/ui/volumes/commands.go +++ b/ui/volumes/commands.go @@ -88,6 +88,7 @@ func (vols *Volumes) prune() { errorTitle := "volume prune error" if err != nil { vols.displayError(errorTitle, err) + vols.appFocusHandler() return } @@ -95,6 +96,7 @@ func (vols *Volumes) prune() { if len(errData) > 0 { pruneError := errors.New(strings.Join(errData, "\n")) //nolint:goerr113 vols.displayError(errorTitle, pruneError) + vols.appFocusHandler() } } @@ -141,6 +143,7 @@ func (vols *Volumes) remove() { if err != nil { title := fmt.Sprintf("volume (%s) remove error", volID) vols.displayError(title, err) + vols.appFocusHandler() return } diff --git a/ui/volumes/volumes.go b/ui/volumes/volumes.go index dda4f53e4..f2f5d4baf 100644 --- a/ui/volumes/volumes.go +++ b/ui/volumes/volumes.go @@ -16,17 +16,18 @@ import ( // Volumes implemnents the volumes page primitive. type Volumes struct { *tview.Box - title string - headers []string - table *tview.Table - errorDialog *dialogs.ErrorDialog - progressDialog *dialogs.ProgressDialog - confirmDialog *dialogs.ConfirmDialog - cmdDialog *dialogs.CommandDialog - messageDialog *dialogs.MessageDialog - createDialog *voldialogs.VolumeCreateDialog - volumeList volListReport - confirmData string + title string + headers []string + table *tview.Table + errorDialog *dialogs.ErrorDialog + progressDialog *dialogs.ProgressDialog + confirmDialog *dialogs.ConfirmDialog + cmdDialog *dialogs.CommandDialog + messageDialog *dialogs.MessageDialog + createDialog *voldialogs.VolumeCreateDialog + volumeList volListReport + confirmData string + appFocusHandler func() } type volListReport struct { @@ -123,6 +124,11 @@ func (vols *Volumes) initUI() { }) } +// SetAppFocusHandler sets application focus handler. +func (vols *Volumes) SetAppFocusHandler(handler func()) { + vols.appFocusHandler = handler +} + // GetTitle returns primitive title. func (vols *Volumes) GetTitle() string { return vols.title