Index: trunk/src/tool.c =================================================================== --- trunk/src/tool.c (revision 12109) +++ trunk/src/tool.c (revision 12110) @@ -26,6 +26,8 @@ #include "error.h" +#warning tool TODO: remove this when pcb_crosshair_set_mode() got moved here +#include "crosshair.h" static void default_tool_reg(void); static void default_tool_unreg(void); @@ -78,8 +80,41 @@ return PCB_TOOLID_INVALID; } +int pcb_tool_select_by_name(const char *name) +{ + pcb_toolid_t id = pcb_tool_lookup(name); + if (id == PCB_TOOLID_INVALID) + return -1; + pcb_crosshair_set_mode(id); + return 0; +} +int pcb_tool_select_by_id(pcb_toolid_t id) +{ + if ((id < 0) || (id > vtp0_len(&pcb_tools))) + return -1; + pcb_crosshair_set_mode(id); + return 0; +} +int pcb_tool_select_highest(void) +{ + pcb_toolid_t n, bestn = PCB_TOOLID_INVALID; + unsigned int bestp = -1; + for(n = 0; n < vtp0_len(&pcb_tools) && (bestp > 0); n++) { + const pcb_tool_t *tool = (const pcb_tool_t *)pcb_tools.array[n]; + if (tool->priority < bestp) { + bestp = tool->priority; + bestn = n; + } + } + if (bestn == PCB_TOOLID_INVALID) + return -1; + pcb_crosshair_set_mode(bestn); + return 0; +} + + #warning tool TODO: move this out to a tool plugin #include "tool_arc.h" Index: trunk/src/tool.h =================================================================== --- trunk/src/tool.h (revision 12109) +++ trunk/src/tool.h (revision 12110) @@ -31,7 +31,7 @@ typedef struct pcb_tool_s { const char *name; /* textual name of the tool */ const char *cookie; /* plugin cookie _pointer_ of the registrar (comparision is pointer based, not strcmp) */ - int priority; /* lower values are higher priorities; escaping mode will try to select the highest prio tool */ + unsigned int priority; /* lower values are higher priorities; escaping mode will try to select the highest prio tool */ /* tool implementation */ void (*notify_mode)(void);