diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index bcdb62b9da..77307ee43d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -171,6 +171,7 @@ set( KICOMMON_SRCS # This is basically a settings object, but for the toolbar tool/ui/toolbar_configuration.cpp + tool/ui/toolbar_context_menu_registry.cpp dialogs/dialog_rc_job.cpp dialogs/dialog_rc_job_base.cpp diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index ef7e2155b0..94fadb5a70 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -332,6 +333,17 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) group->SetDefaultAction( *defaultTool ); AddGroup( std::move( group ) ); + + // Look up and attach context menu if one is registered for this group + auto menuFactory = TOOLBAR_CONTEXT_MENU_REGISTRY::GetGroupMenuFactory( groupName ); + + if( menuFactory && m_toolManager ) + { + // Register the menu for each action in the group + for( const TOOL_ACTION* grpAction : tools ) + AddToolContextMenu( *grpAction, menuFactory( m_toolManager ) ); + } + break; } @@ -363,6 +375,13 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) } Add( *action ); + + // Look up and attach context menu if one is registered for this action + auto factory = TOOLBAR_CONTEXT_MENU_REGISTRY::GetMenuFactory( item.m_ActionName ); + + if( factory && m_toolManager ) + AddToolContextMenu( *action, factory( m_toolManager ) ); + break; } } diff --git a/common/tool/ui/toolbar_configuration.cpp b/common/tool/ui/toolbar_configuration.cpp index c3221a5d2a..b497621c7e 100644 --- a/common/tool/ui/toolbar_configuration.cpp +++ b/common/tool/ui/toolbar_configuration.cpp @@ -27,6 +27,7 @@ #include #include +#include ///! Update the schema version whenever a migration is required const int toolbarSchemaVersion = 1; @@ -213,4 +214,57 @@ std::optional TOOLBAR_SETTINGS::GetStoredToolbarConfig( T // Return a nullopt if no toolbar is configured return std::nullopt; -} \ No newline at end of file +} + + +TOOLBAR_CONFIGURATION& TOOLBAR_ITEM_REF::WithContextMenu( + TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY aFactory ) +{ + // Register the factory globally so JSON configs get the same menu + TOOLBAR_CONTEXT_MENU_REGISTRY::RegisterMenuFactory( m_item.m_ActionName, std::move( aFactory ) ); + return m_parent; +} + + +// Forwarding methods for TOOLBAR_ITEM_REF to enable chaining + +TOOLBAR_ITEM_REF TOOLBAR_ITEM_REF::AppendAction( const std::string& aActionName ) +{ + return m_parent.AppendAction( aActionName ); +} + + +TOOLBAR_ITEM_REF TOOLBAR_ITEM_REF::AppendAction( const TOOL_ACTION& aAction ) +{ + return m_parent.AppendAction( aAction ); +} + + +TOOLBAR_CONFIGURATION& TOOLBAR_ITEM_REF::AppendSeparator() +{ + return m_parent.AppendSeparator(); +} + + +TOOLBAR_CONFIGURATION& TOOLBAR_ITEM_REF::AppendSpacer( int aSize ) +{ + return m_parent.AppendSpacer( aSize ); +} + + +TOOLBAR_CONFIGURATION& TOOLBAR_ITEM_REF::AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup ) +{ + return m_parent.AppendGroup( aGroup ); +} + + +TOOLBAR_CONFIGURATION& TOOLBAR_ITEM_REF::AppendControl( const std::string& aControlName ) +{ + return m_parent.AppendControl( aControlName ); +} + + +TOOLBAR_CONFIGURATION& TOOLBAR_ITEM_REF::AppendControl( const ACTION_TOOLBAR_CONTROL& aControl ) +{ + return m_parent.AppendControl( aControl ); +} diff --git a/common/tool/ui/toolbar_context_menu_registry.cpp b/common/tool/ui/toolbar_context_menu_registry.cpp new file mode 100644 index 0000000000..50a22f1724 --- /dev/null +++ b/common/tool/ui/toolbar_context_menu_registry.cpp @@ -0,0 +1,80 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + + +std::map& +TOOLBAR_CONTEXT_MENU_REGISTRY::getActionMenus() +{ + static std::map s_actionMenus; + return s_actionMenus; +} + + +std::map& +TOOLBAR_CONTEXT_MENU_REGISTRY::getGroupMenus() +{ + static std::map s_groupMenus; + return s_groupMenus; +} + + +void TOOLBAR_CONTEXT_MENU_REGISTRY::RegisterMenuFactory( const std::string& aActionName, + MENU_FACTORY aFactory ) +{ + getActionMenus()[aActionName] = std::move( aFactory ); +} + + +void TOOLBAR_CONTEXT_MENU_REGISTRY::RegisterGroupMenuFactory( const std::string& aGroupName, + MENU_FACTORY aFactory ) +{ + getGroupMenus()[aGroupName] = std::move( aFactory ); +} + + +TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY +TOOLBAR_CONTEXT_MENU_REGISTRY::GetMenuFactory( const std::string& aActionName ) +{ + auto& menus = getActionMenus(); + auto it = menus.find( aActionName ); + + if( it != menus.end() ) + return it->second; + + return nullptr; +} + + +TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY +TOOLBAR_CONTEXT_MENU_REGISTRY::GetGroupMenuFactory( const std::string& aGroupName ) +{ + auto& menus = getGroupMenus(); + auto it = menus.find( aGroupName ); + + if( it != menus.end() ) + return it->second; + + return nullptr; +} diff --git a/eeschema/symbol_editor/toolbars_symbol_editor.cpp b/eeschema/symbol_editor/toolbars_symbol_editor.cpp index 63123dd919..aac6f48ab2 100644 --- a/eeschema/symbol_editor/toolbars_symbol_editor.cpp +++ b/eeschema/symbol_editor/toolbars_symbol_editor.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -58,6 +60,14 @@ std::optional SYMBOL_EDIT_TOOLBAR_SETTINGS::DefaultToolba case TOOLBAR_LOC::LEFT: config.AppendAction( ACTIONS::toggleGrid ) + .WithContextMenu( + []( TOOL_MANAGER* aToolMgr ) + { + SCH_SELECTION_TOOL* selTool = aToolMgr->GetTool(); + auto menu = std::make_unique( false, selTool ); + menu->Add( ACTIONS::gridProperties ); + return menu; + } ) .AppendAction( ACTIONS::toggleGridOverrides ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) ) .AddAction( ACTIONS::millimetersUnits ) @@ -80,13 +90,6 @@ std::optional SYMBOL_EDIT_TOOLBAR_SETTINGS::DefaultToolba config.AppendSeparator() .AppendAction( ACTIONS::showLibraryTree ) .AppendAction( ACTIONS::showProperties ); - - /* TODO: Implement context menus - EE_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - std::unique_ptr gridMenu = std::make_unique( false, selTool ); - gridMenu->Add( ACTIONS::gridProperties ); - m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) ); - */ break; case TOOLBAR_LOC::RIGHT: diff --git a/eeschema/toolbars_sch_editor.cpp b/eeschema/toolbars_sch_editor.cpp index 39cf9d230f..719c18a00c 100644 --- a/eeschema/toolbars_sch_editor.cpp +++ b/eeschema/toolbars_sch_editor.cpp @@ -33,8 +33,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -64,6 +66,14 @@ std::optional SCH_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo case TOOLBAR_LOC::LEFT: config.AppendAction( ACTIONS::toggleGrid ) + .WithContextMenu( + []( TOOL_MANAGER* aToolMgr ) + { + SCH_SELECTION_TOOL* selTool = aToolMgr->GetTool(); + auto menu = std::make_unique( false, selTool ); + menu->Add( ACTIONS::gridProperties ); + return menu; + } ) .AppendAction( ACTIONS::toggleGridOverrides ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) ) .AddAction( ACTIONS::inchesUnits ) @@ -93,12 +103,6 @@ std::optional SCH_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes ) config.AppendAction( ACTIONS::toggleBoundingBoxes ); - /* TODO (ISM): Handle context menus - EE_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - std::unique_ptr gridMenu = std::make_unique( false, selTool ); - gridMenu->Add( ACTIONS::gridProperties ); - m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) ); - */ break; case TOOLBAR_LOC::RIGHT: diff --git a/include/tool/ui/toolbar_configuration.h b/include/tool/ui/toolbar_configuration.h index 52ca850fcd..345325dc10 100644 --- a/include/tool/ui/toolbar_configuration.h +++ b/include/tool/ui/toolbar_configuration.h @@ -32,6 +32,7 @@ #include #include #include +#include enum class TOOLBAR_ITEM_TYPE { @@ -89,6 +90,51 @@ public: std::vector m_GroupItems; }; +// Forward declaration for use in TOOLBAR_ITEM_REF +class TOOLBAR_GROUP_CONFIG; + +/** + * Helper class returned by TOOLBAR_CONFIGURATION::AppendAction() to allow + * chaining of context menu registration. + */ +class KICOMMON_API TOOLBAR_ITEM_REF +{ +public: + TOOLBAR_ITEM_REF( class TOOLBAR_CONFIGURATION& aParent, TOOLBAR_ITEM& aItem ) : + m_parent( aParent ), + m_item( aItem ) + { + } + + /** + * Associate a context menu factory with this action. + * + * The factory is registered globally so JSON-loaded configurations + * will also get this menu. + * + * @param aFactory Factory function that creates the context menu + * @return Reference to parent configuration for continued chaining + */ + TOOLBAR_CONFIGURATION& WithContextMenu( + TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY aFactory ); + + /// Allow implicit conversion back to TOOLBAR_CONFIGURATION for chaining + operator TOOLBAR_CONFIGURATION&() { return m_parent; } + + // Forwarding methods to allow continued chaining after WithContextMenu or directly + TOOLBAR_ITEM_REF AppendAction( const std::string& aActionName ); + TOOLBAR_ITEM_REF AppendAction( const TOOL_ACTION& aAction ); + TOOLBAR_CONFIGURATION& AppendSeparator(); + TOOLBAR_CONFIGURATION& AppendSpacer( int aSize ); + TOOLBAR_CONFIGURATION& AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup ); + TOOLBAR_CONFIGURATION& AppendControl( const std::string& aControlName ); + TOOLBAR_CONFIGURATION& AppendControl( const ACTION_TOOLBAR_CONTROL& aControl ); + +private: + TOOLBAR_CONFIGURATION& m_parent; + TOOLBAR_ITEM& m_item; +}; + class KICOMMON_API TOOLBAR_GROUP_CONFIG { public: @@ -115,6 +161,25 @@ public: return *this; } + /** + * Associate a context menu factory with this group. + * + * The menu will be available for all actions in the group. + * The factory is registered globally so JSON-loaded configurations + * will also get this menu. + * + * @param aFactory Factory function that creates the context menu + * @return Reference for continued chaining + */ + TOOLBAR_GROUP_CONFIG& AddContextMenu( + TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY aFactory ) + { + // Register the factory globally using the group name + TOOLBAR_CONTEXT_MENU_REGISTRY::RegisterGroupMenuFactory( + m_groupName.ToStdString(), std::move( aFactory ) ); + return *this; + } + std::vector GetGroupItems() const { return m_groupItems; @@ -134,16 +199,16 @@ public: TOOLBAR_CONFIGURATION() {} virtual ~TOOLBAR_CONFIGURATION() {} - TOOLBAR_CONFIGURATION& AppendAction( const std::string& aActionName ) + TOOLBAR_ITEM_REF AppendAction( const std::string& aActionName ) { m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName ); - return *this; + return TOOLBAR_ITEM_REF( *this, m_toolbarItems.back() ); } - TOOLBAR_CONFIGURATION& AppendAction( const TOOL_ACTION& aAction ) + TOOLBAR_ITEM_REF AppendAction( const TOOL_ACTION& aAction ) { m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() ); - return *this; + return TOOLBAR_ITEM_REF( *this, m_toolbarItems.back() ); } TOOLBAR_CONFIGURATION& AppendSeparator() diff --git a/include/tool/ui/toolbar_context_menu_registry.h b/include/tool/ui/toolbar_context_menu_registry.h new file mode 100644 index 0000000000..d53990af4b --- /dev/null +++ b/include/tool/ui/toolbar_context_menu_registry.h @@ -0,0 +1,86 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef TOOLBAR_CONTEXT_MENU_REGISTRY_H_ +#define TOOLBAR_CONTEXT_MENU_REGISTRY_H_ + +#include +#include +#include +#include + +class ACTION_MENU; +class TOOL_MANAGER; + +/** + * Registry for toolbar context menu factories. + * + * This allows context menus to be associated with actions and groups by name, + * so that JSON-loaded toolbar configurations can get the same menus as + * code-defined default configurations. + */ +class KICOMMON_API TOOLBAR_CONTEXT_MENU_REGISTRY +{ +public: + /// Factory function type: takes TOOL_MANAGER, returns owned ACTION_MENU + using MENU_FACTORY = std::function( TOOL_MANAGER* )>; + + /** + * Register a context menu factory for an action. + * + * @param aActionName The action name (from TOOL_ACTION::GetName()) + * @param aFactory Factory function that creates the menu + */ + static void RegisterMenuFactory( const std::string& aActionName, MENU_FACTORY aFactory ); + + /** + * Register a context menu factory for a toolbar group. + * + * @param aGroupName The group name (from TOOLBAR_GROUP_CONFIG) + * @param aFactory Factory function that creates the menu + */ + static void RegisterGroupMenuFactory( const std::string& aGroupName, MENU_FACTORY aFactory ); + + /** + * Get the menu factory for an action, if one is registered. + * + * @param aActionName The action name to look up + * @return The factory function, or nullptr if not registered + */ + static MENU_FACTORY GetMenuFactory( const std::string& aActionName ); + + /** + * Get the menu factory for a group, if one is registered. + * + * @param aGroupName The group name to look up + * @return The factory function, or nullptr if not registered + */ + static MENU_FACTORY GetGroupMenuFactory( const std::string& aGroupName ); + +private: + // Use Meyer's singleton to prevent SIOF + static std::map& getActionMenus(); + static std::map& getGroupMenus(); +}; + +#endif /* TOOLBAR_CONTEXT_MENU_REGISTRY_H_ */ diff --git a/pagelayout_editor/toolbars_pl_editor.cpp b/pagelayout_editor/toolbars_pl_editor.cpp index 5242b2f4bd..fc6a0f2d28 100644 --- a/pagelayout_editor/toolbars_pl_editor.cpp +++ b/pagelayout_editor/toolbars_pl_editor.cpp @@ -20,8 +20,10 @@ */ #include +#include #include #include +#include #include #include #include @@ -44,17 +46,18 @@ std::optional PL_EDITOR_TOOLBAR_SETTINGS::DefaultToolbarC case TOOLBAR_LOC::LEFT: config.AppendAction( ACTIONS::toggleGrid ) + .WithContextMenu( + []( TOOL_MANAGER* aToolMgr ) + { + PL_SELECTION_TOOL* selTool = aToolMgr->GetTool(); + auto menu = std::make_unique( false, selTool ); + menu->Add( ACTIONS::gridProperties ); + return menu; + } ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) ) .AddAction( ACTIONS::millimetersUnits ) .AddAction( ACTIONS::inchesUnits ) .AddAction( ACTIONS::milsUnits ) ); - - /* TODO: Implement context menus - PL_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - std::unique_ptr gridMenu = std::make_unique( false, selTool ); - gridMenu->Add( ACTIONS::gridProperties ); - m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) ); - */ break; case TOOLBAR_LOC::RIGHT: diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 1e9f6535b1..d09e49424c 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -21,12 +21,14 @@ */ #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -49,6 +51,15 @@ std::optional FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo case TOOLBAR_LOC::LEFT: config.AppendAction( ACTIONS::toggleGrid ) + .WithContextMenu( + []( TOOL_MANAGER* aToolMgr ) + { + PCB_SELECTION_TOOL* selTool = aToolMgr->GetTool(); + auto menu = std::make_unique( false, selTool ); + menu->Add( ACTIONS::gridProperties ); + menu->Add( ACTIONS::gridOrigin ); + return menu; + } ) .AppendAction( ACTIONS::toggleGridOverrides ) .AppendAction( PCB_ACTIONS::togglePolarCoords ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) ) @@ -79,14 +90,6 @@ std::optional FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo .AppendAction( ACTIONS::showLibraryTree ) .AppendAction( PCB_ACTIONS::showLayersManager ) .AppendAction( ACTIONS::showProperties ); - - /* TODO (ISM): Implement context menus - PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - std::unique_ptr gridMenu = std::make_unique( false, selTool ); - gridMenu->Add( ACTIONS::gridProperties ); - gridMenu->Add( ACTIONS::gridOrigin ); - m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) ); - */ break; case TOOLBAR_LOC::RIGHT: @@ -101,6 +104,16 @@ std::optional FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo config.AppendSeparator() .AppendAction( PCB_ACTIONS::drawLine ) .AppendAction( PCB_ACTIONS::drawArc ) + .WithContextMenu( + []( TOOL_MANAGER* aToolMgr ) + { + PCB_SELECTION_TOOL* selTool = aToolMgr->GetTool(); + auto menu = std::make_unique( false, selTool ); + menu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); + menu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); + menu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); + return menu; + } ) .AppendAction( PCB_ACTIONS::drawRectangle ) .AppendAction( PCB_ACTIONS::drawCircle ) .AppendAction( PCB_ACTIONS::drawPolygon ) @@ -122,24 +135,6 @@ std::optional FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo .AppendAction( PCB_ACTIONS::setAnchor ) .AppendAction( ACTIONS::gridSetOrigin ) .AppendAction( ACTIONS::measureTool ); - - /* TODO (ISM): Implement context menus - PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - - auto makeArcMenu = - [&]() - { - std::unique_ptr arcMenu = std::make_unique( false, selTool ); - - arcMenu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); - - return arcMenu; - }; - - m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawArc, makeArcMenu() ); - */ break; case TOOLBAR_LOC::TOP_MAIN: diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index dc9f51b4b2..c04c98a250 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -43,11 +43,14 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -137,6 +140,18 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo { case TOOLBAR_LOC::LEFT: config.AppendAction( ACTIONS::toggleGrid ) + .WithContextMenu( + []( TOOL_MANAGER* aMgr ) -> std::unique_ptr + { + PCB_SELECTION_TOOL* selTool = aMgr->GetTool(); + std::unique_ptr menu = + std::make_unique( false, selTool ); + + menu->Add( ACTIONS::gridProperties ); + menu->Add( ACTIONS::gridOrigin ); + + return menu; + } ) .AppendAction( ACTIONS::toggleGridOverrides ) .AppendAction( PCB_ACTIONS::togglePolarCoords ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Units" ) ) @@ -185,13 +200,6 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo .AppendAction( PCB_ACTIONS::showLayersManager ) .AppendAction( ACTIONS::showProperties ); - /* TODO (ISM): Support context menus in toolbars - PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - std::unique_ptr gridMenu = std::make_unique( false, selTool ); - gridMenu->Add( ACTIONS::gridProperties ); - gridMenu->Add( ACTIONS::gridOrigin ); - m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) ); - */ break; case TOOLBAR_LOC::RIGHT: @@ -204,18 +212,58 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo .AppendAction( PCB_ACTIONS::placeFootprint ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track routing tools" ) ) .AddAction( PCB_ACTIONS::routeSingleTrack ) - .AddAction( PCB_ACTIONS::routeDiffPair ) ) + .AddAction( PCB_ACTIONS::routeDiffPair ) + .AddContextMenu( + []( TOOL_MANAGER* aMgr ) -> std::unique_ptr + { + PCB_SELECTION_TOOL* selTool = aMgr->GetTool(); + std::unique_ptr menu = + std::make_unique( false, selTool ); + + menu->Add( PCB_ACTIONS::routerHighlightMode, ACTION_MENU::CHECK ); + menu->Add( PCB_ACTIONS::routerShoveMode, ACTION_MENU::CHECK ); + menu->Add( PCB_ACTIONS::routerWalkaroundMode, ACTION_MENU::CHECK ); + menu->AppendSeparator(); + menu->Add( PCB_ACTIONS::routerSettingsDialog ); + + return menu; + } ) ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track tuning tools" ) ) .AddAction( PCB_ACTIONS::tuneSingleTrack ) .AddAction( PCB_ACTIONS::tuneDiffPair ) .AddAction( PCB_ACTIONS::tuneSkew ) ) .AppendAction( PCB_ACTIONS::drawVia ) .AppendAction( PCB_ACTIONS::drawZone ) + .WithContextMenu( + []( TOOL_MANAGER* aMgr ) -> std::unique_ptr + { + PCB_SELECTION_TOOL* selTool = aMgr->GetTool(); + std::unique_ptr menu = + std::make_unique( false, selTool ); + + menu->Add( PCB_ACTIONS::zoneFillAll ); + menu->Add( PCB_ACTIONS::zoneUnfillAll ); + + return menu; + } ) .AppendAction( PCB_ACTIONS::drawRuleArea ); config.AppendSeparator() .AppendAction( PCB_ACTIONS::drawLine ) .AppendAction( PCB_ACTIONS::drawArc ) + .WithContextMenu( + []( TOOL_MANAGER* aMgr ) -> std::unique_ptr + { + PCB_SELECTION_TOOL* selTool = aMgr->GetTool(); + std::unique_ptr menu = + std::make_unique( false, selTool ); + + menu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); + menu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); + menu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); + + return menu; + } ) .AppendAction( PCB_ACTIONS::drawRectangle ) .AppendAction( PCB_ACTIONS::drawCircle ) .AppendAction( PCB_ACTIONS::drawPolygon ) @@ -240,49 +288,6 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo .AppendAction( PCB_ACTIONS::placePoint ) .AppendAction( ACTIONS::measureTool ); - /* TODO (ISM): Support context menus - PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - - auto makeArcMenu = - [&]() - { - std::unique_ptr arcMenu = std::make_unique( false, selTool ); - - arcMenu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); - - return arcMenu; - }; - - m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawArc, makeArcMenu() ); - - auto makeRouteMenu = - [&]() - { - std::unique_ptr routeMenu = std::make_unique( false, selTool ); - - routeMenu->Add( PCB_ACTIONS::routerHighlightMode, ACTION_MENU::CHECK ); - routeMenu->Add( PCB_ACTIONS::routerShoveMode, ACTION_MENU::CHECK ); - routeMenu->Add( PCB_ACTIONS::routerWalkaroundMode, ACTION_MENU::CHECK ); - - routeMenu->AppendSeparator(); - routeMenu->Add( PCB_ACTIONS::routerSettingsDialog ); - - return routeMenu; - }; - - m_tbRight->AddToolContextMenu( PCB_ACTIONS::routeSingleTrack, makeRouteMenu() ); - m_tbRight->AddToolContextMenu( PCB_ACTIONS::routeDiffPair, makeRouteMenu() ); - - std::unique_ptr zoneMenu = std::make_unique( false, selTool ); - zoneMenu->Add( PCB_ACTIONS::zoneFillAll ); - zoneMenu->Add( PCB_ACTIONS::zoneUnfillAll ); - m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawZone, std::move( zoneMenu ) ); - - std::unique_ptr lineMenu = std::make_unique( false, selTool ); - m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawLine, std::move( lineMenu ) ); - */ break; case TOOLBAR_LOC::TOP_MAIN: