1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-18 05:17:55 +02:00
lazygit/pkg/gui/context/suggestions_context.go

50 lines
1.2 KiB
Go
Raw Normal View History

2022-02-05 17:04:10 +11:00
package context
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type SuggestionsContext struct {
2022-03-19 09:31:52 +11:00
*BasicViewModel[*types.Suggestion]
2022-02-05 17:04:10 +11:00
*ListContextTrait
}
var _ types.IListContext = (*SuggestionsContext)(nil)
func NewSuggestionsContext(
getModel func() []*types.Suggestion,
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
2022-02-06 15:54:26 +11:00
c *types.HelperCommon,
2022-02-05 17:04:10 +11:00
) *SuggestionsContext {
2022-03-19 09:31:52 +11:00
viewModel := NewBasicViewModel(getModel)
2022-02-05 17:04:10 +11:00
return &SuggestionsContext{
2022-03-19 09:31:52 +11:00
BasicViewModel: viewModel,
2022-02-05 17:04:10 +11:00
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
2022-08-07 19:13:19 +10:00
View: view,
WindowName: "suggestions",
Key: SUGGESTIONS_CONTEXT_KEY,
Kind: types.PERSISTENT_POPUP,
Focusable: true,
HasUncontrolledBounds: true,
}), ContextCallbackOpts{}),
2022-02-05 17:04:10 +11:00
list: viewModel,
getDisplayStrings: getDisplayStrings,
c: c,
},
}
}
func (self *SuggestionsContext) GetSelectedItemId() string {
item := self.GetSelected()
if item == nil {
return ""
}
return item.Value
}