Skip to content

Commit

Permalink
Provide a general way to open a second drop-dopwn menu
Browse files Browse the repository at this point in the history
This continues the work I did on making menus more flexible. This opens
up the possibility of making context-aware menus with two levels of
options.
  • Loading branch information
gcla committed Feb 26, 2021
1 parent 4cf8025 commit 43c9300
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 64 deletions.
8 changes: 4 additions & 4 deletions ui/psmlcols.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func buildNamesMenu(app gowid.IApp) {
colNamesMenu = menu.New("psmlcols", colNamesMenuListBoxHolder, gowid.RenderWithUnits{U: wid}, menu.Options{
Modal: true,
CloseKeysProvided: true,
OpenCloser: menu.OpenerFunc(openTermsharkMenu),
OpenCloser: &multiMenu1Opener,
CloseKeys: []gowid.IKey{
gowid.MakeKeyExt(tcell.KeyEscape),
gowid.MakeKeyExt(tcell.KeyCtrlC),
Expand All @@ -93,7 +93,7 @@ func buildFieldsMenu(app gowid.IApp) {
colFieldsMenu = menu.New("psmlfieldscols", colFieldsMenuListBoxHolder, gowid.RenderWithUnits{U: wid}, menu.Options{
Modal: true,
CloseKeysProvided: true,
OpenCloser: menu.OpenerFunc(openTermsharkMenu),
OpenCloser: &multiMenu1Opener,
CloseKeys: []gowid.IKey{
gowid.MakeKeyExt(tcell.KeyEscape),
gowid.MakeKeyExt(tcell.KeyCtrlC),
Expand All @@ -119,7 +119,7 @@ func rebuildPsmlNamesListBox(p *psmlColumnsModel, app gowid.IApp) (int, int) {
menuutil.SimpleMenuItem{
Txt: spec.Long,
CB: func(app gowid.IApp, w gowid.IWidget) {
openTermsharkMenu(false, colNamesMenu, nil, app)
multiMenu1Opener.CloseMenu(colNamesMenu, app)
p.UpdateFromField(specCopy.Field, colsCurrentModelRow, app)
},
},
Expand Down Expand Up @@ -149,7 +149,7 @@ func rebuildPsmlFieldListBox(app gowid.IApp) (int, int) {
menuutil.SimpleMenuItem{
Txt: cname,
CB: func(app gowid.IApp, w gowid.IWidget) {
openTermsharkMenu(false, colFieldsMenu, nil, app)
multiMenu1Opener.CloseMenu(colFieldsMenu, app)
p.UpdateFromField(cnameCopy, colsCurrentModelRow, app)
},
},
Expand Down
7 changes: 3 additions & 4 deletions ui/psmlcolsmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (sp *specToWidgets) widgets() psmlDialogWidgets {
}),
customFilter: filter.New("psmlfilter", filter.Options{
Completer: savedCompleter{def: termshark.NewFields()},
MenuOpener: menu.OpenerFunc(openTermsharkMenu),
MenuOpener: &multiMenu1Opener,
Position: filter.Below,
}),
visible: checkbox.New(!sp.Hidden),
Expand Down Expand Up @@ -261,7 +261,6 @@ func (p *psmlColumnsModel) ReadFromWireshark(app gowid.IApp) error {

// Called when user chooses from a menu - so will only have PsmlField Token name
func (p *psmlColumnsModel) UpdateFromField(field string, idx int, app gowid.IApp) {

if p.spec[idx].Field.Token == "%Cus" && field != "%Cus" {
err := p.widgets[idx].customFilter.Close()
if err != nil {
Expand Down Expand Up @@ -347,7 +346,7 @@ func (p *psmlColumnsModel) CellWidgets(row table.RowId) []gowid.IWidget {
colsCurrentModelRow = rowi
colFieldsMenu.SetWidth(units(wid), app)
colFieldsMenu.SetHeight(units(hei), app)
openTermsharkMenu(true, colFieldsMenu, colsMenuFieldsSite, app)
multiMenu1Opener.OpenMenu(colFieldsMenu, colsMenuFieldsSite, app)
}))

// "^"
Expand Down Expand Up @@ -427,7 +426,7 @@ func (p *psmlColumnsModel) CellWidgets(row table.RowId) []gowid.IWidget {
colsCurrentModelRow = rowi
colNamesMenu.SetWidth(units(wid), app)
colNamesMenu.SetHeight(units(hei), app)
openTermsharkMenu(true, colNamesMenu, colsMenuSite, app)
multiMenu1Opener.OpenMenu(colNamesMenu, colsMenuSite, app)
}))

//
Expand Down
5 changes: 2 additions & 3 deletions ui/streamui.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func makeStreamWidget(previousFilter string, filter string, cap string, proto st
return streamwidget.New(filter, cap, proto,
conversationMenu, conversationMenuHolder, &keyState,
streamwidget.Options{
MenuOpener: menu.OpenerFunc(openTermsharkMenu),
MenuOpener: &multiMenu1Opener,
DefaultDisplay: func() streamwidget.DisplayFormat {
view := streamwidget.Hex
choice := termshark.ConfString("main.stream-view", "hex")
Expand All @@ -463,7 +463,6 @@ func makeStreamWidget(previousFilter string, filter string, cap string, proto st
}

FilterWidget.SetValue(newFilter, app)
//Loader.NewFilter(newFilter, MakePacketViewUpdater(), app)
RequestNewFilter(newFilter, app)

},
Expand Down Expand Up @@ -497,7 +496,7 @@ func closeStreamUi(app gowid.IApp, refocus bool) {
//======================================================================

func buildStreamUi() {
conversationMenuHolder, conversationMenu = streamwidget.MakeConvMenu(menu.OpenerFunc(openTermsharkMenu))
conversationMenuHolder, conversationMenu = streamwidget.MakeConvMenu(&multiMenu1Opener)

streamViewNoKeysHolder = holder.New(null.New())

Expand Down
Loading

0 comments on commit 43c9300

Please sign in to comment.