ADDED toolbar context menus

Provides a global registry for context menu factories keyed by
action or group name. This allows JSON-loaded toolbar configurations
to get the same context menus as code-defined defaults.

API syntax:
  config.AppendAction( ACTION ).WithContextMenu( factory );

The WithContextMenu() method registers the factory in the
global registry keyed by action name.

Context menus can also be associated with toolbar groups:
  TOOLBAR_GROUP_CONFIG( name )
      .AddAction( A )
      .AddAction( B )
      .AddContextMenu( factory )

The factory is registered globally by group name.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20713
This commit is contained in:
Seth Hillbrand
2026-01-02 10:09:45 -08:00
parent e8cd9cdfac
commit 3a89a5a9f5
11 changed files with 417 additions and 102 deletions
+1
View File
@@ -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
+19
View File
@@ -41,6 +41,7 @@
#include <tool/tool_interactive.h>
#include <tool/tool_manager.h>
#include <tool/ui/toolbar_configuration.h>
#include <tool/ui/toolbar_context_menu_registry.h>
#include <widgets/bitmap_button.h>
#include <widgets/wx_aui_art_providers.h>
@@ -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;
}
}
+55 -1
View File
@@ -27,6 +27,7 @@
#include <tool/action_toolbar.h>
#include <tool/ui/toolbar_configuration.h>
#include <tool/ui/toolbar_context_menu_registry.h>
///! Update the schema version whenever a migration is required
const int toolbarSchemaVersion = 1;
@@ -213,4 +214,57 @@ std::optional<TOOLBAR_CONFIGURATION> TOOLBAR_SETTINGS::GetStoredToolbarConfig( T
// Return a nullopt if no toolbar is configured
return std::nullopt;
}
}
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 );
}
@@ -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 <tool/ui/toolbar_context_menu_registry.h>
std::map<std::string, TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY>&
TOOLBAR_CONTEXT_MENU_REGISTRY::getActionMenus()
{
static std::map<std::string, MENU_FACTORY> s_actionMenus;
return s_actionMenus;
}
std::map<std::string, TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY>&
TOOLBAR_CONTEXT_MENU_REGISTRY::getGroupMenus()
{
static std::map<std::string, MENU_FACTORY> 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;
}
@@ -30,8 +30,10 @@
#include <symbol_editor_settings.h>
#include <symbol_library_manager.h>
#include <toolbars_symbol_editor.h>
#include <tool/action_menu.h>
#include <tool/action_toolbar.h>
#include <tool/tool_manager.h>
#include <tool/ui/toolbar_context_menu_registry.h>
#include <tools/sch_actions.h>
#include <tools/sch_selection_tool.h>
#include <widgets/sch_properties_panel.h>
@@ -58,6 +60,14 @@ std::optional<TOOLBAR_CONFIGURATION> SYMBOL_EDIT_TOOLBAR_SETTINGS::DefaultToolba
case TOOLBAR_LOC::LEFT:
config.AppendAction( ACTIONS::toggleGrid )
.WithContextMenu(
[]( TOOL_MANAGER* aToolMgr )
{
SCH_SELECTION_TOOL* selTool = aToolMgr->GetTool<SCH_SELECTION_TOOL>();
auto menu = std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> SYMBOL_EDIT_TOOLBAR_SETTINGS::DefaultToolba
config.AppendSeparator()
.AppendAction( ACTIONS::showLibraryTree )
.AppendAction( ACTIONS::showProperties );
/* TODO: Implement context menus
EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
gridMenu->Add( ACTIONS::gridProperties );
m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
*/
break;
case TOOLBAR_LOC::RIGHT:
+10 -6
View File
@@ -33,8 +33,10 @@
#include <eeschema_id.h>
#include <pgm_base.h>
#include <python_scripting.h>
#include <tool/action_menu.h>
#include <tool/tool_manager.h>
#include <tool/action_toolbar.h>
#include <tool/ui/toolbar_context_menu_registry.h>
#include <tools/sch_actions.h>
#include <tools/sch_selection_tool.h>
#include <widgets/hierarchy_pane.h>
@@ -64,6 +66,14 @@ std::optional<TOOLBAR_CONFIGURATION> SCH_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo
case TOOLBAR_LOC::LEFT:
config.AppendAction( ACTIONS::toggleGrid )
.WithContextMenu(
[]( TOOL_MANAGER* aToolMgr )
{
SCH_SELECTION_TOOL* selTool = aToolMgr->GetTool<SCH_SELECTION_TOOL>();
auto menu = std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> 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<EE_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
gridMenu->Add( ACTIONS::gridProperties );
m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
*/
break;
case TOOLBAR_LOC::RIGHT:
+69 -4
View File
@@ -32,6 +32,7 @@
#include <settings/parameters.h>
#include <tool/action_toolbar.h>
#include <tool/tool_action.h>
#include <tool/ui/toolbar_context_menu_registry.h>
enum class TOOLBAR_ITEM_TYPE
{
@@ -89,6 +90,51 @@ public:
std::vector<TOOLBAR_ITEM> 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<TOOLBAR_ITEM> 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()
@@ -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 <functional>
#include <map>
#include <memory>
#include <string>
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<std::unique_ptr<ACTION_MENU>( 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<std::string, MENU_FACTORY>& getActionMenus();
static std::map<std::string, MENU_FACTORY>& getGroupMenus();
};
#endif /* TOOLBAR_CONTEXT_MENU_REGISTRY_H_ */
+10 -7
View File
@@ -20,8 +20,10 @@
*/
#include <bitmaps.h>
#include <tool/action_menu.h>
#include <tool/action_toolbar.h>
#include <tool/tool_manager.h>
#include <tool/ui/toolbar_context_menu_registry.h>
#include <tools/pl_actions.h>
#include <tools/pl_selection_tool.h>
#include <wx/choice.h>
@@ -44,17 +46,18 @@ std::optional<TOOLBAR_CONFIGURATION> PL_EDITOR_TOOLBAR_SETTINGS::DefaultToolbarC
case TOOLBAR_LOC::LEFT:
config.AppendAction( ACTIONS::toggleGrid )
.WithContextMenu(
[]( TOOL_MANAGER* aToolMgr )
{
PL_SELECTION_TOOL* selTool = aToolMgr->GetTool<PL_SELECTION_TOOL>();
auto menu = std::make_unique<ACTION_MENU>( 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<PL_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
gridMenu->Add( ACTIONS::gridProperties );
m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
*/
break;
case TOOLBAR_LOC::RIGHT:
+21 -26
View File
@@ -21,12 +21,14 @@
*/
#include <tool/actions.h>
#include <tool/action_menu.h>
#include <footprint_edit_frame.h>
#include <pcbnew_id.h>
#include <bitmaps.h>
#include <lset.h>
#include <tool/action_toolbar.h>
#include <tool/tool_manager.h>
#include <tool/ui/toolbar_context_menu_registry.h>
#include <tools/pcb_actions.h>
#include <tools/pcb_selection_tool.h>
#include <pcb_layer_box_selector.h>
@@ -49,6 +51,15 @@ std::optional<TOOLBAR_CONFIGURATION> FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo
case TOOLBAR_LOC::LEFT:
config.AppendAction( ACTIONS::toggleGrid )
.WithContextMenu(
[]( TOOL_MANAGER* aToolMgr )
{
PCB_SELECTION_TOOL* selTool = aToolMgr->GetTool<PCB_SELECTION_TOOL>();
auto menu = std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> 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<PCB_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> 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<PCB_SELECTION_TOOL>();
auto menu = std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> 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<PCB_SELECTION_TOOL>();
auto makeArcMenu =
[&]()
{
std::unique_ptr<ACTION_MENU> arcMenu = std::make_unique<ACTION_MENU>( 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:
+56 -51
View File
@@ -43,11 +43,14 @@
#include <router/pns_routing_settings.h>
#include <router/router_tool.h>
#include <settings/color_settings.h>
#include <tool/action_menu.h>
#include <tool/action_toolbar.h>
#include <tool/actions.h>
#include <tool/common_tools.h>
#include <tool/tool_manager.h>
#include <tool/ui/toolbar_context_menu_registry.h>
#include <tools/pcb_actions.h>
#include <tools/pcb_selection_tool.h>
#include <widgets/appearance_controls.h>
#include <widgets/pcb_design_block_pane.h>
#include <widgets/layer_box_selector.h>
@@ -137,6 +140,18 @@ std::optional<TOOLBAR_CONFIGURATION> PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo
{
case TOOLBAR_LOC::LEFT:
config.AppendAction( ACTIONS::toggleGrid )
.WithContextMenu(
[]( TOOL_MANAGER* aMgr ) -> std::unique_ptr<ACTION_MENU>
{
PCB_SELECTION_TOOL* selTool = aMgr->GetTool<PCB_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> menu =
std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> 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<PCB_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> 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<ACTION_MENU>
{
PCB_SELECTION_TOOL* selTool = aMgr->GetTool<PCB_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> menu =
std::make_unique<ACTION_MENU>( 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<ACTION_MENU>
{
PCB_SELECTION_TOOL* selTool = aMgr->GetTool<PCB_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> menu =
std::make_unique<ACTION_MENU>( 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<ACTION_MENU>
{
PCB_SELECTION_TOOL* selTool = aMgr->GetTool<PCB_SELECTION_TOOL>();
std::unique_ptr<ACTION_MENU> menu =
std::make_unique<ACTION_MENU>( 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<TOOLBAR_CONFIGURATION> PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo
.AppendAction( PCB_ACTIONS::placePoint )
.AppendAction( ACTIONS::measureTool );
/* TODO (ISM): Support context menus
PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
auto makeArcMenu =
[&]()
{
std::unique_ptr<ACTION_MENU> arcMenu = std::make_unique<ACTION_MENU>( 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<ACTION_MENU> routeMenu = std::make_unique<ACTION_MENU>( 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<ACTION_MENU> zoneMenu = std::make_unique<ACTION_MENU>( false, selTool );
zoneMenu->Add( PCB_ACTIONS::zoneFillAll );
zoneMenu->Add( PCB_ACTIONS::zoneUnfillAll );
m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawZone, std::move( zoneMenu ) );
std::unique_ptr<ACTION_MENU> lineMenu = std::make_unique<ACTION_MENU>( false, selTool );
m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawLine, std::move( lineMenu ) );
*/
break;
case TOOLBAR_LOC::TOP_MAIN: