2019-11-16 05:00:27 +02:00
package gui
2020-08-19 13:51:50 +02:00
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
)
2019-11-16 05:00:27 +02:00
2020-08-22 00:49:02 +02:00
// TODO: if we don't end up using this, delete it
const (
CONTAINS_NOTHING = iota
CONTAINS_COMMITS
CONTAINS_FILES
CONTAINS_BRANCHES
)
2020-08-17 13:58:30 +02:00
type ListContext struct {
2020-08-20 00:52:51 +02:00
ViewName string
ContextKey string
GetItemsLength func ( ) int
GetDisplayStrings func ( ) [ ] [ ] string
OnFocus func ( ) error
OnFocusLost func ( ) error
OnClickSelectedItem func ( ) error
2020-08-22 01:55:49 +02:00
SelectedItem func ( ) ListItem
2020-08-20 00:52:51 +02:00
GetPanelState func ( ) IListPanelState
2020-08-19 10:06:51 +02:00
Gui * Gui
RendersToMainView bool
Kind int
2020-08-21 01:12:45 +02:00
ParentContext Context
2020-08-21 11:53:45 +02:00
WindowName string
2020-08-22 00:49:02 +02:00
Contains int
2019-11-16 05:00:27 +02:00
}
2020-08-20 00:24:35 +02:00
type ListItem interface {
2020-08-22 02:14:53 +02:00
// ID is a SHA when the item is a commit, a filename when the item is a file, 'stash@{4}' when it's a stash entry, 'my_branch' when it's a branch
2020-08-20 00:24:35 +02:00
ID ( ) string
2020-08-22 02:14:53 +02:00
// Description is something we would show in a message e.g. '123as14: push blah' for a commit
Description ( ) string
2020-08-20 00:24:35 +02:00
}
2020-08-22 01:55:49 +02:00
func ( lc * ListContext ) GetSelectedItem ( ) ListItem {
return lc . SelectedItem ( )
}
2020-08-22 00:49:02 +02:00
func ( lc * ListContext ) GetContains ( ) int {
return lc . Contains
}
2020-08-21 11:53:45 +02:00
func ( lc * ListContext ) SetWindowName ( windowName string ) {
lc . WindowName = windowName
}
func ( lc * ListContext ) GetWindowName ( ) string {
windowName := lc . WindowName
if windowName != "" {
return windowName
}
// TODO: actually set this for everything so we don't default to the view name
return lc . ViewName
}
2020-08-21 01:12:45 +02:00
func ( lc * ListContext ) SetParentContext ( c Context ) {
lc . ParentContext = c
}
func ( lc * ListContext ) GetParentContext ( ) Context {
return lc . ParentContext
}
2020-08-20 00:24:35 +02:00
func ( lc * ListContext ) GetSelectedItemId ( ) string {
2020-08-22 01:55:49 +02:00
item := lc . SelectedItem ( )
2020-08-20 00:24:35 +02:00
if item == nil {
return ""
}
return item . ID ( )
}
2020-08-19 13:51:50 +02:00
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
func ( lc * ListContext ) OnRender ( ) error {
view , err := lc . Gui . g . View ( lc . ViewName )
if err != nil {
return nil
}
if lc . GetDisplayStrings != nil {
2020-08-20 00:52:51 +02:00
lc . Gui . refreshSelectedLine ( lc . GetPanelState ( ) , lc . GetItemsLength ( ) )
2020-08-19 13:51:50 +02:00
lc . Gui . renderDisplayStrings ( view , lc . GetDisplayStrings ( ) )
}
return nil
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) GetKey ( ) string {
return lc . ContextKey
2020-08-16 05:58:29 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) GetKind ( ) int {
return lc . Kind
2020-08-16 05:58:29 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) GetViewName ( ) string {
return lc . ViewName
2020-08-16 05:58:29 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) HandleFocusLost ( ) error {
if lc . OnFocusLost != nil {
return lc . OnFocusLost ( )
2020-08-16 05:58:29 +02:00
}
return nil
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) HandleFocus ( ) error {
2020-08-19 14:27:31 +02:00
if lc . Gui . popupPanelFocused ( ) {
return nil
}
2020-08-22 00:49:02 +02:00
view , err := lc . Gui . g . View ( lc . ViewName )
if err != nil {
return nil
}
view . FocusPoint ( 0 , lc . GetPanelState ( ) . GetSelectedLineIdx ( ) )
2020-08-22 03:44:03 +02:00
if lc . Gui . State . Modes . Diffing . Active ( ) {
2020-08-19 14:27:31 +02:00
return lc . Gui . renderDiff ( )
}
2020-08-20 00:24:35 +02:00
// every time you select an item we need to store that item's ID on the context (a string). After a state refresh, after we update the selected line, we need to check if the selected item is new, in which case we will reset the origin. In the case of the merge panel we set the origin in a custom way, so it can't be as simple as just resetting the origin. for files we need to know whether we're dealing with a file with merge conflicts, and if so, we need to scroll to the file in a custom way, after rendering to the main view.
// we can use this id to know what to do once we're actually in the merging context, so that we're not affected by outside state changes.
2020-08-19 14:27:31 +02:00
if lc . OnFocus != nil {
return lc . OnFocus ( )
}
return nil
2020-08-16 05:58:29 +02:00
}
2020-08-19 10:06:51 +02:00
func ( lc * ListContext ) HandleRender ( ) error {
return lc . OnRender ( )
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handlePrevLine ( g * gocui . Gui , v * gocui . View ) error {
return lc . handleLineChange ( - 1 )
2019-11-16 05:00:27 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handleNextLine ( g * gocui . Gui , v * gocui . View ) error {
return lc . handleLineChange ( 1 )
2019-11-16 05:00:27 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handleLineChange ( change int ) error {
if ! lc . Gui . isPopupPanel ( lc . ViewName ) && lc . Gui . popupPanelFocused ( ) {
2019-11-16 05:00:27 +02:00
return nil
}
2020-08-17 13:58:30 +02:00
view , err := lc . Gui . g . View ( lc . ViewName )
2020-08-16 01:18:57 +02:00
if err != nil {
return err
}
2020-08-20 00:52:51 +02:00
lc . Gui . changeSelectedLine ( lc . GetPanelState ( ) , lc . GetItemsLength ( ) , change )
view . FocusPoint ( 0 , lc . GetPanelState ( ) . GetSelectedLineIdx ( ) )
2019-11-16 05:00:27 +02:00
2020-08-17 13:58:30 +02:00
if lc . RendersToMainView {
if err := lc . Gui . resetOrigin ( lc . Gui . getMainView ( ) ) ; err != nil {
2019-11-16 05:00:27 +02:00
return err
}
2020-08-17 13:58:30 +02:00
if err := lc . Gui . resetOrigin ( lc . Gui . getSecondaryView ( ) ) ; err != nil {
2020-08-16 01:18:57 +02:00
return err
}
2019-11-16 05:00:27 +02:00
}
2020-01-12 04:39:48 +02:00
2020-08-19 14:27:31 +02:00
return lc . HandleFocus ( )
2019-11-16 05:00:27 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handleNextPage ( g * gocui . Gui , v * gocui . View ) error {
view , err := lc . Gui . g . View ( lc . ViewName )
2020-03-28 04:44:20 +02:00
if err != nil {
return nil
}
_ , height := view . Size ( )
delta := height - 1
if delta == 0 {
delta = 1
}
2020-08-17 13:58:30 +02:00
return lc . handleLineChange ( delta )
2020-03-28 04:44:20 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handleGotoTop ( g * gocui . Gui , v * gocui . View ) error {
return lc . handleLineChange ( - lc . GetItemsLength ( ) )
2020-03-28 04:44:20 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handleGotoBottom ( g * gocui . Gui , v * gocui . View ) error {
return lc . handleLineChange ( lc . GetItemsLength ( ) )
2020-03-28 04:44:20 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handlePrevPage ( g * gocui . Gui , v * gocui . View ) error {
view , err := lc . Gui . g . View ( lc . ViewName )
2020-03-28 04:44:20 +02:00
if err != nil {
return nil
}
_ , height := view . Size ( )
delta := height - 1
if delta == 0 {
delta = 1
}
2020-08-17 13:58:30 +02:00
return lc . handleLineChange ( - delta )
2020-03-28 04:44:20 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) handleClick ( g * gocui . Gui , v * gocui . View ) error {
if ! lc . Gui . isPopupPanel ( lc . ViewName ) && lc . Gui . popupPanelFocused ( ) {
2019-11-17 08:23:06 +02:00
return nil
}
2020-08-20 00:52:51 +02:00
prevSelectedLineIdx := lc . GetPanelState ( ) . GetSelectedLineIdx ( )
2019-11-17 08:23:06 +02:00
newSelectedLineIdx := v . SelectedLineIdx ( )
2020-08-16 01:18:57 +02:00
// we need to focus the view
2020-08-17 13:58:30 +02:00
if err := lc . Gui . switchContext ( lc ) ; err != nil {
2020-08-16 01:18:57 +02:00
return err
}
2020-08-17 13:58:30 +02:00
if newSelectedLineIdx > lc . GetItemsLength ( ) - 1 {
2020-08-16 05:58:29 +02:00
return nil
2019-11-17 08:23:06 +02:00
}
2020-08-20 00:52:51 +02:00
lc . GetPanelState ( ) . SetSelectedLineIdx ( newSelectedLineIdx )
2019-11-17 08:23:06 +02:00
2020-08-17 13:58:30 +02:00
prevViewName := lc . Gui . currentViewName ( )
if prevSelectedLineIdx == newSelectedLineIdx && prevViewName == lc . ViewName && lc . OnClickSelectedItem != nil {
return lc . OnClickSelectedItem ( )
2019-11-17 08:23:06 +02:00
}
2020-08-19 14:27:31 +02:00
return lc . HandleFocus ( )
2020-08-16 01:18:57 +02:00
}
2020-08-17 13:58:30 +02:00
func ( lc * ListContext ) onSearchSelect ( selectedLineIdx int ) error {
2020-08-20 00:52:51 +02:00
lc . GetPanelState ( ) . SetSelectedLineIdx ( selectedLineIdx )
2020-08-19 14:27:31 +02:00
return lc . HandleFocus ( )
2020-08-16 01:18:57 +02:00
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) menuListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "menu" ,
ContextKey : "menu" ,
GetItemsLength : func ( ) int { return gui . getMenuView ( ) . LinesHeight ( ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . Menu } ,
OnFocus : gui . handleMenuSelect ,
2020-08-16 01:18:57 +02:00
// need to add a layer of indirection here because the callback changes during runtime
2020-08-16 02:05:45 +02:00
OnClickSelectedItem : func ( ) error { return gui . State . Panels . Menu . OnPress ( gui . g , nil ) } ,
Gui : gui ,
RendersToMainView : false ,
2020-08-16 05:58:29 +02:00
Kind : PERSISTENT_POPUP ,
2020-08-22 00:49:02 +02:00
Contains : CONTAINS_NOTHING ,
2020-08-19 13:51:50 +02:00
// no GetDisplayStrings field because we do a custom render on menu creation
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) filesListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "files" ,
2020-08-20 11:42:58 +02:00
ContextKey : FILES_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . Files ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . Files } ,
OnFocus : gui . focusAndSelectFile ,
OnClickSelectedItem : gui . handleFilePress ,
Gui : gui ,
RendersToMainView : false ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetFileListDisplayStrings ( gui . State . Files , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_NOTHING ,
SelectedItem : func ( ) ListItem { return gui . getSelectedFile ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) branchesListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "branches" ,
2020-08-20 11:42:58 +02:00
ContextKey : LOCAL_BRANCHES_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . Branches ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . Branches } ,
OnFocus : gui . handleBranchSelect ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetBranchListDisplayStrings ( gui . State . Branches , gui . State . ScreenMode != SCREEN_NORMAL , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_COMMITS ,
SelectedItem : func ( ) ListItem { return gui . getSelectedBranch ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) remotesListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "branches" ,
2020-08-20 11:42:58 +02:00
ContextKey : REMOTES_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . Remotes ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . Remotes } ,
OnFocus : gui . handleRemoteSelect ,
OnClickSelectedItem : gui . handleRemoteEnter ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetRemoteListDisplayStrings ( gui . State . Remotes , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_BRANCHES ,
SelectedItem : func ( ) ListItem { return gui . getSelectedRemote ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) remoteBranchesListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "branches" ,
2020-08-20 11:42:58 +02:00
ContextKey : REMOTE_BRANCHES_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . RemoteBranches ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . RemoteBranches } ,
OnFocus : gui . handleRemoteBranchSelect ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetRemoteBranchListDisplayStrings ( gui . State . RemoteBranches , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_COMMITS ,
SelectedItem : func ( ) ListItem { return gui . getSelectedRemoteBranch ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) tagsListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "branches" ,
2020-08-20 11:42:58 +02:00
ContextKey : TAGS_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . Tags ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . Tags } ,
OnFocus : gui . handleTagSelect ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetTagListDisplayStrings ( gui . State . Tags , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_COMMITS ,
SelectedItem : func ( ) ListItem { return gui . getSelectedTag ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) branchCommitsListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "commits" ,
2020-08-20 11:42:58 +02:00
ContextKey : BRANCH_COMMITS_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . Commits ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . Commits } ,
OnFocus : gui . handleCommitSelect ,
2020-08-21 01:12:45 +02:00
OnClickSelectedItem : gui . handleViewCommitFiles ,
2020-08-20 00:52:51 +02:00
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetCommitListDisplayStrings ( gui . State . Commits , gui . State . ScreenMode != SCREEN_NORMAL , gui . CherryPickedCommitShaMap ( ) , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_FILES ,
SelectedItem : func ( ) ListItem { return gui . getSelectedLocalCommit ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) reflogCommitsListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "commits" ,
2020-08-20 11:42:58 +02:00
ContextKey : REFLOG_COMMITS_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . FilteredReflogCommits ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . ReflogCommits } ,
OnFocus : gui . handleReflogCommitSelect ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetReflogCommitListDisplayStrings ( gui . State . FilteredReflogCommits , gui . State . ScreenMode != SCREEN_NORMAL , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_FILES ,
SelectedItem : func ( ) ListItem { return gui . getSelectedReflogCommit ( ) } ,
2020-08-22 00:49:02 +02:00
}
}
func ( gui * Gui ) subCommitsListContext ( ) * ListContext {
return & ListContext {
ViewName : "branches" ,
ContextKey : SUB_COMMITS_CONTEXT_KEY ,
GetItemsLength : func ( ) int { return len ( gui . State . SubCommits ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . SubCommits } ,
OnFocus : gui . handleSubCommitSelect ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:44:03 +02:00
gui . Log . Warn ( "getting display strings for sub commits" )
2020-08-22 03:05:37 +02:00
return presentation . GetCommitListDisplayStrings ( gui . State . SubCommits , gui . State . ScreenMode != SCREEN_NORMAL , gui . CherryPickedCommitShaMap ( ) , gui . State . Modes . Diffing . Ref )
2020-08-22 00:49:02 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_COMMITS ,
SelectedItem : func ( ) ListItem { return gui . getSelectedSubCommit ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) stashListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "stash" ,
2020-08-20 11:42:58 +02:00
ContextKey : STASH_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . StashEntries ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . Stash } ,
OnFocus : gui . handleStashEntrySelect ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetStashEntryListDisplayStrings ( gui . State . StashEntries , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_FILES ,
SelectedItem : func ( ) ListItem { return gui . getSelectedStashEntry ( ) } ,
2020-08-16 01:18:57 +02:00
}
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) commitFilesListContext ( ) * ListContext {
return & ListContext {
2020-08-20 00:52:51 +02:00
ViewName : "commitFiles" ,
2020-08-21 11:53:45 +02:00
WindowName : "commits" ,
2020-08-20 11:42:58 +02:00
ContextKey : COMMIT_FILES_CONTEXT_KEY ,
2020-08-20 00:52:51 +02:00
GetItemsLength : func ( ) int { return len ( gui . State . CommitFiles ) } ,
GetPanelState : func ( ) IListPanelState { return gui . State . Panels . CommitFiles } ,
OnFocus : gui . handleCommitFileSelect ,
Gui : gui ,
RendersToMainView : true ,
Kind : SIDE_CONTEXT ,
2020-08-19 13:51:50 +02:00
GetDisplayStrings : func ( ) [ ] [ ] string {
2020-08-22 03:05:37 +02:00
return presentation . GetCommitFileListDisplayStrings ( gui . State . CommitFiles , gui . State . Modes . Diffing . Ref )
2020-08-19 13:51:50 +02:00
} ,
2020-08-22 01:55:49 +02:00
Contains : CONTAINS_NOTHING ,
SelectedItem : func ( ) ListItem { return gui . getSelectedCommitFile ( ) } ,
2020-08-16 01:18:57 +02:00
}
2019-11-17 08:23:06 +02:00
}
2020-08-17 13:58:30 +02:00
func ( gui * Gui ) getListContexts ( ) [ ] * ListContext {
return [ ] * ListContext {
gui . menuListContext ( ) ,
gui . filesListContext ( ) ,
gui . branchesListContext ( ) ,
gui . remotesListContext ( ) ,
gui . remoteBranchesListContext ( ) ,
gui . tagsListContext ( ) ,
gui . branchCommitsListContext ( ) ,
gui . reflogCommitsListContext ( ) ,
2020-08-22 00:49:02 +02:00
gui . subCommitsListContext ( ) ,
2020-08-17 13:58:30 +02:00
gui . stashListContext ( ) ,
gui . commitFilesListContext ( ) ,
2019-11-16 05:00:27 +02:00
}
}
2020-08-17 14:05:15 +02:00
func ( gui * Gui ) getListContextKeyBindings ( ) [ ] * Binding {
bindings := make ( [ ] * Binding , 0 )
for _ , listContext := range gui . getListContexts ( ) {
bindings = append ( bindings , [ ] * Binding {
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gui . getKey ( "universal.prevItem-alt" ) , Modifier : gocui . ModNone , Handler : listContext . handlePrevLine } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gui . getKey ( "universal.prevItem" ) , Modifier : gocui . ModNone , Handler : listContext . handlePrevLine } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gocui . MouseWheelUp , Modifier : gocui . ModNone , Handler : listContext . handlePrevLine } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gui . getKey ( "universal.nextItem-alt" ) , Modifier : gocui . ModNone , Handler : listContext . handleNextLine } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gui . getKey ( "universal.nextItem" ) , Modifier : gocui . ModNone , Handler : listContext . handleNextLine } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gui . getKey ( "universal.prevPage" ) , Modifier : gocui . ModNone , Handler : listContext . handlePrevPage , Description : gui . Tr . SLocalize ( "prevPage" ) } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gui . getKey ( "universal.nextPage" ) , Modifier : gocui . ModNone , Handler : listContext . handleNextPage , Description : gui . Tr . SLocalize ( "nextPage" ) } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gui . getKey ( "universal.gotoTop" ) , Modifier : gocui . ModNone , Handler : listContext . handleGotoTop , Description : gui . Tr . SLocalize ( "gotoTop" ) } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gocui . MouseWheelDown , Modifier : gocui . ModNone , Handler : listContext . handleNextLine } ,
{ ViewName : listContext . ViewName , Contexts : [ ] string { listContext . ContextKey } , Key : gocui . MouseLeft , Modifier : gocui . ModNone , Handler : listContext . handleClick } ,
} ... )
// the commits panel needs to lazyload things so it has a couple of its own handlers
openSearchHandler := gui . handleOpenSearch
gotoBottomHandler := listContext . handleGotoBottom
if listContext . ViewName == "commits" {
openSearchHandler = gui . handleOpenSearchForCommitsPanel
gotoBottomHandler = gui . handleGotoBottomForCommitsPanel
}
bindings = append ( bindings , [ ] * Binding {
{
ViewName : listContext . ViewName ,
Contexts : [ ] string { listContext . ContextKey } ,
Key : gui . getKey ( "universal.startSearch" ) ,
Handler : openSearchHandler ,
Description : gui . Tr . SLocalize ( "startSearch" ) ,
} ,
{
ViewName : listContext . ViewName ,
Contexts : [ ] string { listContext . ContextKey } ,
Key : gui . getKey ( "universal.gotoBottom" ) ,
Handler : gotoBottomHandler ,
Description : gui . Tr . SLocalize ( "gotoBottom" ) ,
} ,
} ... )
}
return bindings
}