KiCad PCB EDA Suite
GRID_MENU Class Reference

#include <grid_menu.h>

Inheritance diagram for GRID_MENU:
ACTION_MENU

Public Member Functions

 GRID_MENU (EDA_DRAW_FRAME *aParent)
 
void SetTitle (const wxString &aTitle) override
 Function SetTitle() Sets title for the menu. More...
 
void DisplayTitle (bool aDisplay=true)
 Function DisplayTitle() Decides whether a title for a pop up menu should be displayed. More...
 
void SetIcon (const BITMAP_OPAQUE *aIcon)
 Function SetIcon() Assigns an icon for the entry. More...
 
wxMenuItem * Add (const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
 Function Add() Adds a wxWidgets-style entry to the menu. More...
 
wxMenuItem * Add (const wxString &aLabel, const wxString &aToolTip, int aId, const BITMAP_OPAQUE *aIcon)
 
wxMenuItem * Add (const TOOL_ACTION &aAction, bool aIsCheckmarkEntry=false)
 Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object. More...
 
wxMenuItem * Add (ACTION_MENU *aMenu)
 Function Add() Adds an action menu as a submenu. More...
 
void Clear ()
 Function Clear() Removes all the entries from the menu (as well as its title). More...
 
bool HasEnabledItems () const
 Function HasEnabledItems();. More...
 
int GetSelected () const
 Function GetSelected() Returns the position of selected item. More...
 
void UpdateAll ()
 Function UpdateAll() Runs update handlers for the menu and its submenus. More...
 
void ClearDirty ()
 Function ClearDirty() Clears the dirty flag on the menu and all descendants. More...
 
void SetDirty ()
 
void SetTool (TOOL_INTERACTIVE *aTool)
 Function SetTool() Sets a tool that is the creator of the menu. More...
 
ACTION_MENUClone () const
 Creates a deep, recursive copy of this ACTION_MENU. More...
 
void OnMenuEvent (wxMenuEvent &aEvent)
 
void OnIdle (wxIdleEvent &event)
 

Protected Member Functions

TOOL_MANAGERgetToolManager () const
 

Returns an instance of TOOL_MANAGER class.

More...
 
void copyFrom (const ACTION_MENU &aMenu)
 Copies another menus data to this instance. More...
 
wxMenuItem * appendCopy (const wxMenuItem *aSource)
 Function appendCopy Appends a copy of wxMenuItem. More...
 
void setupEvents ()
 

Initializes handlers for events.

More...
 
void updateHotKeys ()
 

Updates hot key settings for TOOL_ACTIONs in this menu.

More...
 
void runEventHandlers (const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
 

Traverses the submenus tree looking for a submenu capable of handling a particular menu event.

More...
 
void runOnSubmenus (std::function< void(ACTION_MENU *)> aFunction)
 

Runs a function on the menu and all its submenus.

More...
 
OPT_TOOL_EVENT findToolAction (int aId)
 

Checks if any of submenus contains a TOOL_ACTION with a specific ID.

More...
 

Static Protected Member Functions

static int getMenuId (const TOOL_ACTION &aAction)
 

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

More...
 

Protected Attributes

bool m_dirty
 
bool m_titleDisplayed
 
bool m_isContextMenu
 
wxString m_title
 

Menu title

More...
 
const BITMAP_OPAQUEm_icon
 

Optional icon

More...
 
int m_selected
 

Stores the id number of selected item.

More...
 
TOOL_INTERACTIVEm_tool
 

Creator of the menu

More...
 
std::map< int, const TOOL_ACTION * > m_toolActions
 

Associates tool actions with menu item IDs. Non-owning.

More...
 
std::list< ACTION_MENU * > m_submenus
 

List of submenus.

More...
 

Static Protected Attributes

static const int ACTION_ID = 20000
 

Menu items with ID higher than that are considered TOOL_ACTIONs

More...
 

Private Member Functions

ACTION_MENUcreate () const override
 

Returns an instance of this class. It has to be overridden in inheriting classes.

More...
 
OPT_TOOL_EVENT eventHandler (const wxMenuEvent &aEvent) override
 Event handler stub. More...
 
void update () override
 Update menu state stub. More...
 

Private Attributes

EDA_DRAW_FRAMEm_parent
 

Detailed Description

Definition at line 32 of file grid_menu.h.

Constructor & Destructor Documentation

◆ GRID_MENU()

GRID_MENU::GRID_MENU ( EDA_DRAW_FRAME aParent)

Definition at line 36 of file grid_menu.cpp.

36  :
37  ACTION_MENU( true ),
38  m_parent( aParent )
39 {
40  BASE_SCREEN* screen = m_parent->GetScreen();
41 
42  SetTitle( _( "Grid" ) );
44 
45  wxArrayString gridsList;
46  screen->BuildGridsChoiceList( gridsList, m_parent->GetUserUnits() != EDA_UNITS::INCHES );
47 
48  for( unsigned int i = 0; i < gridsList.GetCount(); ++i )
49  {
50  GRID_TYPE& grid = screen->GetGrid( i );
51  Append( grid.m_CmdId, gridsList[i], wxEmptyString, wxITEM_CHECK );
52  }
53 }
int BuildGridsChoiceList(wxArrayString &aGridsList, bool aMmFirst) const
Function BuildGridsChoiceList().
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:291
const BITMAP_OPAQUE grid_select_xpm[1]
Definition: grid_select.cpp:29
EDA_DRAW_FRAME * m_parent
Definition: grid_menu.h:46
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
GRID_TYPE is for grid arrays.
Definition: base_screen.h:43
#define _(s)
Definition: 3d_actions.cpp:33
ACTION_MENU(bool isContextMenu)
Default constructor
Definition: action_menu.cpp:45
int m_CmdId
Definition: base_screen.h:46
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References _, BASE_SCREEN::BuildGridsChoiceList(), BASE_SCREEN::GetGrid(), EDA_DRAW_FRAME::GetScreen(), EDA_BASE_FRAME::GetUserUnits(), grid_select_xpm, INCHES, GRID_TYPE::m_CmdId, m_parent, ACTION_MENU::SetIcon(), and ACTION_MENU::SetTitle().

Referenced by create().

Member Function Documentation

◆ Add() [1/4]

wxMenuItem * ACTION_MENU::Add ( const wxString &  aLabel,
int  aId,
const BITMAP_OPAQUE aIcon 
)
inherited

Function Add() Adds a wxWidgets-style entry to the menu.

After highlighting/selecting the entry, a wxWidgets event is generated.

Definition at line 136 of file action_menu.cpp.

137 {
138  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
139 
140  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
141 
142  if( aIcon )
143  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
144 
145  return Append( item );
146 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223

References AddBitmapToMenuItem(), and KiBitmap().

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), CONDITIONAL_MENU::Evaluate(), ALIGN_DISTRIBUTE_TOOL::Init(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), CVPCB_MAINFRAME::setupTools(), SPECIAL_TOOLS_CONTEXT_MENU::SPECIAL_TOOLS_CONTEXT_MENU(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

◆ Add() [2/4]

wxMenuItem * ACTION_MENU::Add ( const wxString &  aLabel,
const wxString &  aToolTip,
int  aId,
const BITMAP_OPAQUE aIcon 
)
inherited

Definition at line 149 of file action_menu.cpp.

151 {
152  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
153 
154  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, aTooltip, wxITEM_NORMAL );
155 
156  if( aIcon )
157  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
158 
159  return Append( item );
160 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223

References AddBitmapToMenuItem(), and KiBitmap().

◆ Add() [3/4]

wxMenuItem * ACTION_MENU::Add ( const TOOL_ACTION aAction,
bool  aIsCheckmarkEntry = false 
)
inherited

Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object.

After selecting the entry, a TOOL_EVENT command containing name of the action is sent.

Parameters
aActionis the action to be added to menu entry.

ID numbers for tool actions need to have a value higher than ACTION_ID

Definition at line 163 of file action_menu.cpp.

164 {
166  const BITMAP_OPAQUE* icon = aAction.GetIcon();
167 
168  wxMenuItem* item = new wxMenuItem( this, getMenuId( aAction ), aAction.GetMenuItem(),
169  aAction.GetDescription(),
170  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
171 
172  if( icon )
173  AddBitmapToMenuItem( item, KiBitmap( icon ) );
174 
175  m_toolActions[getMenuId( aAction )] = &aAction;
176 
177  return Append( item );
178 }
PNG memory record (file in memory).
Definition: bitmap_def.h:29
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: action_menu.h:162
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:149
wxString GetDescription() const
Definition: tool_action.cpp:83
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:234
wxString GetMenuItem() const
Definition: tool_action.cpp:75

References AddBitmapToMenuItem(), TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), ACTION_MENU::getMenuId(), TOOL_ACTION::GetMenuItem(), KiBitmap(), and ACTION_MENU::m_toolActions.

◆ Add() [4/4]

wxMenuItem * ACTION_MENU::Add ( ACTION_MENU aMenu)
inherited

Function Add() Adds an action menu as a submenu.

The difference between this function and wxMenu::AppendSubMenu() is the capability to handle icons.

Parameters
aMenuis the submenu to be added.

Definition at line 181 of file action_menu.cpp.

182 {
183  ACTION_MENU* menuCopy = aMenu->Clone();
184  m_submenus.push_back( menuCopy );
185 
186  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
187 
188  if( aMenu->m_icon )
189  {
190  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
191  AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) );
192  newItem->SetSubMenu( menuCopy );
193  return Append( newItem );
194  }
195  else
196  {
197  return AppendSubMenu( menuCopy, menuCopy->m_title );
198  }
199 }
ACTION_MENU.
Definition: action_menu.h:44
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:222
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223
wxString m_title
Menu title
Definition: action_menu.h:219
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:237
ACTION_MENU * Clone() const
Creates a deep, recursive copy of this ACTION_MENU.

References AddBitmapToMenuItem(), ACTION_MENU::Clone(), KiBitmap(), ACTION_MENU::m_icon, ACTION_MENU::m_submenus, and ACTION_MENU::m_title.

◆ appendCopy()

wxMenuItem * ACTION_MENU::appendCopy ( const wxMenuItem *  aSource)
protectedinherited

Function appendCopy Appends a copy of wxMenuItem.

Definition at line 577 of file action_menu.cpp.

578 {
579  wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
580  aSource->GetHelp(), aSource->GetKind() );
581 
582  // Add the source bitmap if it is not the wxNullBitmap
583  // On Windows, for Checkable Menu items, adding a null bitmap adds also
584  // our predefined checked alternate bitmap
585  const wxBitmap& src_bitmap = aSource->GetBitmap();
586 
587  if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size
588  AddBitmapToMenuItem( newItem, src_bitmap );
589 
590  if( aSource->IsSubMenu() )
591  {
592  ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
593  wxASSERT_MSG( menu, "Submenus are expected to be a ACTION_MENU" );
594 
595  if( menu )
596  {
597  ACTION_MENU* menuCopy = menu->Clone();
598  newItem->SetSubMenu( menuCopy );
599  m_submenus.push_back( menuCopy );
600  }
601  }
602 
603  // wxMenuItem has to be added before enabling/disabling or checking
604  Append( newItem );
605 
606  if( aSource->IsCheckable() )
607  newItem->Check( aSource->IsChecked() );
608 
609  newItem->Enable( aSource->IsEnabled() );
610 
611  return newItem;
612 }
ACTION_MENU.
Definition: action_menu.h:44
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:237
ACTION_MENU * Clone() const
Creates a deep, recursive copy of this ACTION_MENU.

