summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-22 15:56:30 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commit5874529f4310c6b4b0abdfcef714ff6f6cc8afd5 (patch)
tree3a225e081659c52cd548cace154f2f2c64f2894b /pkg/gui/context.go
parente290710f6741c046ee7e52e622af813e8955639b (diff)
deal with the fact that a nil wrapped in an interface is not equal to nil
Diffstat (limited to 'pkg/gui/context.go')
-rw-r--r--pkg/gui/context.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index e3a90871b..77527f466 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -45,8 +45,6 @@ type Context interface {
GetWindowName() string
SetWindowName(string)
GetKey() string
- GetSelectedItemId() string
- GetSelectedItem() ListItem
SetParentContext(Context)
GetParentContext() Context
}
@@ -64,10 +62,6 @@ func (c BasicContext) SetWindowName(windowName string) {
panic("can't set window name on basic context")
}
-func (c BasicContext) GetSelectedItem() ListItem {
- return nil
-}
-
func (c BasicContext) GetWindowName() string {
// TODO: fix this up
return c.GetViewName()
@@ -81,11 +75,6 @@ func (c BasicContext) GetParentContext() Context {
panic("can't get parent context on basic context")
}
-// TODO: think about whether we need this on the Context interface or if it should just be on the ListContext struct
-func (c BasicContext) GetSelectedItemId() string {
- return ""
-}
-
func (c BasicContext) HandleRender() error {
if c.OnRender != nil {
return c.OnRender()
@@ -534,7 +523,12 @@ func (gui *Gui) currentSideContext() *ListContext {
context := stack[len(stack)-1-i]
if context.GetKind() == SIDE_CONTEXT {
- return context.(*ListContext)
+ // not all side contexts are list contexts (e.g. the status panel)
+ listContext, ok := context.(*ListContext)
+ if !ok {
+ return nil
+ }
+ return listContext
}
}
@@ -694,11 +688,17 @@ func (gui *Gui) getCurrentSideView() *gocui.View {
return view
}
-func (gui *Gui) getSideContextSelectedItem() ListItem {
+func (gui *Gui) getSideContextSelectedItemId() string {
currentSideContext := gui.currentSideContext()
if currentSideContext == nil {
- return nil
+ return ""
+ }
+
+ item, ok := currentSideContext.GetSelectedItem()
+
+ if ok {
+ return item.ID()
}
- return currentSideContext.GetSelectedItem()
+ return ""
}