pelican/internal/ui/keymappings.go

149 lines
3.2 KiB
Go
Raw Normal View History

package ui
import (
"fmt"
"github.com/gdamore/tcell/v2"
)
func (a *App) inputCapture() func(event *tcell.EventKey) *tcell.EventKey {
return func(event *tcell.EventKey) *tcell.EventKey {
key, character := event.Key(), event.Rune()
switch {
case character == 'h' || key == tcell.KeyLeft:
a.shiftColumnFocus(previous)
case character == 'l' || key == tcell.KeyRight:
a.shiftColumnFocus(next)
case character == 'c':
a.create()
case character == 'm':
a.move()
case character == 'e':
a.edit()
case character == 'b':
a.updateBoardMode(boardEdit)
case key == tcell.KeyCtrlD:
a.delete()
case key == tcell.KeyCtrlQ:
a.quit()
case key == tcell.KeyESC:
a.escape()
case key == tcell.KeyEnter:
a.selected()
}
return event
}
}
func (a *App) create() {
switch a.mode {
case normal:
a.cardForm.mode = create
a.cardForm.updateInputFields("", "")
a.cardForm.frame.SetTitle(" Create Card ")
a.pages.ShowPage(cardFormPage)
a.SetFocus(a.cardForm)
case boardEdit:
a.statusForm.mode = create
a.statusForm.updateInputFields("")
a.statusForm.frame.SetTitle(" Create Status ")
a.pages.ShowPage(statusFormPage)
a.SetFocus(a.statusForm)
}
}
func (a *App) move() {
if a.mode == normal {
a.statusSelection.cardID = a.focusedCardID()
a.statusSelection.currentStatusID = a.focusedStatusID()
a.updateBoardMode(selection)
}
}
func (a *App) edit() {
switch a.mode {
case normal:
a.cardForm.mode = edit
card, ok := a.getFocusedCard()
if !ok {
return
}
a.cardForm.updateInputFields(card.Title, card.Description)
a.cardForm.frame.SetTitle(" Edit Card ")
a.pages.ShowPage(cardFormPage)
a.SetFocus(a.cardForm)
case boardEdit:
a.statusForm.mode = edit
statusName := a.focusedStatusName()
a.statusForm.updateInputFields(statusName)
a.statusForm.frame.SetTitle(" Edit Status Name ")
a.pages.ShowPage(statusFormPage)
a.SetFocus(a.statusForm)
}
}
func (a *App) delete() {
if a.mode == normal {
card, ok := a.getFocusedCard()
if !ok {
return
}
text := fmt.Sprintf("Do you want to delete '%s'?", card.Title)
a.deleteCardModal.SetText(text)
a.pages.ShowPage(deleteCardModalPage)
a.SetFocus(a.deleteCardModal)
}
}
func (a *App) quit() {
if a.mode == normal {
a.pages.ShowPage(quitPage)
a.SetFocus(a.quitModal)
}
}
func (a *App) selected() {
switch a.mode {
case normal:
card, ok := a.getFocusedCard()
if !ok {
break
}
status := a.focusedStatusName()
a.cardView.setText(card.ID, card.Title, status, card.Created, card.Description)
a.pages.ShowPage(viewPage)
a.SetFocus(a.cardView)
case selection:
a.statusSelection.nextStatusID = a.focusedStatusID()
if a.statusSelection.currentStatusID != a.statusSelection.nextStatusID {
if err := a.statusSelection.moveCard(a.board); err != nil {
a.statusbar.displayMessage(
errorLevel,
fmt.Sprintf("Failed to move card: %v", err),
)
} else {
a.statusbar.displayMessage(
infoLevel,
"Card moved successfully.",
)
}
}
a.statusSelection = statusSelection{0, 0, 0}
a.updateBoardMode(normal)
a.refresh(refreshArgs{updateFocusedColumnOnly: false, reinitialiseColumns: false})
}
}
func (a *App) escape() {
if a.mode != normal {
a.updateBoardMode(normal)
}
}