References AddBitmapToMenuItem(), ACTION_MENU::Clone(), and ACTION_MENU::m_submenus.

Referenced by ACTION_MENU::copyFrom().

◆ Clear()

void ACTION_MENU::Clear ( )
inherited

Function Clear() Removes all the entries from the menu (as well as its title).

It leaves the menu in the initial state.

Definition at line 202 of file action_menu.cpp.

203 {
204  m_titleDisplayed = false;
205 
206  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
207  Destroy( FindItemByPosition( i ) );
208 
209  m_toolActions.clear();
210  m_submenus.clear();
211 
212  wxASSERT( GetMenuItemCount() == 0 );
213 }
bool m_titleDisplayed
Definition: action_menu.h:215
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:237
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:234

References ACTION_MENU::m_submenus, ACTION_MENU::m_titleDisplayed, and ACTION_MENU::m_toolActions.

Referenced by ACTION_MENU::Clone(), CONDITIONAL_MENU::Evaluate(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), TRACK_WIDTH_MENU::update(), and DIFF_PAIR_MENU::update().

◆ ClearDirty()

void ACTION_MENU::ClearDirty ( )
inherited

Function ClearDirty() Clears the dirty flag on the menu and all descendants.

Definition at line 253 of file action_menu.cpp.

254 {
255  m_dirty = false;
256  runOnSubmenus( std::bind( &ACTION_MENU::ClearDirty, _1 ) );
257 }
void ClearDirty()
Function ClearDirty() Clears the dirty flag on the menu and all descendants.
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.

