From ade54b38c12079ba133e9c8810af2a3760afb0f3 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 23 Aug 2020 10:13:56 +1000 Subject: cleanup --- pkg/commands/patch/patch_manager.go | 1 + pkg/gui/context.go | 16 ++++++++-------- pkg/gui/list_context.go | 13 ++++++------- pkg/gui/patch_options_panel.go | 4 ++-- pkg/gui/sub_commits_panel.go | 2 -- pkg/gui/window.go | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go index 29385479b..2c08da67a 100644 --- a/pkg/commands/patch/patch_manager.go +++ b/pkg/commands/patch/patch_manager.go @@ -36,6 +36,7 @@ type PatchManager struct { Reverse bool // CanRebase tells us whether we're allowed to modify our commits. CanRebase should be true for commits of the currently checked out branch and false for everything else + // TODO: move this out into a proper mode struct in the gui package: it doesn't really belong here CanRebase bool // fileInfoMap starts empty but you add files to it as you go along diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 78aafba37..fe444321c 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -210,7 +210,7 @@ func (gui *Gui) contextTree() ContextTree { }, Kind: MAIN_CONTEXT, ViewName: "main", - Key: "normal", + Key: MAIN_NORMAL_CONTEXT_KEY, }, }, Staging: SimpleContextNode{ @@ -222,7 +222,7 @@ func (gui *Gui) contextTree() ContextTree { }, Kind: MAIN_CONTEXT, ViewName: "main", - Key: "staging", + Key: MAIN_STAGING_CONTEXT_KEY, }, }, PatchBuilding: SimpleContextNode{ @@ -234,7 +234,7 @@ func (gui *Gui) contextTree() ContextTree { }, Kind: MAIN_CONTEXT, ViewName: "main", - Key: "patchBuilding", + Key: MAIN_PATCH_BUILDING_CONTEXT_KEY, }, }, Merging: SimpleContextNode{ @@ -246,7 +246,7 @@ func (gui *Gui) contextTree() ContextTree { }, Kind: MAIN_CONTEXT, ViewName: "main", - Key: "merging", + Key: MAIN_MERGING_CONTEXT_KEY, }, }, Credentials: SimpleContextNode{ @@ -254,7 +254,7 @@ func (gui *Gui) contextTree() ContextTree { OnFocus: func() error { return gui.handleCredentialsViewFocused() }, Kind: PERSISTENT_POPUP, ViewName: "credentials", - Key: "credentials", + Key: CREDENTIALS_CONTEXT_KEY, }, }, Confirmation: SimpleContextNode{ @@ -262,7 +262,7 @@ func (gui *Gui) contextTree() ContextTree { OnFocus: func() error { return nil }, Kind: TEMPORARY_POPUP, ViewName: "confirmation", - Key: "confirmation", + Key: CONFIRMATION_CONTEXT_KEY, }, }, CommitMessage: SimpleContextNode{ @@ -270,7 +270,7 @@ func (gui *Gui) contextTree() ContextTree { OnFocus: func() error { return gui.handleCommitMessageFocused() }, Kind: PERSISTENT_POPUP, ViewName: "commitMessage", - Key: "commitMessage", + Key: COMMIT_MESSAGE_CONTEXT_KEY, }, }, Search: SimpleContextNode{ @@ -278,7 +278,7 @@ func (gui *Gui) contextTree() ContextTree { OnFocus: func() error { return nil }, Kind: PERSISTENT_POPUP, ViewName: "search", - Key: "search", + Key: SEARCH_CONTEXT_KEY, }, }, } diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index d3894d7a3..23a96952d 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -232,13 +232,12 @@ func (lc *ListContext) onSearchSelect(selectedLineIdx int) error { func (gui *Gui) menuListContext() *ListContext { return &ListContext{ - ViewName: "menu", - ContextKey: "menu", - GetItemsLength: func() int { return gui.getMenuView().LinesHeight() }, - GetPanelState: func() IListPanelState { return gui.State.Panels.Menu }, - OnFocus: gui.handleMenuSelect, - // need to add a layer of indirection here because the callback changes during runtime - OnClickSelectedItem: func() error { return gui.State.Panels.Menu.OnPress() }, + ViewName: "menu", + ContextKey: "menu", + GetItemsLength: func() int { return gui.getMenuView().LinesHeight() }, + GetPanelState: func() IListPanelState { return gui.State.Panels.Menu }, + OnFocus: gui.handleMenuSelect, + OnClickSelectedItem: func() error { return gui.onMenuPress() }, Gui: gui, ResetMainViewOriginOnFocus: false, Kind: PERSISTENT_POPUP, diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index 20b008459..1eb6cffa7 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -42,7 +42,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error }, }...) - if gui.currentContext() == gui.Contexts.BranchCommits.Context { + if gui.currentContext().GetKey() == gui.Contexts.BranchCommits.Context.GetKey() { selectedCommit := gui.getSelectedLocalCommit() if selectedCommit != nil && gui.GitCommand.PatchManager.To != selectedCommit.Sha { // adding this option to index 1 @@ -84,7 +84,7 @@ func (gui *Gui) validateNormalWorkingTreeState() (bool, error) { } func (gui *Gui) returnFocusFromLineByLinePanelIfNecessary() error { - if gui.State.MainContext == "patchBuilding" { + if gui.State.MainContext == MAIN_PATCH_BUILDING_CONTEXT_KEY { return gui.handleEscapePatchBuildingPanel() } return nil diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go index 46c45fd3a..1c2762faf 100644 --- a/pkg/gui/sub_commits_panel.go +++ b/pkg/gui/sub_commits_panel.go @@ -107,7 +107,5 @@ func (gui *Gui) handleSwitchToSubCommits() error { return nil } - gui.Log.Warn(currentContext.GetKey()) - return gui.switchToSubCommitsContext(currentContext.GetSelectedItemId()) } diff --git a/pkg/gui/window.go b/pkg/gui/window.go index 8931ff07b..c3fffc637 100644 --- a/pkg/gui/window.go +++ b/pkg/gui/window.go @@ -4,7 +4,7 @@ package gui // A view is a box that renders content, and within a window only one view will // appear at a time. When a view appears within a window, it occupies the whole // space. Right now most windows are 1:1 with views, except for commitFiles which -// is a view belonging to the 'commits' window, alongside the 'commits' view. +// is a view that moves between windows func (gui *Gui) getViewNameForWindow(window string) string { viewName, ok := gui.State.WindowViewNameMap[window] -- cgit v1.2.3