mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Automatically set persistent on new Preferences keys.
This improves interoperability with old dashboards as it enables new Preferences keys to be added from an old dashboard and still be automatically saved. Change-Id: I51e988006f8fa4fd780fac34f47633a9727f31e0
This commit is contained in:
committed by
Brad Miller (WPI)
parent
f93bf82fa9
commit
87fc49c66d
@@ -11,6 +11,8 @@ import java.util.Vector;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
import edu.wpi.first.wpilibj.tables.TableKeyNotDefinedException;
|
||||
|
||||
/**
|
||||
@@ -48,6 +50,20 @@ public class Preferences {
|
||||
* The network table
|
||||
*/
|
||||
private NetworkTable table;
|
||||
/**
|
||||
* Listener to set all Preferences values to persistent (for backwards
|
||||
* compatibility with old dashboards).
|
||||
*/
|
||||
private final ITableListener listener = new ITableListener() {
|
||||
@Override
|
||||
public void valueChanged(ITable table, String key, Object value, boolean isNew) {
|
||||
// unused
|
||||
}
|
||||
@Override
|
||||
public void valueChangedEx(ITable table, String key, Object value, int flags) {
|
||||
table.setPersistent(key);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the preferences instance.
|
||||
@@ -66,6 +82,7 @@ public class Preferences {
|
||||
*/
|
||||
private Preferences() {
|
||||
table = NetworkTable.getTable(TABLE_NAME);
|
||||
table.addTableListenerEx(listener, ITable.NOTIFY_NEW | ITable.NOTIFY_IMMEDIATE);
|
||||
UsageReporting.report(tResourceType.kResourceType_Preferences, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user