References ACTION_MENU::m_dirty, and ACTION_MENU::runOnSubmenus().

Referenced by TOOL_MENU::ShowContextMenu().

◆ Clone()

ACTION_MENU * ACTION_MENU::Clone ( ) const
inherited

Creates a deep, recursive copy of this ACTION_MENU.

Definition at line 274 of file action_menu.cpp.

275 {
276  ACTION_MENU* clone = create();
277  clone->Clear();
278  clone->copyFrom( *this );
279  return clone;
280 }
ACTION_MENU.
Definition: action_menu.h:44
virtual ACTION_MENU * create() const
Returns an instance of this class. It has to be overridden in inheriting classes.
void copyFrom(const ACTION_MENU &aMenu)
Copies another menus data to this instance.
void Clear()
Function Clear() Removes all the entries from the menu (as well as its title).

References ACTION_MENU::Clear(), ACTION_MENU::copyFrom(), and ACTION_MENU::create().

Referenced by ACTION_MENU::Add(), ACTION_MENU::appendCopy(), and TOOL_MANAGER::DispatchContextMenu().

◆ copyFrom()

void ACTION_MENU::copyFrom ( const ACTION_MENU aMenu)
protectedinherited

Copies another menus data to this instance.

Old entries are preserved, and ones form aMenu are copied.

Definition at line 559 of file action_menu.cpp.

560 {
561  m_icon = aMenu.m_icon;
562  m_title = aMenu.m_title;
564  m_selected = -1; // aMenu.m_selected;
565  m_tool = aMenu.m_tool;
567 
568  // Copy all menu entries
569  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
570  {
571  wxMenuItem* item = aMenu.FindItemByPosition( i );
572  appendCopy( item );
573  }
574 }
bool m_titleDisplayed
Definition: action_menu.h:215
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:222
wxString m_title
Menu title
Definition: action_menu.h:219
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:225
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:228
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Function appendCopy Appends a copy of wxMenuItem.
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:234

