summaryrefslogtreecommitdiffstats
path: root/pkg/gui/list_context.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-24 08:26:42 +1000
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2020-08-23 22:30:32 +0000
commitf172f20219096e6dac26f8f01e7a7fe1f3b5d3ef (patch)
tree46d197e8f2b25e3075ac89dd5c4245d25b300d63 /pkg/gui/list_context.go
parent0f7003d939a969920ffdb5f2d28fca2fd0eb7f65 (diff)
Return whether the context has a parent or not along with that parent
There has got to be a better way around this but if we're returning a Context from a function (Context is an interface, not a concrete type), even if we return nil, on the calling end it won't be equal to nil because an interface value is a tuple of the type and the value meaning it's never itself nil, unless both values in the tuple are nil. So we're explicitly returning whether or not the underlying concrete type is nil.
Diffstat (limited to 'pkg/gui/list_context.go')
-rw-r--r--pkg/gui/list_context.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go
index 5b64aa435..e437337d1 100644
--- a/pkg/gui/list_context.go
+++ b/pkg/gui/list_context.go
@@ -23,7 +23,9 @@ type ListContext struct {
ResetMainViewOriginOnFocus bool
Kind int
ParentContext Context
- WindowName string
+ // we can't know on the calling end whether a Context is actually a nil value without reflection, so we're storing this flag here to tell us. There has got to be a better way around this.
+ hasParent bool
+ WindowName string
}
type ListItem interface {
@@ -55,10 +57,11 @@ func (lc *ListContext) GetWindowName() string {
func (lc *ListContext) SetParentContext(c Context) {
lc.ParentContext = c
+ lc.hasParent = true
}
-func (lc *ListContext) GetParentContext() Context {
- return lc.ParentContext
+func (lc *ListContext) GetParentContext() (Context, bool) {
+ return lc.ParentContext, lc.hasParent
}
func (lc *ListContext) GetSelectedItemId() string {