From c50d28d94deccdfe6da87fbadb143fc5df51aa89 Mon Sep 17 00:00:00 2001 From: John Beard Date: Thu, 12 Jan 2017 18:07:52 +0800 Subject: [PATCH] Access tools' TOOL_MENUs rather than CONDITIONAL_MENUs This means that non-top-level tools, for example EDIT_TOOL and PCB_EDITOR_CONTROL can submit their own menus to the top-level tool's TOOL_MENU, which will then retain a reference to it and make it available for the CONTEXT_MENU that is shown. --- pcbnew/tools/drawing_tool.h | 4 ++-- pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/tools/module_tools.cpp | 2 +- pcbnew/tools/pcb_editor_control.cpp | 35 ++++++++++++++++++----------- pcbnew/tools/pcb_editor_control.h | 5 ----- pcbnew/tools/placement_tool.cpp | 5 +++-- pcbnew/tools/point_editor.cpp | 9 ++++---- pcbnew/tools/selection_tool.h | 4 ++-- 8 files changed, 36 insertions(+), 30 deletions(-) diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index da0012eb4f..2b2d211929 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -58,9 +58,9 @@ public: void Reset( RESET_REASON aReason ) override; ///> Get the DRAWING_TOOL top-level context menu - inline CONDITIONAL_MENU& GetMenu() + inline TOOL_MENU& GetToolMenu() { - return m_menu.GetMenu(); + return m_menu; } ///> The possible drawing modes of DRAWING_TOOL diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index fd83a4bf97..2a38bc88fc 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -87,7 +87,7 @@ bool EDIT_TOOL::Init() } // Add context menu entries that are displayed when selection tool is active - CONDITIONAL_MENU& menu = m_selectionTool->GetMenu(); + CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu(); menu.AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); diff --git a/pcbnew/tools/module_tools.cpp b/pcbnew/tools/module_tools.cpp index 2cc251ad89..59a6fce47a 100644 --- a/pcbnew/tools/module_tools.cpp +++ b/pcbnew/tools/module_tools.cpp @@ -96,7 +96,7 @@ bool MODULE_TOOLS::Init() return false; } - selectionTool->GetMenu().AddItem( COMMON_ACTIONS::enumeratePads ); + selectionTool->GetToolMenu().GetMenu().AddItem( COMMON_ACTIONS::enumeratePads ); return true; } diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 599e33a110..8a98ea4d78 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -105,7 +105,7 @@ public: PCB_EDITOR_CONTROL::PCB_EDITOR_CONTROL() : TOOL_INTERACTIVE( "pcbnew.EditorControl" ), - m_frame( NULL ), m_zoneMenu( NULL ), m_lockMenu( NULL ) + m_frame( nullptr ) { m_placeOrigin = new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ), KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS ); @@ -118,8 +118,6 @@ PCB_EDITOR_CONTROL::~PCB_EDITOR_CONTROL() getView()->Remove( m_placeOrigin ); delete m_placeOrigin; - delete m_zoneMenu; - delete m_lockMenu; } @@ -138,11 +136,11 @@ void PCB_EDITOR_CONTROL::Reset( RESET_REASON aReason ) bool PCB_EDITOR_CONTROL::Init() { - m_zoneMenu = new ZONE_CONTEXT_MENU; - m_zoneMenu->SetTool( this ); + auto zoneMenu = std::make_shared(); + zoneMenu->SetTool( this ); - m_lockMenu = new LOCK_CONTEXT_MENU; - m_lockMenu->SetTool( this ); + auto lockMenu = std::make_shared(); + lockMenu->SetTool( this ); // Add the PCB control menus to relevant other tools @@ -150,17 +148,28 @@ bool PCB_EDITOR_CONTROL::Init() if( selTool ) { - selTool->GetMenu().AddMenu( m_zoneMenu, _( "Zones" ), false, - SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); + auto& toolMenu = selTool->GetToolMenu(); + auto& menu = toolMenu.GetMenu(); - selTool->GetMenu().AddMenu( m_lockMenu, _( "Locking" ), false, - SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); + toolMenu.AddSubMenu( zoneMenu ); + toolMenu.AddSubMenu( lockMenu ); + + menu.AddMenu( zoneMenu.get(), _( "Zones" ), false, + SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); + + menu.AddMenu( lockMenu.get(), _( "Locking" ), false, + SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); } DRAWING_TOOL* drawingTool = m_toolMgr->GetTool(); if( drawingTool ) { + auto& toolMenu = drawingTool->GetToolMenu(); + auto& menu = toolMenu.GetMenu(); + + toolMenu.AddSubMenu( zoneMenu ); + // Functor to say if the PCB_EDIT_FRAME is in a given mode // Capture the tool pointer and tool mode by value auto toolActiveFunctor = [=]( DRAWING_TOOL::MODE aMode ) @@ -171,8 +180,8 @@ bool PCB_EDITOR_CONTROL::Init() }; }; - drawingTool->GetMenu().AddMenu( m_zoneMenu, _( "Zones" ), false, - toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ) ); + menu.AddMenu( zoneMenu.get(), _( "Zones" ), false, + toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ) ); } return true; diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index bbf99e7243..1647297d11 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -32,8 +32,6 @@ namespace KIGFX { } class PCB_EDIT_FRAME; -class ZONE_CONTEXT_MENU; -class LOCK_CONTEXT_MENU; /** * Class PCB_EDITOR_CONTROL @@ -121,9 +119,6 @@ private: // How does line width change after one -/+ key press. static const int WIDTH_STEP; - - ZONE_CONTEXT_MENU* m_zoneMenu; - LOCK_CONTEXT_MENU* m_lockMenu; }; #endif diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 55a765f066..fd850ca154 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -77,8 +77,9 @@ bool PLACEMENT_TOOL::Init() item = m_placementMenu->Add( COMMON_ACTIONS::distributeVertically ); SET_BITMAP( KiBitmap( distribute_vertical_xpm ) ); - m_selectionTool->GetMenu().AddMenu( m_placementMenu, _( "Align/distribute" ), false, - SELECTION_CONDITIONS::MoreThan( 1 ) ); + m_selectionTool->GetToolMenu().GetMenu().AddMenu( + m_placementMenu, _( "Align/distribute" ), false, + SELECTION_CONDITIONS::MoreThan( 1 ) ); return true; } diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 38b570b582..e792869648 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -211,10 +211,11 @@ bool POINT_EDITOR::Init() return false; } - m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::pointEditorAddCorner, - POINT_EDITOR::addCornerCondition ); - m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::pointEditorRemoveCorner, - std::bind( &POINT_EDITOR::removeCornerCondition, this, _1 ) ); + auto& menu = m_selectionTool->GetToolMenu().GetMenu(); + menu.AddItem( COMMON_ACTIONS::pointEditorAddCorner, + POINT_EDITOR::addCornerCondition ); + menu.AddItem( COMMON_ACTIONS::pointEditorRemoveCorner, + std::bind( &POINT_EDITOR::removeCornerCondition, this, _1 ) ); return true; } diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index eaebaa0734..ec2edc95ca 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -193,9 +193,9 @@ public: */ SELECTION& GetSelection(); - inline CONDITIONAL_MENU& GetMenu() + inline TOOL_MENU& GetToolMenu() { - return m_menu.GetMenu(); + return m_menu; } ///> Checks if the user has agreed to modify locked items for the given selection.