References ACTION_MENU::appendCopy(), ACTION_MENU::m_icon, ACTION_MENU::m_selected, ACTION_MENU::m_title, ACTION_MENU::m_titleDisplayed, ACTION_MENU::m_tool, and ACTION_MENU::m_toolActions.

Referenced by ACTION_MENU::Clone().

◆ create()

ACTION_MENU* GRID_MENU::create ( ) const
inlineoverrideprivatevirtual

Returns an instance of this class. It has to be overridden in inheriting classes.

Reimplemented from ACTION_MENU.

Definition at line 38 of file grid_menu.h.

39  {
40  return new GRID_MENU( m_parent );
41  }
EDA_DRAW_FRAME * m_parent
Definition: grid_menu.h:46
GRID_MENU(EDA_DRAW_FRAME *aParent)
Definition: grid_menu.cpp:36

References GRID_MENU(), and m_parent.

◆ DisplayTitle()

void ACTION_MENU::DisplayTitle ( bool  aDisplay = true)
inherited

Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.

Definition at line 99 of file action_menu.cpp.

100 {
101  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
102  {
103  // Destroy the menu entry keeping the title..
104  wxMenuItem* item = FindItemByPosition( 0 );
105  wxASSERT( item->GetItemLabelText() == GetTitle() );
106  Destroy( item );
107  // ..and separator
108  item = FindItemByPosition( 0 );
109  wxASSERT( item->IsSeparator() );
110  Destroy( item );
111  m_titleDisplayed = false;
112  }
113 
114  else if( aDisplay && !m_title.IsEmpty() )
115  {
116  if( m_titleDisplayed )
117  {
118  // Simply update the title
119  FindItemByPosition( 0 )->SetItemLabel( m_title );
120  }
121  else
122  {
123  // Add a separator and a menu entry to display the title
124  InsertSeparator( 0 );
125  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
126 
127  if( m_icon )
128  AddBitmapToMenuItem( FindItemByPosition( 0 ), KiBitmap( m_icon ) );
129 
130  m_titleDisplayed = true;
131  }
132  }
133 }
bool m_titleDisplayed
Definition: action_menu.h:215
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:222
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223
wxString m_title
Menu title
Definition: action_menu.h:219

References AddBitmapToMenuItem(), KiBitmap(), ACTION_MENU::m_icon, ACTION_MENU::m_title, and ACTION_MENU::m_titleDisplayed.

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), ACTION_MENU::SetTitle(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

◆ eventHandler()

OPT_TOOL_EVENT GRID_MENU::eventHandler ( const wxMenuEvent &  )
overrideprivatevirtual

Event handler stub.

It should be used if you want to generate a TOOL_EVENT from a wxMenuEvent. It will be called when a menu entry is clicked.

Reimplemented from ACTION_MENU.

Definition at line 56 of file grid_menu.cpp.

57 {
58  OPT_TOOL_EVENT event( ACTIONS::gridPreset.MakeEvent() );
59  intptr_t idx = aEvent.GetId() - ID_POPUP_GRID_SELECT - 1;
60  event->SetParameter( idx );
61 
62  return event;
63 }
static TOOL_ACTION gridPreset
Definition: actions.h:134
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:556

References ACTIONS::gridPreset, and ID_POPUP_GRID_SELECT.

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int  aId)
protectedinherited

Checks if any of submenus contains a TOOL_ACTION with a specific ID.

Definition at line 536 of file action_menu.cpp.

537 {
538  OPT_TOOL_EVENT evt;
539 
540  auto findFunc = [&]( ACTION_MENU* m ) {
541  if( evt )
542  return;
543 
544  const auto it = m->m_toolActions.find( aId );
545 
546  if( it != m->m_toolActions.end() )
547  evt = it->second->MakeEvent();
548  };
549 
550  findFunc( this );
551 
552  if( !evt )
553  runOnSubmenus( findFunc );
554 
555  return evt;
556 }
ACTION_MENU.
Definition: action_menu.h:44
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:556

References ACTION_MENU::runOnSubmenus().

Referenced by ACTION_MENU::OnMenuEvent().

◆ getMenuId()

static int ACTION_MENU::getMenuId ( const TOOL_ACTION aAction)
inlinestaticprotectedinherited

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

Definition at line 162 of file action_menu.h.

163  {
164  return aAction.GetId() + ACTION_ID;
165  }
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: action_menu.h:231
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100

References ACTION_MENU::ACTION_ID, and TOOL_ACTION::GetId().

Referenced by ACTION_MENU::Add().

◆ GetSelected()

int ACTION_MENU::GetSelected ( ) const
inlineinherited

Function GetSelected() Returns the position of selected item.

If the returned value is negative, that means that menu was dismissed.

Returns
The position of selected item in the action menu.

Definition at line 121 of file action_menu.h.

122  {
123  return m_selected;
124  }
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:225

References ACTION_MENU::m_selected.

◆ getToolManager()

TOOL_MANAGER * ACTION_MENU::getToolManager ( ) const
protectedinherited

Returns an instance of TOOL_MANAGER class.

Definition at line 294 of file action_menu.cpp.

