Re-jigger standard submenus so they both link AND work.

This commit is contained in:
Jeff Young 2019-06-11 15:38:21 +01:00
parent 05652d4787
commit 7726b039b2
17 changed files with 53 additions and 65 deletions

View File

@ -45,6 +45,11 @@
#include <ws_draw_item.h>
#include <page_info.h>
#include <title_block.h>
#include <tool/tool_menu.h>
#include <tool/selection_conditions.h>
#include <tool/zoom_menu.h>
#include <tool/grid_menu.h>
#include <tool/common_tools.h>
/**
* Definition for enabling and disabling scroll bar setting trace output. See the
@ -328,6 +333,31 @@ double EDA_DRAW_FRAME::GetZoom()
}
void EDA_DRAW_FRAME::AddStandardSubMenus( TOOL_MENU& aToolMenu )
{
COMMON_TOOLS* commonTools = m_toolManager->GetTool<COMMON_TOOLS>();
CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu();
aMenu.AddItem( ACTIONS::zoomCenter, SELECTION_CONDITIONS::ShowAlways, 1000 );
aMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 );
aMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways, 1000 );
aMenu.AddItem( ACTIONS::zoomFitScreen, SELECTION_CONDITIONS::ShowAlways, 1000 );
aMenu.AddSeparator(SELECTION_CONDITIONS::ShowAlways, 1000 );
auto zoomMenu = std::make_shared<ZOOM_MENU>( this );
zoomMenu->SetTool( commonTools );
aToolMenu.AddSubMenu( zoomMenu );
auto gridMenu = std::make_shared<GRID_MENU>( this );
gridMenu->SetTool( commonTools );
aToolMenu.AddSubMenu( gridMenu );
aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 );
}
void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
{
m_toolMsg = msg;

View File

@ -76,24 +76,3 @@ void TOOL_MENU::CloseContextMenu( OPT_TOOL_EVENT& evt )
{
}
// This makes the factory functions a bit less verbose
using S_C = SELECTION_CONDITIONS;
void TOOL_MENU::AddStandardSubMenus( EDA_DRAW_FRAME* aFrame )
{
#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR )
m_menu.AddItem( ACTIONS::zoomCenter, S_C::ShowAlways, 1000 );
m_menu.AddItem( ACTIONS::zoomIn, S_C::ShowAlways, 1000 );
m_menu.AddItem( ACTIONS::zoomOut, S_C::ShowAlways, 1000 );
m_menu.AddItem( ACTIONS::zoomFitScreen, S_C::ShowAlways, 1000 );
m_menu.AddSeparator(SELECTION_CONDITIONS::ShowAlways, 1000 );
if( aFrame )
{
m_menu.AddMenu( createOwnSubMenu<ZOOM_MENU>( aFrame ).get(), S_C::ShowAlways, 1000 );
m_menu.AddMenu( createOwnSubMenu<GRID_MENU>( aFrame ).get(), S_C::ShowAlways, 1000 );
}
#endif
}

View File

@ -45,8 +45,7 @@ CVPCB_SELECTION_TOOL::CVPCB_SELECTION_TOOL() :
bool CVPCB_SELECTION_TOOL::Init()
{
m_menu.AddStandardSubMenus( getEditFrame<DISPLAY_FOOTPRINTS_FRAME>() );
getEditFrame<DISPLAY_FOOTPRINTS_FRAME>()->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -238,7 +238,7 @@ bool EE_SELECTION_TOOL::Init()
menu.AddItem( EE_ACTIONS::pinTable, havePartCondition && EE_CONDITIONS::Empty, 400 );
menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddStandardSubMenus( m_frame );
m_frame->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -80,7 +80,7 @@ public:
ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 );
// Finally, add the standard zoom/grid items
m_menu.AddStandardSubMenus( m_frame );
m_frame->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -165,7 +165,7 @@ bool GERBVIEW_SELECTION_TOOL::Init()
menu.AddMenu( selectMenu.get() );
menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddStandardSubMenus( getEditFrame<GERBVIEW_FRAME>() );
getEditFrame<GERBVIEW_FRAME>()->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -37,6 +37,7 @@
class wxSingleInstanceChecker;
class EDA_HOTKEY;
class ACTION_TOOLBAR;
class TOOL_MENU;
using KIGFX::COLOR4D;
@ -515,6 +516,14 @@ public:
*/
double GetZoom();
/**
* Function CreateBasicMenu
*
* Construct a "basic" menu for a tool, containing only items
* that apply to all tools (e.g. zoom and grid)
*/
void AddStandardSubMenus( TOOL_MENU& aMenu );
/**
* Prints the page layout with the frame and the basic inscriptions.
*

View File

@ -118,36 +118,7 @@ public:
*/
void CloseContextMenu( OPT_TOOL_EVENT& evt );
/**
* Function CreateBasicMenu
*
* Construct a "basic" menu for a tool, containing only items
* that apply to all tools (e.g. zoom and grid)
*/
void AddStandardSubMenus( EDA_DRAW_FRAME* aFrame );
private:
/*!
* Helper function for factories to abe able to easily add
* their own new sub menus. This sets the tool to the TOOL_MENUs
* owner and adds to the store.
*
* Note, this won't share the menu between multiple invocations
* of the factory. But if different top-level tools are using the
* same factory, which one would be used for SetTool()?
*/
template <typename T, typename ... Args>
std::shared_ptr<T> createOwnSubMenu( Args&& ... args )
{
auto subMenuPtr = std::make_shared<T>( args ... );
subMenuPtr->SetTool( &m_tool );
AddSubMenu( subMenuPtr );
return subMenuPtr;
}
/**
* The conditional menu displayed by the tool
*/

