allwpilib icon indicating copy to clipboard operation
allwpilib copied to clipboard

SendableChooser change listener no longer (easily) exists

Open pjreiniger opened this issue 7 years ago • 5 comments

Last year I was able to do something along the lines of

SendableChooser chooser = new SendableChooser()
// ... fill in options ....
SmartDashboard.putData("Chooser Name", chooser );

ITableListener changeListener= ....
chooser.getTable().addTableListener(changeListener);

Looks like the functionality was removed in #622. I can certainly modify our side to look more like this

NetworkTableInstance.getDefault().getTable("SmartDashboard").getSubTable("ChooserName").addEntryListener("selected", changeListener, 0xFF);

But that seems clunky, especially with two magic strings in there ("SmartDashboard" is not a constant, "selected" is a private constant)

I'm not sure how large this use case is, but the convenience of having chooser.addSelectionChangedListener(listener, flags) might be nice to have. I think I understand the path to add this and don't mind implementing it, but I wanted to double check that this doesn't exist somewhere or was removed on purpose

pjreiniger avatar Dec 19 '17 03:12 pjreiniger

That definitely seems like an oversight. I'm fine with that as a PR, and think it would be a valuable addition. Not sure it would get merged before the season but will definitely look at it

ThadHouse avatar Dec 19 '17 04:12 ThadHouse

Note the addSelectionChangedListener() approach will necessitate documenting an ordering with SmartDashboard.putData(), as m_tableSelected isn't set until initSendable() is called by putData().

PeterJohnson avatar Dec 19 '17 04:12 PeterJohnson

Unless... the listener is just a Runnable and we set up a thunk callback in initSendable(). Then you could make it work for either order.

PeterJohnson avatar Dec 19 '17 04:12 PeterJohnson

Also, not sure why you need flags. Don't you only care about valueChanged?

PeterJohnson avatar Dec 19 '17 04:12 PeterJohnson

I suggest an onChange(Consumer<T> consumer) method to expose this

Bankst avatar Mar 21 '22 15:03 Bankst

Fixed by #5458.

PeterJohnson avatar Jul 18 '23 23:07 PeterJohnson