summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-09-27 09:37:22 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-09-27 09:49:30 +1000
commita09bb5d4d83c9738969b337d82e14e4bbe34dd53 (patch)
tree2bf51c23618ef52d9b8e1f6b46ee7c389623ff03 /pkg/gui/context.go
parent7cd17d3a73e31c6f7ab7aac69b77fbd1775d4ee5 (diff)
better validation messages
Diffstat (limited to 'pkg/gui/context.go')
-rw-r--r--pkg/gui/context.go41
1 files changed, 37 insertions, 4 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index c84e604b8..c48626a44 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -36,6 +36,29 @@ const (
COMMIT_MESSAGE_CONTEXT_KEY = "commitMessage"
)
+var allContextKeys = []string{
+ STATUS_CONTEXT_KEY,
+ FILES_CONTEXT_KEY,
+ LOCAL_BRANCHES_CONTEXT_KEY,
+ REMOTES_CONTEXT_KEY,
+ REMOTE_BRANCHES_CONTEXT_KEY,
+ TAGS_CONTEXT_KEY,
+ BRANCH_COMMITS_CONTEXT_KEY,
+ REFLOG_COMMITS_CONTEXT_KEY,
+ SUB_COMMITS_CONTEXT_KEY,
+ COMMIT_FILES_CONTEXT_KEY,
+ STASH_CONTEXT_KEY,
+ MAIN_NORMAL_CONTEXT_KEY,
+ MAIN_MERGING_CONTEXT_KEY,
+ MAIN_PATCH_BUILDING_CONTEXT_KEY,
+ MAIN_STAGING_CONTEXT_KEY,
+ MENU_CONTEXT_KEY,
+ CREDENTIALS_CONTEXT_KEY,
+ CONFIRMATION_CONTEXT_KEY,
+ SEARCH_CONTEXT_KEY,
+ COMMIT_MESSAGE_CONTEXT_KEY,
+}
+
type Context interface {
HandleFocus() error
HandleFocusLost() error
@@ -674,14 +697,24 @@ type tabContext struct {
contexts []Context
}
-func (gui *Gui) contextForContextKey(contextKey string) Context {
+func (gui *Gui) mustContextForContextKey(contextKey string) Context {
+ context, ok := gui.contextForContextKey(contextKey)
+
+ if !ok {
+ panic(fmt.Sprintf("context now found for key %s", contextKey))
+ }
+
+ return context
+}
+
+func (gui *Gui) contextForContextKey(contextKey string) (Context, bool) {
for _, context := range gui.allContexts() {
if context.GetKey() == contextKey {
- return context
+ return context, true
}
}
- panic(fmt.Sprintf("context now found for key %s", contextKey))
+ return nil, false
}
func (gui *Gui) rerenderView(viewName string) error {
@@ -691,7 +724,7 @@ func (gui *Gui) rerenderView(viewName string) error {
}
contextKey := v.Context
- context := gui.contextForContextKey(contextKey)
+ context := gui.mustContextForContextKey(contextKey)
return context.HandleRender()
}