diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 146ec2567f..26087b1026 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -430,7 +430,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) aEvent.Skip(); #endif - updateUI(); + updateUI( aEvent ); } @@ -443,11 +443,11 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent ) else aEvent.Skip(); - updateUI(); + updateUI( aEvent ); } -void TOOL_DISPATCHER::updateUI() +void TOOL_DISPATCHER::updateUI( wxEvent& aEvent ) { // TODO I don't feel it is the right place for updating UI, // but at the moment I cannot think of a better one.. @@ -456,6 +456,6 @@ void TOOL_DISPATCHER::updateUI() if( frame ) { frame->UpdateStatusBar(); - //frame->UpdateMsgPanel(); + frame->SyncMenusAndToolbars( aEvent ); } } diff --git a/include/draw_frame.h b/include/draw_frame.h index a6e48dbc9e..a4e6436b4a 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -897,11 +897,18 @@ public: virtual void* GetDisplayOptions() { return NULL; } /** - * Function GetGalDisplayOptions - * Returns a reference to the gal rendering options used by GAL for rendering. - */ + * Function GetGalDisplayOptions + * Returns a reference to the gal rendering options used by GAL for rendering. + */ KIGFX::GAL_DISPLAY_OPTIONS& GetGalDisplayOptions() { return *m_galDisplayOptions; } + /** + * Function SyncMenusAndToolbars + * Updates the toolbars and menus (mostly settings/check buttons/checkboxes) + * with the current controller state + */ + virtual void SyncMenusAndToolbars( wxEvent& aEvent ) {}; + DECLARE_EVENT_TABLE() }; diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index 44a3c31af6..df02563768 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -115,8 +115,8 @@ private: return mods; } - ///> Redraws the status bar and message panel. - void updateUI(); + ///> Redraws the status bar and message panel, synchronizes menus and toolbars. + void updateUI( wxEvent& aEvent ); ///> Stores all the informations regarding a mouse button state. struct BUTTON_STATE; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 80d25795ea..e9c28d5393 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -308,8 +308,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) PCB_EDIT_FRAME::OnUpdateSelectViaSize ) EVT_UPDATE_UI_RANGE( ID_PCB_HIGHLIGHT_BUTT, ID_PCB_MEASUREMENT_TOOL, PCB_EDIT_FRAME::OnUpdateVerticalToolbar ) - EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SHOW_ZONES, ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY, - PCB_EDIT_FRAME::OnUpdateZoneDisplayStyle ) EVT_UPDATE_UI_RANGE( ID_PCB_MUWAVE_START_CMD, ID_PCB_MUWAVE_END_CMD, PCB_EDIT_FRAME::OnUpdateMuWaveToolbar ) diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index b2f05f0a6f..6deb9a15b1 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -1730,6 +1730,8 @@ public: int GetIconScale() override; void SetIconScale( int aScale ) override; + void SyncMenusAndToolbars( wxEvent& aEvent ) override; + DECLARE_EVENT_TABLE() }; diff --git a/pcbnew/toolbars_update_user_interface.cpp b/pcbnew/toolbars_update_user_interface.cpp index 79002a20e0..8080a7e899 100644 --- a/pcbnew/toolbars_update_user_interface.cpp +++ b/pcbnew/toolbars_update_user_interface.cpp @@ -119,13 +119,7 @@ void PCB_EDIT_FRAME::OnUpdateScriptingConsoleState( wxUpdateUIEvent& aEvent ) void PCB_EDIT_FRAME::OnUpdateZoneDisplayStyle( wxUpdateUIEvent& aEvent ) { - int selected = aEvent.GetId() - ID_TB_OPTIONS_SHOW_ZONES; - auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions(); - if( aEvent.IsChecked() && ( displ_opts->m_DisplayZonesMode == selected ) ) - return; - - aEvent.Check( displ_opts->m_DisplayZonesMode == selected ); } @@ -231,3 +225,32 @@ void PCB_EDIT_FRAME::OnUpdateAutoPlaceModulesMode( wxUpdateUIEvent& aEvent ) { //Nothing to do. } + +void PCB_EDIT_FRAME::SyncMenusAndToolbars( wxEvent& aEvent ) +{ + auto displOpts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions(); + auto menuBar = GetMenuBar(); + + m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_ZONES, false ); + m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_ZONES_DISABLE, false ); + m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY, false ); + + + switch( displOpts->m_DisplayZonesMode ) + { + case 0: + menuBar->FindItem( ID_TB_OPTIONS_SHOW_ZONES )->Check( true ); + m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_ZONES, true ); + break; + + case 1: + menuBar->FindItem( ID_TB_OPTIONS_SHOW_ZONES_DISABLE )->Check( true ); + m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_ZONES_DISABLE, true ); + break; + + case 2: + menuBar->FindItem( ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY )->Check( true ); + m_optionsToolBar->ToggleTool( ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY, true ); + break; + } +}