From a970c1ae2ef89ae691fc2104db0c2c4e512f58f3 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sat, 14 May 2016 12:20:44 +0200 Subject: cfgfiles: Introduce an after_update callback This allows individual preferences to take action when their value is changed. Signed-off-by: Ben Gamari --- src/common/cfgfiles.c | 10 ++++++++++ src/common/cfgfiles.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c index 4bf2f470..910e0781 100644 --- a/src/common/cfgfiles.c +++ b/src/common/cfgfiles.c @@ -1046,6 +1046,11 @@ save_config (void) return 0; } } + + if (vars[i].after_update != NULL) + { + vars[i].after_update(); + } i++; } while (vars[i].name); @@ -1293,6 +1298,11 @@ cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[]) { set_showval (sess, &vars[i], tbuf); } + + if (vars[i].after_update != NULL) + { + vars[i].after_update(); + } break; } } diff --git a/src/common/cfgfiles.h b/src/common/cfgfiles.h index b421884a..b0d57519 100644 --- a/src/common/cfgfiles.h +++ b/src/common/cfgfiles.h @@ -71,6 +71,11 @@ struct prefs unsigned short offset; unsigned short len; unsigned short type; + /* + * an optional function which will be called after the preference value has + * been updated. + */ + void (*after_update)(void); }; #define TYPE_STR 0 -- cgit 1.4.1