Index: trunk/src_plugins/lib_hid_common/toolbar.c =================================================================== --- trunk/src_plugins/lib_hid_common/toolbar.c (revision 29647) +++ trunk/src_plugins/lib_hid_common/toolbar.c (revision 29648) @@ -37,6 +37,7 @@ #include #include #include +#include #include "toolbar.h" @@ -204,3 +205,42 @@ { toolbar_pcb2dlg(); } + + + +static const char *toolbar_cookie = "lib_hid_pcbui/toolbar"; + +static conf_hid_id_t install_events(const char *cookie, const char *paths[], conf_hid_callbacks_t cb[], void (*update_cb)(conf_native_t*,int)) +{ + const char **rp; + conf_native_t *nat; + int n; + conf_hid_id_t conf_id; + + conf_id = pcb_conf_hid_reg(cookie, NULL); + for(rp = paths, n = 0; *rp != NULL; rp++, n++) { + memset(&cb[n], 0, sizeof(cb[0])); + cb[n].val_change_post = update_cb; + nat = pcb_conf_get_field(*rp); + if (nat != NULL) + pcb_conf_hid_set_cb(nat, conf_id, &cb[n]); + } + + return conf_id; +} + +void rnd_toolbar_uninit(void) +{ + pcb_event_unbind_allcookie(toolbar_cookie); + pcb_conf_hid_unreg(toolbar_cookie); +} + +void rnd_toolbar_init(void) +{ + const char *tpaths[] = {"editor/mode", NULL}; + static conf_hid_callbacks_t tcb[sizeof(tpaths)/sizeof(tpaths[0])]; + + pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_toolbar_gui_init_ev, NULL, toolbar_cookie); + pcb_event_bind(PCB_EVENT_TOOL_REG, pcb_toolbar_reg_ev, NULL, toolbar_cookie); + install_events(toolbar_cookie, tpaths, tcb, pcb_toolbar_update_conf); +} Index: trunk/src_plugins/lib_hid_common/toolbar.h =================================================================== --- trunk/src_plugins/lib_hid_common/toolbar.h (revision 29647) +++ trunk/src_plugins/lib_hid_common/toolbar.h (revision 29648) @@ -1,9 +1,14 @@ #include #include -/* The caller needs to make sure these are bound */ +/* Automatic initialization (event and conf change bindings) */ +void rnd_toolbar_init(void); +void rnd_toolbar_uninit(void); + +/* Alternatively, the caller can bind these */ void pcb_toolbar_gui_init_ev(pcb_hidlib_t *hidlib, void *user_data, int argc, pcb_event_arg_t argv[]); void pcb_toolbar_reg_ev(pcb_hidlib_t *hidlib, void *user_data, int argc, pcb_event_arg_t argv[]); void pcb_toolbar_update_conf(conf_native_t *cfg, int arr_idx); + Index: trunk/src_plugins/lib_hid_pcbui/lib_hid_pcbui.c =================================================================== --- trunk/src_plugins/lib_hid_pcbui/lib_hid_pcbui.c (revision 29647) +++ trunk/src_plugins/lib_hid_pcbui/lib_hid_pcbui.c (revision 29648) @@ -47,7 +47,6 @@ static const char *layer_cookie = "lib_hid_pcbui/layer"; static const char *rst_cookie = "lib_hid_pcbui/route_style"; static const char *act_cookie = "lib_hid_pcbui/actions"; -static const char *toolbar_cookie = "lib_hid_pcbui/toolbar"; static const char *status_cookie = "lib_hid_pcbui/status"; static const char *status_rd_cookie = "lib_hid_pcbui/status/readouts"; static const char *rendering_cookie = "lib_hid_pcbui/rendering"; @@ -85,7 +84,6 @@ pcb_remove_actions_by_cookie(act_cookie); pcb_event_unbind_allcookie(layer_cookie); pcb_event_unbind_allcookie(rst_cookie); - pcb_event_unbind_allcookie(toolbar_cookie); pcb_event_unbind_allcookie(status_cookie); pcb_event_unbind_allcookie(rendering_cookie); pcb_event_unbind_allcookie(infobar_cookie); @@ -92,10 +90,10 @@ pcb_event_unbind_allcookie(title_cookie); pcb_event_unbind_allcookie(layersel_cookie); pcb_conf_hid_unreg(rst_cookie); - pcb_conf_hid_unreg(toolbar_cookie); pcb_conf_hid_unreg(status_cookie); pcb_conf_hid_unreg(status_rd_cookie); pcb_conf_hid_unreg(infobar_cookie); + rnd_toolbar_uninit(); } static conf_hid_id_t install_events(const char *cookie, const char *paths[], conf_hid_callbacks_t cb[], void (*update_cb)(conf_native_t*,int)) @@ -121,12 +119,10 @@ { TODO("padstack: remove some paths when route style has proto") const char *rpaths[] = {"design/line_thickness", "design/via_thickness", "design/via_drilling_hole", "design/clearance", NULL}; - const char *tpaths[] = {"editor/mode", NULL}; const char *stpaths[] = { "editor/show_solder_side", "design/line_thickness", "editor/all_direction_lines", "editor/line_refraction", "editor/rubber_band_mode", "design/via_thickness", "design/via_drilling_hole", "design/clearance", "design/text_scale", "design/text_thickness", "editor/buffer_number", "editor/grid_unit", "editor/grid", "appearance/compact", NULL }; const char *rdpaths[] = { "editor/grid_unit", "appearance/compact", NULL }; const char *ibpaths[] = { "rc/file_changed_interval", NULL }; static conf_hid_callbacks_t rcb[sizeof(rpaths)/sizeof(rpaths[0])]; - static conf_hid_callbacks_t tcb[sizeof(tpaths)/sizeof(tpaths[0])]; static conf_hid_callbacks_t stcb[sizeof(stpaths)/sizeof(stpaths[0])]; static conf_hid_callbacks_t rdcb[sizeof(rdpaths)/sizeof(rdpaths[0])]; static conf_hid_callbacks_t ibcb[sizeof(rdpaths)/sizeof(ibpaths[0])]; @@ -146,10 +142,8 @@ pcb_event_bind(PCB_EVENT_BOARD_CHANGED, pcb_rst_update_ev, NULL, rst_cookie); pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_layersel_gui_init_ev, NULL, layersel_cookie); pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_rst_gui_init_ev, NULL, rst_cookie); - pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_toolbar_gui_init_ev, NULL, toolbar_cookie); pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_status_gui_init_ev, NULL, status_cookie); pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_rendering_gui_init_ev, NULL, rendering_cookie); - pcb_event_bind(PCB_EVENT_TOOL_REG, pcb_toolbar_reg_ev, NULL, toolbar_cookie); pcb_event_bind(PCB_EVENT_USER_INPUT_KEY, pcb_status_st_update_ev, NULL, status_cookie); pcb_event_bind(PCB_EVENT_CROSSHAIR_MOVE, pcb_status_rd_update_ev, NULL, status_cookie); pcb_event_bind(PCB_EVENT_BOARD_CHANGED, pcb_infobar_brdchg_ev, NULL, infobar_cookie); @@ -160,10 +154,11 @@ pcb_event_bind(PCB_EVENT_BOARD_META_CHANGED, pcb_title_meta_changed_ev, NULL, title_cookie); install_events(rst_cookie, rpaths, rcb, pcb_rst_update_conf); - install_events(toolbar_cookie, tpaths, tcb, pcb_toolbar_update_conf); install_events(status_cookie, stpaths, stcb, pcb_status_st_update_conf); install_events(status_rd_cookie, rdpaths, rdcb, pcb_status_rd_update_conf); install_events(infobar_cookie, ibpaths, ibcb, pcb_infobar_update_conf); + rnd_toolbar_init(); + return 0; }