Files
MujicaUI/git/stash_list.go
T

61 lines
1.9 KiB
Go

package git
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/data"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/icons"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
)
// Stash is one stash entry.
type Stash struct {
// Ref names the entry, as stash@{0}.
Ref string
Message string
Branch string
}
// StashListOptions configure a StashList.
type StashListOptions struct {
// Status and Error show the load state.
Status data.DataStatus
Error string
}
// StashList shows stashes with apply, pop and drop actions.
func StashList(c *ui.Context, s *data.ListState[string], stashes []Stash, opts StashListOptions) GitListResult {
var r GitListResult
k := core.Tokens(c)
actions := []GitAction{
{ID: "apply", Label: core.Msg(c, "stash_list.apply"), Icon: "check"},
{ID: "pop", Label: core.Msg(c, "stash_list.pop"), Icon: "upload"},
{ID: "drop", Label: core.Msg(c, "stash_list.drop"), Icon: "trash-2"},
}
v := data.List(c, s, len(stashes), data.ListOptions[string]{
Key: func(i int) string { return stashListKey(stashes[i]) },
Label: func(i int) string { return stashes[i].Message },
Status: opts.Status, Error: opts.Error, Empty: core.Msg(c, "stash_list.empty"),
}, func(i int) {
st := stashes[i]
small := core.FontSize(c, theme.CaptionSize)
ui.Icon(c, icons.Must("archive")).Size(14, 14).Shrink(0).TextColor(k.TextMuted)
ui.Text(c, st.Ref).Font(theme.MonoFont).FontSize(small).TextColor(k.AccentText).Shrink(0)
ui.Text(c, st.Message).SingleLine().Grow(1).MinWidth(0)
if st.Branch != "" {
ui.Text(c, st.Branch).FontSize(small).TextColor(k.TextMuted).SingleLine().MaxWidth(140).Shrink(0)
}
gitRowActions(c, actions, st.Ref, &r)
})
r.Element, r.changed, r.submitted = v.Element, v.Changed(), v.Submitted()
return r
}
func stashListKey(s Stash) string {
if s.Ref == "" {
panic("mujica: Stash needs a Ref")
}
return s.Ref
}