295 {
296  wxASSERT( m_tool );
297  return m_tool ? m_tool->GetManager() : nullptr;
298 }
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:228

References TOOL_BASE::GetManager(), and ACTION_MENU::m_tool.

Referenced by ACTION_MENU::OnMenuEvent(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), and ACTION_MENU::updateHotKeys().

◆ HasEnabledItems()

bool ACTION_MENU::HasEnabledItems ( ) const
inherited

Function HasEnabledItems();.

Returns true if the menu has any enabled items

Definition at line 216 of file action_menu.cpp.

217 {
218  bool hasEnabled = false;
219 
220  auto& items = GetMenuItems();
221 
222  for( auto item : items )
223  {
224  if( item->IsEnabled() && !item->IsSeparator() )
225  {
226  hasEnabled = true;
227  break;
228  }
229  }
230 
231  return hasEnabled;
232 }

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent &  event)
inherited

Definition at line 349 of file action_menu.cpp.

350 {
352  g_menu_open_position.x = 0.0;
353  g_menu_open_position.y = 0.0;
354 }
static int g_last_menu_highlighted_id
static VECTOR2D g_menu_open_position

References g_last_menu_highlighted_id, g_menu_open_position, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by ACTION_MENU::setupEvents().

◆ OnMenuEvent()

void ACTION_MENU::OnMenuEvent ( wxMenuEvent &  aEvent)
inherited

Definition at line 357 of file action_menu.cpp.

358 {
359  OPT_TOOL_EVENT evt;
360  wxString menuText;
361  wxEventType type = aEvent.GetEventType();
362  wxWindow* focus = wxWindow::FindFocus();
363 
364  if( type == wxEVT_MENU_OPEN )
365  {
366  if( m_dirty && m_tool )
367  getToolManager()->RunAction( ACTIONS::updateMenu, true, this );
368 
369  wxMenu* parent = dynamic_cast<wxMenu*>( GetParent() );
370 
371  // Don't update the position if this menu has a parent
372  if( !parent && m_tool )
374 
376  }
377  else if( type == wxEVT_MENU_HIGHLIGHT )
378  {
379  if( aEvent.GetId() > 0 )
380  g_last_menu_highlighted_id = aEvent.GetId();
381 
382  evt = TOOL_EVENT( TC_COMMAND, TA_CHOICE_MENU_UPDATE, aEvent.GetId() );
383  }
384  else if( type == wxEVT_COMMAND_MENU_SELECTED )
385  {
386  // Despite our attempts to catch the theft of text editor CHAR_HOOK and CHAR events
387  // in TOOL_DISPATCHER::DispatchWxEvent, wxWidgets sometimes converts those it knows
388  // about into menu commands without ever generating the appropriate CHAR_HOOK and CHAR
389  // events first.
390  if( dynamic_cast<wxTextEntry*>( focus )
391  || dynamic_cast<wxStyledTextCtrl*>( focus )
392  || dynamic_cast<wxListView*>( focus ) )
393  {
394  // Original key event has been lost, so we have to re-create it from the menu's
395  // wxAcceleratorEntry.
396  wxMenuItem* menuItem = FindItem( aEvent.GetId() );
397  wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() : nullptr;
398 
399  if( acceleratorKey )
400  {
401  wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
402  keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
403  keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
404  keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
405  keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
406 
407  if( dynamic_cast<wxStyledTextCtrl*>( focus ) )
408  focus->HandleWindowEvent( keyEvent );
409  else if( dynamic_cast<wxTextEntry*>( focus ) )
410  TEXTENTRY_TRICKS::OnCharHook( dynamic_cast<wxTextEntry*>( focus ), keyEvent );
411 
412  if( keyEvent.GetSkipped() )
413  {
414  keyEvent.SetEventType( wxEVT_CHAR );
415  focus->HandleWindowEvent( keyEvent );
416  }
417  }
418 
419  return;
420  }
421 
422  // Store the selected position, so it can be checked by the tools
423  m_selected = aEvent.GetId();
424 
425  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
426 
427  while( parent )
428  {
429  parent->m_selected = m_selected;
430  parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
431  }
432 
433  // Check if there is a TOOL_ACTION for the given ID
434  if( m_selected >= ACTION_ID )
435  evt = findToolAction( m_selected );
436 
437  if( !evt )
438  {
439 #ifdef __WINDOWS__
440  if( !evt )
441  {
442  // Try to find the submenu which holds the selected item
443  wxMenu* menu = nullptr;
444  FindItem( m_selected, &menu );
445 
446  // This conditional compilation is probably not needed.
447  // It will be removed later, for the Kicad V 6.x version.
448  // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid hang
449  // This hang is no longer encountered in wxWidgets 3.0.4 version, and this condition is no longer needed.
450  // And in 3.1.2, we have to remove it, as "menu != this" never happens
451  // ("menu != this" always happens in 3.1.1 and older!).
452  #if wxCHECK_VERSION(3, 1, 2)
453  if( menu )
454  #else
455  if( menu && menu != this )
456  #endif
457  {
458  ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
459  evt = cxmenu->eventHandler( aEvent );
460  }
461  }
462 #else
463  if( !evt )
464  runEventHandlers( aEvent, evt );
465 #endif
466 
467  // Handling non-action menu entries (e.g. items in clarification list)
468  // in some context menus, that have IDs explicitly chosen between
469  // ID_POPUP_MENU_START and ID_POPUP_MENU_END
470  // Note also items in clarification list have an id >= 0 and < wxID_LOWEST
471  // in fact 0 to n-1 for n items in clarification list)
472  // id < 0 are automatically created for menuitems created with wxID_ANY
473  #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be enough and better */
474 
475  if( !evt &&
476  ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) ||
478  {
479  menuText = GetLabelText( aEvent.GetId() );
481  &menuText );
482  }
483  }
484  }
485 
486  // forward the action/update event to the TOOL_MANAGER
487  // clients that don't supply a tool will have to check GetSelected() themselves
488  if( evt && m_tool )
489  {
490  wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() );
491 
492  // Pass the position the menu was opened from into the generated event if it is a select event
493  if( type == wxEVT_COMMAND_MENU_SELECTED )
494  evt->SetMousePosition( g_menu_open_position );
495  else
496  evt->SetMousePosition( getToolManager()->GetMousePosition() );
497 
498  if( g_last_menu_highlighted_id == aEvent.GetId() && !m_isContextMenu )
499  evt->SetHasPosition( false );
500 
501  if( m_tool->GetManager() )
502  m_tool->GetManager()->ProcessEvent( *evt );
503  }
504  else
505  {
506  aEvent.Skip();
507  }
508 }
OPT_TOOL_EVENT findToolAction(int aId)
Checks if any of submenus contains a TOOL_ACTION with a specific ID.
static int g_last_menu_highlighted_id
ACTION_MENU.
Definition: action_menu.h:44
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Traverses the submenus tree looking for a submenu capable of handling a particular menu event.
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition: action_menu.h:179
#define ID_CONTEXT_MENU_ID_MAX
bool m_isContextMenu
Definition: action_menu.h:216
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
TOOL_EVENT.
Definition: tool_event.h:171
static VECTOR2D g_menu_open_position
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:225
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: action_menu.h:231
static TOOL_ACTION updateMenu
Definition: actions.h:162
All active tools
Definition: tool_event.h:147
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:228
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
VECTOR2D GetMousePosition()
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:556

