mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-05-04 22:17:48 +08:00
implement stack popup
This commit is contained in:
parent
e577eeff6a
commit
9f669f94a6
2
gomu.go
2
gomu.go
@ -18,7 +18,7 @@ type Gomu struct {
|
|||||||
playlist *Playlist
|
playlist *Playlist
|
||||||
player *Player
|
player *Player
|
||||||
pages *tview.Pages
|
pages *tview.Pages
|
||||||
popups []tview.Primitive
|
popups Stack
|
||||||
prevPanel Panel
|
prevPanel Panel
|
||||||
popupBg tcell.Color
|
popupBg tcell.Color
|
||||||
textColor tcell.Color
|
textColor tcell.Color
|
||||||
|
@ -118,7 +118,6 @@ func newPlaylist() *Playlist {
|
|||||||
case 'a':
|
case 'a':
|
||||||
|
|
||||||
name, _ := gomu.pages.GetFrontPage()
|
name, _ := gomu.pages.GetFrontPage()
|
||||||
|
|
||||||
if name != "mkdir-popup" {
|
if name != "mkdir-popup" {
|
||||||
createPlaylistPopup()
|
createPlaylistPopup()
|
||||||
}
|
}
|
||||||
@ -229,7 +228,7 @@ func (p *Playlist) deleteSong(audioFile *AudioFile) (err error) {
|
|||||||
|
|
||||||
if buttonName == "no" || buttonName == "" {
|
if buttonName == "no" || buttonName == "" {
|
||||||
gomu.pages.RemovePage("confirmation-popup")
|
gomu.pages.RemovePage("confirmation-popup")
|
||||||
gomu.app.SetFocus(gomu.prevPanel.(tview.Primitive))
|
gomu.popups.pop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +250,7 @@ func (p *Playlist) deleteSong(audioFile *AudioFile) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gomu.pages.RemovePage("confirmation-popup")
|
gomu.pages.RemovePage("confirmation-popup")
|
||||||
gomu.app.SetFocus(gomu.prevPanel.(tview.Primitive))
|
gomu.popups.pop()
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
68
popup.go
68
popup.go
@ -18,6 +18,49 @@ var (
|
|||||||
popupCounter = 0
|
popupCounter = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Simple stack data structure
|
||||||
|
type Stack struct {
|
||||||
|
popups []tview.Primitive
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push popup to the stack and focus
|
||||||
|
func (s *Stack) push(p tview.Primitive) {
|
||||||
|
s.popups = append(s.popups, p)
|
||||||
|
gomu.app.SetFocus(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show item on the top of the stack
|
||||||
|
func (s *Stack) peekTop() tview.Primitive {
|
||||||
|
|
||||||
|
if len(s.popups)-1 < 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.popups[len(s.popups)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove popup from the stack and focus previous popup
|
||||||
|
func (s *Stack) pop() tview.Primitive {
|
||||||
|
|
||||||
|
if len(s.popups) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
last := s.popups[len(s.popups)-1]
|
||||||
|
res := s.popups[:len(s.popups)-1]
|
||||||
|
s.popups = res
|
||||||
|
|
||||||
|
// focus previous popup
|
||||||
|
if len(s.popups) > 0 {
|
||||||
|
gomu.app.SetFocus(s.popups[len(s.popups)-1])
|
||||||
|
} else {
|
||||||
|
// focus the panel if no popup left
|
||||||
|
gomu.app.SetFocus(gomu.prevPanel.(tview.Primitive))
|
||||||
|
}
|
||||||
|
|
||||||
|
return last
|
||||||
|
}
|
||||||
|
|
||||||
// Gets popup timeout from config file
|
// Gets popup timeout from config file
|
||||||
func getPopupTimeout() time.Duration {
|
func getPopupTimeout() time.Duration {
|
||||||
|
|
||||||
@ -48,7 +91,8 @@ func confirmationPopup(
|
|||||||
|
|
||||||
gomu.pages.
|
gomu.pages.
|
||||||
AddPage("confirmation-popup", center(modal, 40, 10), true, true)
|
AddPage("confirmation-popup", center(modal, 40, 10), true, true)
|
||||||
gomu.app.SetFocus(modal)
|
|
||||||
|
gomu.popups.push(modal)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +151,16 @@ func timedPopup(
|
|||||||
time.Sleep(timeout)
|
time.Sleep(timeout)
|
||||||
gomu.pages.RemovePage(popupId)
|
gomu.pages.RemovePage(popupId)
|
||||||
gomu.app.Draw()
|
gomu.app.Draw()
|
||||||
gomu.app.SetFocus(gomu.prevPanel.(tview.Primitive))
|
|
||||||
|
// timed popup shouldn't get focused
|
||||||
|
// this here check if another popup exists and focus that instead of panel
|
||||||
|
// if none continue focus panel
|
||||||
|
topPopup := gomu.popups.peekTop()
|
||||||
|
if topPopup == nil {
|
||||||
|
gomu.app.SetFocus(gomu.prevPanel.(tview.Primitive))
|
||||||
|
} else {
|
||||||
|
gomu.app.SetFocus(topPopup)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +239,7 @@ func helpPopup(panel Panel) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
gomu.pages.AddPage("help-page", center(list, 50, 30), true, true)
|
gomu.pages.AddPage("help-page", center(list, 50, 30), true, true)
|
||||||
gomu.app.SetFocus(list)
|
gomu.popups.push(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input popup. Takes video url from youtube to be downloaded
|
// Input popup. Takes video url from youtube to be downloaded
|
||||||
@ -226,7 +279,7 @@ func downloadMusicPopup(selPlaylist *tview.TreeNode) {
|
|||||||
gomu.pages.
|
gomu.pages.
|
||||||
AddPage("download-input-popup", center(inputField, 50, 4), true, true)
|
AddPage("download-input-popup", center(inputField, 50, 4), true, true)
|
||||||
|
|
||||||
gomu.app.SetFocus(inputField)
|
gomu.popups.push(inputField)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,17 +310,18 @@ func createPlaylistPopup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gomu.pages.RemovePage("mkdir-input-popup")
|
gomu.pages.RemovePage("mkdir-input-popup")
|
||||||
gomu.app.SetFocus(gomu.prevPanel.(tview.Primitive))
|
gomu.popups.pop()
|
||||||
|
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
gomu.pages.RemovePage("mkdir-input-popup")
|
gomu.pages.RemovePage("mkdir-input-popup")
|
||||||
gomu.app.SetFocus(gomu.prevPanel.(tview.Primitive))
|
gomu.popups.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
gomu.pages.
|
gomu.pages.
|
||||||
AddPage("mkdir-input-popup", center(inputField, 50, 4), true, true)
|
AddPage("mkdir-input-popup", center(inputField, 50, 4), true, true)
|
||||||
gomu.app.SetFocus(inputField)
|
|
||||||
|
gomu.popups.push(inputField)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user