summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-27 14:14:43 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-03 12:54:13 +1000
commita9e2c8129f6e1cdfd58446d7ce5080fcabc2ea04 (patch)
tree272c6f737052d6e06f71c6e1e9ce355410238f1a /pkg/gui/context.go
parentfd861826bc11754caf4ee4651dbadf9544792d1f (diff)
Introduce filtered list view model
We're going to start supporting filtering of list views
Diffstat (limited to 'pkg/gui/context.go')
-rw-r--r--pkg/gui/context.go53
1 files changed, 50 insertions, 3 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index b55713f27..26cec4c23 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -200,9 +200,21 @@ func (self *ContextMgr) RemoveContexts(contextsToRemove []types.Context) error {
func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLostOpts) error {
view, _ := self.gui.c.GocuiGui().View(c.GetViewName())
- if view != nil && view.IsSearching() {
- if err := self.gui.onSearchEscape(); err != nil {
- return err
+ if opts.NewContextKey != context.SEARCH_CONTEXT_KEY {
+
+ if searchableContext, ok := c.(types.ISearchableContext); ok {
+ if view != nil && view.IsSearching() {
+ view.ClearSearch()
+ searchableContext.ClearSearchString()
+ self.gui.helpers.Search.Cancel()
+ }
+ }
+
+ if filterableContext, ok := c.(types.IFilterableContext); ok {
+ if filterableContext.GetFilter() != "" {
+ filterableContext.ClearFilter()
+ self.gui.helpers.Search.Cancel()
+ }
}
}
@@ -234,6 +246,17 @@ func (self *ContextMgr) ActivateContext(c types.Context, opts types.OnFocusOpts)
return err
}
+ if searchableContext, ok := c.(types.ISearchableContext); ok {
+ if searchableContext.GetSearchString() != "" {
+ self.gui.helpers.Search.DisplaySearchPrompt(searchableContext)
+ }
+ }
+ if filterableContext, ok := c.(types.IFilterableContext); ok {
+ if filterableContext.GetFilter() != "" {
+ self.gui.helpers.Search.DisplayFilterPrompt(filterableContext)
+ }
+ }
+
desiredTitle := c.Title()
if desiredTitle != "" {
v.Title = desiredTitle
@@ -326,6 +349,30 @@ func (self *ContextMgr) IsCurrent(c types.Context) bool {
return self.Current().GetKey() == c.GetKey()
}
+func (self *ContextMgr) AllFilterable() []types.IFilterableContext {
+ var result []types.IFilterableContext
+
+ for _, context := range self.allContexts.Flatten() {
+ if ctx, ok := context.(types.IFilterableContext); ok {
+ result = append(result, ctx)
+ }
+ }
+
+ return result
+}
+
+func (self *ContextMgr) AllSearchable() []types.ISearchableContext {
+ var result []types.ISearchableContext
+
+ for _, context := range self.allContexts.Flatten() {
+ if ctx, ok := context.(types.ISearchableContext); ok {
+ result = append(result, ctx)
+ }
+ }
+
+ return result
+}
+
// all list contexts
func (self *ContextMgr) AllList() []types.IListContext {
var listContexts []types.IListContext