References ACTION_MENU::ACTION_ID, AS_GLOBAL, ACTION_MENU::eventHandler(), ACTION_MENU::findToolAction(), g_last_menu_highlighted_id, g_menu_open_position, TOOL_BASE::GetManager(), TOOL_MANAGER::GetMousePosition(), ACTION_MENU::getToolManager(), ID_CONTEXT_MENU_ID_MAX, ID_POPUP_MENU_END, ID_POPUP_MENU_START, kicadTraceToolStack, ACTION_MENU::m_dirty, ACTION_MENU::m_isContextMenu, ACTION_MENU::m_selected, ACTION_MENU::m_tool, TEXTENTRY_TRICKS::OnCharHook(), TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), ACTION_MENU::runEventHandlers(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, TC_COMMAND, and ACTIONS::updateMenu.

Referenced by TOOL_DISPATCHER::DispatchWxEvent(), and ACTION_MENU::setupEvents().

◆ runEventHandlers()

void ACTION_MENU::runEventHandlers ( const wxMenuEvent &  aMenuEvent,
OPT_TOOL_EVENT aToolEvent 
)
protectedinherited

Traverses the submenus tree looking for a submenu capable of handling a particular menu event.

In case it is handled, it is returned the aToolEvent parameter.

Definition at line 511 of file action_menu.cpp.

512 {
513  aToolEvent = eventHandler( aMenuEvent );
514 
515  if( !aToolEvent )
516  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
517 }
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Traverses the submenus tree looking for a submenu capable of handling a particular menu event.
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition: action_menu.h:179
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.

References ACTION_MENU::eventHandler(), and ACTION_MENU::runOnSubmenus().

Referenced by ACTION_MENU::OnMenuEvent().

◆ runOnSubmenus()

void ACTION_MENU::runOnSubmenus ( std::function< void(ACTION_MENU *)>  aFunction)
protectedinherited

Runs a function on the menu and all its submenus.

Definition at line 520 of file action_menu.cpp.

521 {
522  try
523  {
524  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
525  aFunction( m );
526  m->runOnSubmenus( aFunction );
527  } );
528  }
529  catch( std::exception& e )
530  {
531  wxLogDebug( wxString::Format( "ACTION_MENU runOnSubmenus exception: %s", e.what() ) );
532  }
533 }
ACTION_MENU.
Definition: action_menu.h:44
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:237
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References Format(), and ACTION_MENU::m_submenus.

Referenced by ACTION_MENU::ClearDirty(), CONDITIONAL_MENU::Evaluate(), ACTION_MENU::findToolAction(), CONDITIONAL_MENU::Resolve(), ACTION_MENU::runEventHandlers(), ACTION_MENU::SetDirty(), ACTION_MENU::SetTool(), and ACTION_MENU::UpdateAll().

