diff options
Diffstat (limited to 'pkg/gui/controllers')
-rw-r--r-- | pkg/gui/controllers/attach.go | 1 | ||||
-rw-r--r-- | pkg/gui/controllers/base_controller.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/commitish_controller.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/commits_files_controller.go | 10 | ||||
-rw-r--r-- | pkg/gui/controllers/files_controller.go | 28 | ||||
-rw-r--r-- | pkg/gui/controllers/list_controller.go | 83 | ||||
-rw-r--r-- | pkg/gui/controllers/local_commits_controller.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/menu_controller.go | 8 | ||||
-rw-r--r-- | pkg/gui/controllers/remotes_controller.go | 8 | ||||
-rw-r--r-- | pkg/gui/controllers/sub_commits_switch_controller.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/submodules_controller.go | 8 |
11 files changed, 101 insertions, 61 deletions
diff --git a/pkg/gui/controllers/attach.go b/pkg/gui/controllers/attach.go index 008c15505..3e621c54c 100644 --- a/pkg/gui/controllers/attach.go +++ b/pkg/gui/controllers/attach.go @@ -6,5 +6,6 @@ func AttachControllers(context types.Context, controllers ...types.IController) for _, controller := range controllers { context.AddKeybindingsFn(controller.GetKeybindings) context.AddMouseKeybindingsFn(controller.GetMouseKeybindings) + context.AddOnClickFn(controller.GetOnClick()) } } diff --git a/pkg/gui/controllers/base_controller.go b/pkg/gui/controllers/base_controller.go index e510c1a9f..db7ad7a40 100644 --- a/pkg/gui/controllers/base_controller.go +++ b/pkg/gui/controllers/base_controller.go @@ -14,3 +14,7 @@ func (self *baseController) GetKeybindings(opts types.KeybindingsOpts) []*types. func (self *baseController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { return nil } + +func (self *baseController) GetOnClick() func() error { + return nil +} diff --git a/pkg/gui/controllers/commitish_controller.go b/pkg/gui/controllers/commitish_controller.go index b570e4aba..04e271253 100644 --- a/pkg/gui/controllers/commitish_controller.go +++ b/pkg/gui/controllers/commitish_controller.go @@ -58,6 +58,10 @@ func (self *CommitishController) GetKeybindings(opts types.KeybindingsOpts) []*t return bindings } +func (self *CommitishController) GetOnClick() func() error { + return self.checkSelected(self.enter) +} + func (self *CommitishController) checkSelected(callback func(string) error) func() error { return func() error { refName := self.context.GetSelectedRefName() diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 5eed10883..d0015faff 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -70,9 +70,10 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) [] func (self *CommitFilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { return []*gocui.ViewMouseBinding{ { - ViewName: "main", - Key: gocui.MouseLeft, - Handler: self.onClickMain, + ViewName: "main", + Key: gocui.MouseLeft, + Handler: self.onClickMain, + FromContext: string(self.context().GetKey()), }, } } @@ -97,12 +98,11 @@ func (self *CommitFilesController) context() *context.CommitFilesContext { } func (self *CommitFilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error { - clickedViewLineIdx := opts.Cy + opts.Oy node := self.context().GetSelectedFileNode() if node == nil { return nil } - return self.enterCommitFile(node, types.OnFocusOpts{ClickedViewName: "main", ClickedViewLineIdx: clickedViewLineIdx}) + return self.enterCommitFile(node, types.OnFocusOpts{ClickedViewName: "main", ClickedViewLineIdx: opts.Y}) } func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error { diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 5f6ccec7e..b10efc15c 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -50,10 +50,6 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types Handler: self.checkSelectedFileNode(self.press), Description: self.c.Tr.LcToggleStaged, }, - // { - // Key: gocui.MouseLeft, - // Handler: func() error { return self.context().HandleClick(self.checkSelectedFileNode(self.press)) }, - // }, { Key: opts.GetKey("<c-b>"), // TODO: softcode Handler: self.handleStatusFilterPressed, @@ -153,18 +149,24 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { return []*gocui.ViewMouseBinding{ { - ViewName: "main", - Key: gocui.MouseLeft, - Handler: self.onClickMain, + ViewName: "main", + Key: gocui.MouseLeft, + Handler: self.onClickMain, + FromContext: string(self.context().GetKey()), }, { - ViewName: "secondary", - Key: gocui.MouseLeft, - Handler: self.onClickSecondary, + ViewName: "secondary", + Key: gocui.MouseLeft, + Handler: self.onClickSecondary, + FromContext: string(self.context().GetKey()), }, } } +func (self *FilesController) GetOnClick() func() error { + return self.checkSelectedFileNode(self.press) +} + func (self *FilesController) press(node *filetree.FileNode) error { if node.IsLeaf() { file := node.File @@ -631,13 +633,11 @@ func (self *FilesController) handleStashSave(stashFunc func(message string) erro } func (self *FilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error { - clickedViewLineIdx := opts.Cy + opts.Oy - return self.EnterFile(types.OnFocusOpts{ClickedViewName: "main", ClickedViewLineIdx: clickedViewLineIdx}) + return self.EnterFile(types.OnFocusOpts{ClickedViewName: "main", ClickedViewLineIdx: opts.Y}) } func (self *FilesController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error { - clickedViewLineIdx := opts.Cy + opts.Oy - return self.EnterFile(types.OnFocusOpts{ClickedViewName: "secondary", ClickedViewLineIdx: clickedViewLineIdx}) + return self.EnterFile(types.OnFocusOpts{ClickedViewName: "secondary", ClickedViewLineIdx: opts.Y}) } func (self *FilesController) fetch() error { diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go index 5b1d2e04a..c9898f908 100644 --- a/pkg/gui/controllers/list_controller.go +++ b/pkg/gui/controllers/list_controller.go @@ -61,6 +61,10 @@ func (self *ListController) handleLineChange(change int) error { self.context.GetList().MoveSelectedLine(change) after := self.context.GetList().GetSelectedLineIdx() + if err := self.pushContextIfNotFocused(); err != nil { + return err + } + // doing this check so that if we're holding the up key at the start of the list // we're not constantly re-rendering the main view. if before != after { @@ -86,20 +90,13 @@ func (self *ListController) HandleGotoBottom() error { return self.handleLineChange(self.context.GetList().GetItemsLength()) } -func (self *ListController) HandleClick(onClick func() error) error { +func (self *ListController) HandleClick(opts gocui.ViewMouseBindingOpts) error { prevSelectedLineIdx := self.context.GetList().GetSelectedLineIdx() - // because we're handling a click, we need to determine the new line idx based - // on the view itself. - newSelectedLineIdx := self.context.GetViewTrait().SelectedLineIdx() + newSelectedLineIdx := opts.Y + alreadyFocused := self.isFocused() - currentContextKey := self.c.CurrentContext().GetKey() - alreadyFocused := currentContextKey == self.context.GetKey() - - // we need to focus the view - if !alreadyFocused { - if err := self.c.PushContext(self.context); err != nil { - return err - } + if err := self.pushContextIfNotFocused(); err != nil { + return err } if newSelectedLineIdx > self.context.GetList().GetItemsLength()-1 { @@ -108,26 +105,37 @@ func (self *ListController) HandleClick(onClick func() error) error { self.context.GetList().SetSelectedLineIdx(newSelectedLineIdx) - if prevSelectedLineIdx == newSelectedLineIdx && alreadyFocused && onClick != nil { - return onClick() + if prevSelectedLineIdx == newSelectedLineIdx && alreadyFocused && self.context.GetOnClick() != nil { + return self.context.GetOnClick()() } return self.context.HandleFocus() } +func (self *ListController) pushContextIfNotFocused() error { + if !self.isFocused() { + if err := self.c.PushContext(self.context); err != nil { + return err + } + } + + return nil +} + +func (self *ListController) isFocused() bool { + return self.c.CurrentContext().GetKey() == self.context.GetKey() +} + func (self *ListController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { return []*types.Binding{ - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItem), Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, - {Tag: "navigation", Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.HandleNextLine}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItem), Modifier: gocui.ModNone, Handler: self.HandleNextLine}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevPage), Modifier: gocui.ModNone, Handler: self.HandlePrevPage, Description: self.c.Tr.LcPrevPage}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextPage), Modifier: gocui.ModNone, Handler: self.HandleNextPage, Description: self.c.Tr.LcNextPage}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.GotoTop), Modifier: gocui.ModNone, Handler: self.HandleGotoTop, Description: self.c.Tr.LcGotoTop}, - {Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: func() error { return self.HandleClick(nil) }}, - {Tag: "navigation", Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: self.HandleNextLine}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: self.HandleScrollLeft}, - {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: self.HandleScrollRight}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItemAlt), Handler: self.HandlePrevLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItem), Handler: self.HandlePrevLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItemAlt), Handler: self.HandleNextLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItem), Handler: self.HandleNextLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevPage), Handler: self.HandlePrevPage, Description: self.c.Tr.LcPrevPage}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextPage), Handler: self.HandleNextPage, Description: self.c.Tr.LcNextPage}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.GotoTop), Handler: self.HandleGotoTop, Description: self.c.Tr.LcGotoTop}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollLeft), Handler: self.HandleScrollLeft}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollRight), Handler: self.HandleScrollRight}, { Key: opts.GetKey(opts.Config.Universal.StartSearch), Handler: func() error { self.c.OpenSearch(); return nil }, @@ -142,3 +150,26 @@ func (self *ListController) GetKeybindings(opts types.KeybindingsOpts) []*types. }, } } + +func (self *ListController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { + return []*gocui.ViewMouseBinding{ + { + ViewName: self.context.GetViewName(), + ToContext: string(self.context.GetKey()), + Key: gocui.MouseWheelUp, + Handler: func(gocui.ViewMouseBindingOpts) error { return self.HandlePrevLine() }, + }, + { + ViewName: self.context.GetViewName(), + ToContext: string(self.context.GetKey()), + Key: gocui.MouseLeft, + Handler: func(opts gocui.ViewMouseBindingOpts) error { return self.HandleClick(opts) }, + }, + { + ViewName: self.context.GetViewName(), + ToContext: string(self.context.GetKey()), + Key: gocui.MouseWheelDown, + Handler: func(gocui.ViewMouseBindingOpts) error { return self.HandleNextLine() }, + }, + } +} diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 1693f19c3..b54cfa3c0 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -136,10 +136,6 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ Description: self.c.Tr.LcGotoBottom, Tag: "navigation", }, - // { - // Key: gocui.MouseLeft, - // Handler: func() error { return self.context().HandleClick(self.checkSelected(self.enter)) }, - // }, } for _, binding := range outsideFilterModeBindings { diff --git a/pkg/gui/controllers/menu_controller.go b/pkg/gui/controllers/menu_controller.go index 91e85dec5..f217c993a 100644 --- a/pkg/gui/controllers/menu_controller.go +++ b/pkg/gui/controllers/menu_controller.go @@ -35,15 +35,15 @@ func (self *MenuController) GetKeybindings(opts types.KeybindingsOpts) []*types. Key: opts.GetKey(opts.Config.Universal.ConfirmAlt1), Handler: self.press, }, - // { - // Key: gocui.MouseLeft, - // Handler: func() error { return self.context.HandleClick(self.press) }, - // }, } return bindings } +func (self *MenuController) GetOnClick() func() error { + return self.press +} + func (self *MenuController) press() error { selectedItem := self.context().GetSelected() diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index 489454f89..fd4b34297 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -35,10 +35,6 @@ func (self *RemotesController) GetKeybindings(opts types.KeybindingsOpts) []*typ Key: opts.GetKey(opts.Config.Universal.GoInto), Handler: self.checkSelected(self.enter), }, - // { - // Key: gocui.MouseLeft, - // Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) }, - // }, { Key: opts.GetKey(opts.Config.Branches.FetchRemote), Handler: self.checkSelected(self.fetch), @@ -64,6 +60,10 @@ func (self *RemotesController) GetKeybindings(opts types.KeybindingsOpts) []*typ return bindings } +func (self *RemotesController) GetOnClick() func() error { + return self.checkSelected(self.enter) +} + func (self *RemotesController) enter(remote *models.Remote) error { // naive implementation: get the branches from the remote and render them to the list, change the context self.setRemoteBranches(remote.Branches) diff --git a/pkg/gui/controllers/sub_commits_switch_controller.go b/pkg/gui/controllers/sub_commits_switch_controller.go index cbc9ce137..4c8f086a5 100644 --- a/pkg/gui/controllers/sub_commits_switch_controller.go +++ b/pkg/gui/controllers/sub_commits_switch_controller.go @@ -57,6 +57,10 @@ func (self *SubCommitsSwitchController) GetKeybindings(opts types.KeybindingsOpt return bindings } +func (self *SubCommitsSwitchController) GetOnClick() func() error { + return self.viewCommits +} + func (self *SubCommitsSwitchController) viewCommits() error { refName := self.context.GetSelectedRefName() if refName == "" { diff --git a/pkg/gui/controllers/submodules_controller.go b/pkg/gui/controllers/submodules_controller.go index 408536960..83c05da4b 100644 --- a/pkg/gui/controllers/submodules_controller.go +++ b/pkg/gui/controllers/submodules_controller.go @@ -69,13 +69,13 @@ func (self *SubmodulesController) GetKeybindings(opts types.KeybindingsOpts) []* Description: self.c.Tr.LcViewBulkSubmoduleOptions, OpensMenu: true, }, - // { - // Key: gocui.MouseLeft, - // Handler: func() error { return self.context().HandleClick(self.checkSelected(self.enter)) }, - // }, } } +func (self *SubmodulesController) GetOnClick() func() error { + return self.checkSelected(self.enter) +} + func (self *SubmodulesController) enter(submodule *models.SubmoduleConfig) error { return self.enterSubmodule(submodule) } |