Index: trunk/src/crosshair.c =================================================================== --- trunk/src/crosshair.c (revision 29325) +++ trunk/src/crosshair.c (revision 29326) @@ -1055,6 +1055,17 @@ PCB->hidlib.grid = save_grid; } +static void pcb_crosshair_tool_logics(pcb_hidlib_t *hidlib, void *user_data, int argc, pcb_event_arg_t argv[]) +{ + int *ok = argv[1].d.p; + int id = argv[2].d.i; + pcb_board_t *pcb = (pcb_board_t *)hidlib; + if (pcb->RatDraw && !pcb_tool_get(id)->allow_when_drawing_ratlines) { + pcb_message(PCB_MSG_WARNING, "That tool can not be used on the rat layer!\n"); + *ok = 0; + } +} + /* allocate GC only when the GUI is already up and running */ static void pcb_crosshair_gui_init(pcb_hidlib_t *hidlib, void *user_data, int argc, pcb_event_arg_t argv[]) { @@ -1066,7 +1077,6 @@ pcb_hid_set_line_width(pcb_crosshair.GC, 1); } - /* --------------------------------------------------------------------------- * initializes crosshair stuff * clears the struct @@ -1087,6 +1097,7 @@ pcb_crosshair.tool_arc = pcb_crosshair.tool_poly = pcb_crosshair.tool_poly_hole = -1; pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_crosshair_gui_init, NULL, crosshair_cookie); + pcb_event_bind(PCB_EVENT_TOOL_SELECT_PRE, pcb_crosshair_tool_logics, NULL, crosshair_cookie); } Index: trunk/src/librnd/core/event.c =================================================================== --- trunk/src/librnd/core/event.c (revision 29325) +++ trunk/src/librnd/core/event.c (revision 29326) @@ -41,6 +41,7 @@ "pcbev_load_pre", "pcbev_load_post", "pcbeb_new_tool", + "pcbeb_tool_select_pre", "pcbev_board_changed", "pcbev_board_meta_changed", "pcbev_board_fn_changed", Index: trunk/src/librnd/core/event.h =================================================================== --- trunk/src/librnd/core/event.h (revision 29325) +++ trunk/src/librnd/core/event.h (revision 29326) @@ -40,6 +40,7 @@ PCB_EVENT_LOAD_POST, /* called after loading a new design, whether it was successful or not */ PCB_EVENT_TOOL_REG, /* called after a new tool has been registered; arg is (pcb_tool_t *) of the new tool */ + PCB_EVENT_TOOL_SELECT_PRE, /* called before a tool is selected; arg is (int *ok, int toolid); if ok is non-zero if the selection is accepted */ PCB_EVENT_BOARD_CHANGED, /* called after the board being edited got _replaced_ (used to be the PCBChanged action) */ PCB_EVENT_BOARD_META_CHANGED, /* called if the metadata of the board has changed */ Index: trunk/src/tool.c =================================================================== --- trunk/src/tool.c (revision 29325) +++ trunk/src/tool.c (revision 29326) @@ -143,6 +143,7 @@ pcb_board_t *pcb = (pcb_board_t *)hidlib; char id_s[32]; static pcb_bool recursing = pcb_false; + int ok = 1; if ((id < 0) || (id > vtp0_len(&pcb_tools))) return -1; @@ -153,13 +154,14 @@ */ if (recursing) return -1; + + /* check if the UI logic allows picking that tool */ + pcb_event(hidlib, PCB_EVENT_TOOL_SELECT_PRE, "pi", &ok, id); + if (ok == 0) + id = pcbhl_conf.editor.mode; + recursing = pcb_true; - - if (pcb->RatDraw && !pcb_tool_get(id)->allow_when_drawing_ratlines) { - pcb_message(PCB_MSG_WARNING, "That mode is NOT allowed when drawing ratlines!\n"); - id = PCB_MODE_ARROW; - } - + pcb_tool_prev_id = pcbhl_conf.editor.mode; pcb_tool_next_id = id; uninit_current_tool();