◆ SetDirty()

void ACTION_MENU::SetDirty ( )
inherited

Definition at line 260 of file action_menu.cpp.

261 {
262  m_dirty = true;
263  runOnSubmenus( std::bind( &ACTION_MENU::SetDirty, _1 ) );
264 }
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
void SetDirty()

References ACTION_MENU::m_dirty, and ACTION_MENU::runOnSubmenus().

Referenced by TOOL_MENU::ShowContextMenu().

◆ SetIcon()

◆ SetTitle()

void ACTION_MENU::SetTitle ( const wxString &  aTitle)
overrideinherited

Function SetTitle() Sets title for the menu.

The title is shown as a text label shown on the top of the menu.

Parameters
aTitleis the new title.

Definition at line 88 of file action_menu.cpp.

89 {
90  // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version
91  m_title = aTitle;
92 
93  // Update the menu title
94  if( m_titleDisplayed )
95  DisplayTitle( true );
96 }
bool m_titleDisplayed
Definition: action_menu.h:215
wxString m_title
Menu title
Definition: action_menu.h:219
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
Definition: action_menu.cpp:99

References ACTION_MENU::DisplayTitle(), ACTION_MENU::m_title, and ACTION_MENU::m_titleDisplayed.

Referenced by AddMenuLanguageList(), BUS_UNFOLD_MENU::BUS_UNFOLD_MENU(), EDA_3D_VIEWER::CreateMenuBar(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), SPECIAL_TOOLS_CONTEXT_MENU::SPECIAL_TOOLS_CONTEXT_MENU(), SYMBOL_UNIT_MENU::SYMBOL_UNIT_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), TUNER_TOOL_MENU::TUNER_TOOL_MENU(), and ZOOM_MENU::ZOOM_MENU().

◆ SetTool()

void ACTION_MENU::SetTool ( TOOL_INTERACTIVE aTool)
inherited

Function SetTool() Sets a tool that is the creator of the menu.

Parameters
aToolis the tool that created the menu.

Definition at line 267 of file action_menu.cpp.

268 {
269  m_tool = aTool;
270  runOnSubmenus( std::bind( &ACTION_MENU::SetTool, _1, aTool ) );
271 }
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:228
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.

References ACTION_MENU::m_tool, and ACTION_MENU::runOnSubmenus().

Referenced by ALIGN_DISTRIBUTE_TOOL::Init(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), TOOL_INTERACTIVE::SetContextMenu(), CVPCB_MAINFRAME::setupTools(), SCH_LINE_WIRE_BUS_TOOL::UnfoldBus(), and BUS_UNFOLD_MENU::update().

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protectedinherited

Initializes handlers for events.

Definition at line 76 of file action_menu.cpp.

77 {
78 // See wxWidgets hack in TOOL_DISPATCHER::DispatchWxEvent().
79 // Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
80 // Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
81 // Connect( wxEVT_MENU_CLOSE, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
82 
83  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
84  Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), NULL, this );
85 }
#define NULL
void OnMenuEvent(wxMenuEvent &aEvent)
void OnIdle(wxIdleEvent &event)

References NULL, ACTION_MENU::OnIdle(), and ACTION_MENU::OnMenuEvent().

Referenced by ACTION_MENU::ACTION_MENU().

◆ update()

void GRID_MENU::update ( )
overrideprivatevirtual

Update menu state stub.

It is called before a menu is shown, in order to update its state. Here you can tick current settings, enable/disable entries, etc.

Reimplemented from ACTION_MENU.

Definition at line 66 of file grid_menu.cpp.

67 {
68  BASE_SCREEN* screen = m_parent->GetScreen();
69  int currentId = screen->GetGridCmdId();
70  wxArrayString gridsList;
71 
72  screen->BuildGridsChoiceList( gridsList, m_parent->GetUserUnits() != EDA_UNITS::INCHES );
73 
74  for( unsigned int i = 0; i < GetMenuItemCount(); ++i )
75  {
76  GRID_TYPE& grid = screen->GetGrid( i );
77  wxMenuItem* menuItem = FindItemByPosition( i );
78 
79  menuItem->SetId( grid.m_CmdId );
80  menuItem->SetItemLabel( gridsList[ i ] ); // Refresh label in case units have changed
81  menuItem->Check( grid.m_CmdId == currentId ); // Refresh checkmark
82  }
83 }
int BuildGridsChoiceList(wxArrayString &aGridsList, bool aMmFirst) const
Function BuildGridsChoiceList().
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:291
EDA_DRAW_FRAME * m_parent
Definition: grid_menu.h:46
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
GRID_TYPE is for grid arrays.
Definition: base_screen.h:43
int m_CmdId
Definition: base_screen.h:46
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:277
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References BASE_SCREEN::BuildGridsChoiceList(), BASE_SCREEN::GetGrid(), BASE_SCREEN::GetGridCmdId(), EDA_DRAW_FRAME::GetScreen(), EDA_BASE_FRAME::GetUserUnits(), INCHES, GRID_TYPE::m_CmdId, and m_parent.