View File

@ -100,7 +100,7 @@ bool PL_DRAWING_TOOLS::Init()
ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 );
// Finally, add the standard zoom/grid items
m_menu.AddStandardSubMenus( m_frame );
m_frame->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -80,7 +80,7 @@ bool PL_EDIT_TOOL::Init()
ctxMenu.AddItem( PL_ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 200 );
// Finally, add the standard zoom/grid items
m_menu.AddStandardSubMenus( m_frame );
m_frame->AddStandardSubMenus( m_menu );
//
// Add editing actions to the selection tool menu

View File

@ -53,7 +53,7 @@ bool PL_PICKER_TOOL::Init()
ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 );
// Finally, add the standard zoom/grid items
m_menu.AddStandardSubMenus( m_frame );
m_frame->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -102,7 +102,7 @@ bool PL_SELECTION_TOOL::Init()
menu.AddItem( PL_ACTIONS::appendImportedWorksheet, PL_CONDITIONS::Idle, 250 );
menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddStandardSubMenus( m_frame );
m_frame->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -224,7 +224,7 @@ bool DRAWING_TOOL::Init()
// For example, zone fill/unfill is provided by the PCB control tool
// Finally, add the standard zoom/grid items
m_menu.AddStandardSubMenus( getEditFrame<PCB_BASE_FRAME>() );
getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -282,7 +282,7 @@ bool EDIT_TOOL::Init()
ctxMenu.AddSeparator( activeToolCondition, 1 );
if( frame )
m_menu.AddStandardSubMenus( frame );
frame->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -382,7 +382,7 @@ bool PCB_EDITOR_CONTROL::Init()
ctxMenu.AddSeparator( placeModuleCondition, 1000 );
// Finally, add the standard zoom & grid items
m_menu.AddStandardSubMenus( getEditFrame<PCB_BASE_FRAME>() );
getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
auto zoneMenu = std::make_shared<ZONE_CONTEXT_MENU>();
zoneMenu->SetTool( this );

View File

@ -219,7 +219,7 @@ bool PCB_TOOL_BASE::Init()
ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 );
// Finally, add the standard zoom/grid items
m_menu.AddStandardSubMenus( getEditFrame<PCB_BASE_FRAME>() );
getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
return true;
}

View File

@ -211,7 +211,7 @@ bool SELECTION_TOOL::Init()
if( frame && ( frame->IsType( FRAME_PCB_MODULE_VIEWER )
|| frame->IsType( FRAME_PCB_MODULE_VIEWER_MODAL ) ) )
{
m_menu.AddStandardSubMenus( frame );
frame->AddStandardSubMenus( m_menu );
return true;
}
@ -225,7 +225,7 @@ bool SELECTION_TOOL::Init()
menu.AddSeparator( SELECTION_CONDITIONS::NotEmpty, 1000 );
if( frame )
m_menu.AddStandardSubMenus( frame );
frame->AddStandardSubMenus( m_menu );
return true;
}