For the toolbar, you can look at PCB_EDIT_FRAME::ReCreateOptToolbar() in tool_pcb_editor.cpp. You'll want to create an icon that can be set/unset when clicked. Also, don't forget that system options should be stored in the preferences (pcbnew_config.cpp)
Your revised patch works better.
For the toolbar, you can look at PCB_EDIT_ FRAME:: ReCreateOptTool bar() in tool_pcb_ editor. cpp. You'll want to create an icon that can be set/unset when clicked. Also, don't forget that system options should be stored in the preferences (pcbnew_config.cpp)