◆ UpdateAll()

void ACTION_MENU::UpdateAll ( )
inherited

Function UpdateAll() Runs update handlers for the menu and its submenus.

Definition at line 235 of file action_menu.cpp.

236 {
237  try
238  {
239  update();
240  }
241  catch( std::exception& e )
242  {
243  wxLogDebug( wxString::Format( "ACTION_MENU update handler exception: %s", e.what() ) );
244  }
245 
246  if( m_tool )
247  updateHotKeys();
248 
249  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
250 }
virtual void update()
Update menu state stub.
Definition: action_menu.h:171
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:228
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void updateHotKeys()
Updates hot key settings for TOOL_ACTIONs in this menu.

References Format(), ACTION_MENU::m_tool, ACTION_MENU::runOnSubmenus(), ACTION_MENU::update(), and ACTION_MENU::updateHotKeys().

Referenced by CONDITIONAL_MENU::Resolve(), TOOL_MENU::ShowContextMenu(), KICAD_MANAGER_CONTROL::UpdateMenu(), EDA_3D_CONTROLLER::UpdateMenu(), GERBVIEW_SELECTION_TOOL::UpdateMenu(), PL_SELECTION_TOOL::UpdateMenu(), EE_SELECTION_TOOL::UpdateMenu(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu(), CVPCB_CONTROL::UpdateMenu(), and SELECTION_TOOL::UpdateMenu().

◆ updateHotKeys()

void ACTION_MENU::updateHotKeys ( )
protectedinherited

Updates hot key settings for TOOL_ACTIONs in this menu.

Definition at line 301 of file action_menu.cpp.

302 {
303  TOOL_MANAGER* toolMgr = getToolManager();
304 
305  for( auto& ii : m_toolActions )
306  {
307  int id = ii.first;
308  const TOOL_ACTION& action = *ii.second;
309  int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
310 
311  if( key )
312  {
313  int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
314  int flags = 0;
315  wxMenuItem* item = FindChildItem( id );
316 
317  if( item )
318  {
319  flags |= ( mod & MD_ALT ) ? wxACCEL_ALT : 0;
320  flags |= ( mod & MD_CTRL ) ? wxACCEL_CTRL : 0;
321  flags |= ( mod & MD_SHIFT ) ? wxACCEL_SHIFT : 0;
322 
323  if( !flags )
324  flags = wxACCEL_NORMAL;
325 
326  wxAcceleratorEntry accel( flags, key, id, item );
327  item->SetAccel( &accel );
328  }
329  }
330  }
331 }
int GetHotKey(const TOOL_ACTION &aAction)
TOOL_MANAGER.
Definition: tool_manager.h:50
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:234
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
TOOL_ACTION.
Definition: tool_action.h:46

References TOOL_MANAGER::GetHotKey(), ACTION_MENU::getToolManager(), ACTION_MENU::m_toolActions, MD_ALT, MD_CTRL, MD_MODIFIER_MASK, and MD_SHIFT.

Referenced by ACTION_MENU::UpdateAll().

Member Data Documentation

◆ ACTION_ID

const int ACTION_MENU::ACTION_ID = 20000
staticprotectedinherited

Menu items with ID higher than that are considered TOOL_ACTIONs

Definition at line 231 of file action_menu.h.

Referenced by ACTION_MENU::getMenuId(), and ACTION_MENU::OnMenuEvent().

◆ m_dirty

bool ACTION_MENU::m_dirty
protectedinherited

◆ m_icon

const BITMAP_OPAQUE* ACTION_MENU::m_icon
protectedinherited

Optional icon

Definition at line 222 of file action_menu.h.

Referenced by ACTION_MENU::Add(), ACTION_MENU::copyFrom(), ACTION_MENU::DisplayTitle(), and ACTION_MENU::SetIcon().

◆ m_isContextMenu

bool ACTION_MENU::m_isContextMenu
protectedinherited

◆ m_parent

EDA_DRAW_FRAME* GRID_MENU::m_parent
private

Definition at line 46 of file grid_menu.h.

Referenced by create(), GRID_MENU(), and update().

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Stores the id number of selected item.

Definition at line 225 of file action_menu.h.

Referenced by ACTION_MENU::copyFrom(), ACTION_MENU::GetSelected(), and ACTION_MENU::OnMenuEvent().

◆ m_submenus

std::list<ACTION_MENU*> ACTION_MENU::m_submenus
protectedinherited

◆ m_title

wxString ACTION_MENU::m_title
protectedinherited

◆ m_titleDisplayed

bool ACTION_MENU::m_titleDisplayed
protectedinherited

◆ m_tool

◆ m_toolActions

std::map<int, const TOOL_ACTION*> ACTION_MENU::m_toolActions
protectedinherited

Associates tool actions with menu item IDs. Non-owning.

Definition at line 234 of file action_menu.h.

Referenced by ACTION_MENU::Add(), ACTION_MENU::Clear(), ACTION_MENU::copyFrom(), and ACTION_MENU::updateHotKeys().


The documentation for this class was generated from the following files: