File: filterconvs.go

package info (click to toggle)
termshark 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,800 kB
  • sloc: sh: 98; makefile: 9
file content (134 lines) | stat: -rw-r--r-- 3,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2019-2021 Graham Clark. All rights reserved.  Use of this source
// code is governed by the MIT license that can be found in the LICENSE
// file.

// Package ui contains user-interface functions and helpers for termshark.
package ui

import (
	"github.com/gcla/gowid"
	"github.com/gcla/gowid/widgets/columns"
	"github.com/gcla/gowid/widgets/holder"
	"github.com/gcla/gowid/widgets/menu"
	"github.com/gcla/termshark/v2/ui/menuutil"
	"github.com/gdamore/tcell"
)

//======================================================================

var filterConvsMenu1 *menu.Widget
var filterConvsMenu1Site *menu.SiteWidget
var filterConvsMenu2 *menu.Widget

type indirect struct {
	*holder.Widget
}

func buildFilterConvsMenu() {
	filterConvsMenu1Holder := &indirect{}
	filterConvsMenu2Holder := &indirect{}

	filterConvsMenu1 = menu.New("filterconvs1", filterConvsMenu1Holder, fixed, menu.Options{
		Modal:             true,
		CloseKeysProvided: true,
		CloseKeys: []gowid.IKey{
			gowid.MakeKey('q'),
			gowid.MakeKeyExt(tcell.KeyLeft),
			gowid.MakeKeyExt(tcell.KeyEscape),
			gowid.MakeKeyExt(tcell.KeyCtrlC),
		},
	})

	filterConvsMenu2 = menu.New("filterconvs2", filterConvsMenu2Holder, fixed, menu.Options{
		Modal:             true,
		CloseKeysProvided: true,
		CloseKeys: []gowid.IKey{
			gowid.MakeKey('q'),
			gowid.MakeKeyExt(tcell.KeyLeft),
			gowid.MakeKeyExt(tcell.KeyEscape),
			gowid.MakeKeyExt(tcell.KeyCtrlC),
		},
	})

	w := makeFilterConvsMenuWidget()
	filterConvsMenu1Site = menu.NewSite(menu.SiteOptions{
		XOffset: -3,
		YOffset: -3,
	})
	cols := columns.New([]gowid.IContainerWidget{
		&gowid.ContainerWidget{IWidget: w, D: fixed},
		&gowid.ContainerWidget{IWidget: filterConvsMenu1Site, D: fixed},
	})
	filterConvsMenu1Holder.Widget = holder.New(cols)

	w2 := makeFilterConvs2MenuWidget()
	filterConvsMenu2Holder.Widget = holder.New(w2)
}

func makeFilterConvsMenuWidget() gowid.IWidget {
	menuItems := make([]menuutil.SimpleMenuItem, 0)

	for i, s := range []string{
		"Selected",
		"Not Selected",
		"...and Selected",
		"...or Selected",
		"...and not Selected",
		"...or not Selected",
	} {
		i2 := i
		menuItems = append(menuItems,
			menuutil.SimpleMenuItem{
				Txt: s,
				Key: gowid.MakeKey('1' + rune(i)),
				CB: func(app gowid.IApp, w2 gowid.IWidget) {
					convsUi.filterSelectedIndex = FilterCombinator(i2)
					filterConvsMenu2.Open(filterConvsMenu1Site, app)
				},
			},
		)
	}

	convListBox := menuutil.MakeMenuWithHotKeys(menuItems)

	return convListBox
}

func makeFilterConvs2MenuWidget() gowid.IWidget {
	menuItems := make([]menuutil.SimpleMenuItem, 0)

	for i, s := range []string{
		"A ↔ B",
		"A → B",
		"B → A",
		"A ↔ Any",
		"A → Any",
		"Any → A",
		"Any ↔ B",
		"Any → B",
		"B → Any",
	} {
		i2 := i
		menuItems = append(menuItems,
			menuutil.SimpleMenuItem{
				Txt: s,
				Key: gowid.MakeKey('1' + rune(i)),
				CB: func(app gowid.IApp, w2 gowid.IWidget) {
					filterConvsMenu1.Close(app)
					filterConvsMenu2.Close(app)
					convsUi.doFilterMenuOp(FilterMask(i2), app)
				},
			},
		)
	}

	convListBox := menuutil.MakeMenuWithHotKeys(menuItems)

	return convListBox
}

//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: