KiCad PCB EDA Suite
SELECT_MENU Class Reference
Inheritance diagram for SELECT_MENU:
ACTION_MENU

Public Member Functions

 SELECT_MENU ()
 
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...
 
virtual OPT_TOOL_EVENT eventHandler (const wxMenuEvent &)
 Event handler stub. 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_isForcedPosition
 
wxPoint m_forcedPosition
 
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

void update () override
 Update menu state stub. More...
 
ACTION_MENUcreate () const override
 

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

More...
 

Detailed Description

Definition at line 61 of file selection_tool.cpp.

Constructor & Destructor Documentation

◆ SELECT_MENU()

SELECT_MENU::SELECT_MENU ( )
inline

Definition at line 64 of file selection_tool.cpp.

64  :
65  ACTION_MENU( true )
66  {
67  SetTitle( _( "Select" ) );
69 
71 
72  AppendSeparator();
73 
77  }
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
const BITMAP_OPAQUE options_generic_xpm[1]
static TOOL_ACTION selectNet
Selects all connections belonging to a single net.
Definition: pcb_actions.h:80
static TOOL_ACTION selectConnection
Selects tracks between junctions or expands an existing selection to pads or the entire connection.
Definition: pcb_actions.h:77
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
static TOOL_ACTION filterSelection
Filters the items in the current selection (invokes dialog)
Definition: pcb_actions.h:89
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
#define _(s)
Definition: 3d_actions.cpp:33
ACTION_MENU(bool isContextMenu)
Default constructor
Definition: action_menu.cpp:45
static TOOL_ACTION selectSameSheet
Selects all components on the same sheet as the selected footprint.
Definition: pcb_actions.h:86

References _, PCB_ACTIONS::filterSelection, options_generic_xpm, PCB_ACTIONS::selectConnection, PCB_ACTIONS::selectNet, and PCB_ACTIONS::selectSameSheet.

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:205

References AddBitmapToMenuItem(), and KiBitmap().

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), CONDITIONAL_MENU::Evaluate(), ALIGN_DISTRIBUTE_TOOL::Init(), NET_CONTEXT_MENU::NET_CONTEXT_MENU(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_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:205

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:205
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:237
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:225
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:205
wxString m_title
Menu title
Definition: action_menu.h:222
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:240
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 582 of file action_menu.cpp.

583 {
584  wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
585  aSource->GetHelp(), aSource->GetKind() );
586 
587  // Add the source bitmap if it is not the wxNullBitmap
588  // On Windows, for Checkable Menu items, adding a null bitmap adds also
589  // our predefined checked alternate bitmap
590  const wxBitmap& src_bitmap = aSource->GetBitmap();
591 
592  if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size
593  AddBitmapToMenuItem( newItem, src_bitmap );
594 
595  if( aSource->IsSubMenu() )
596  {
597  ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
598  wxASSERT_MSG( menu, "Submenus are expected to be a ACTION_MENU" );
599 
600  if( menu )
601  {
602  ACTION_MENU* menuCopy = menu->Clone();
603  newItem->SetSubMenu( menuCopy );
604  m_submenus.push_back( menuCopy );
605  }
606  }
607 
608  // wxMenuItem has to be added before enabling/disabling or checking
609  Append( newItem );
610 
611  if( aSource->IsCheckable() )
612  newItem->Check( aSource->IsChecked() );
613 
614  newItem->Enable( aSource->IsEnabled() );
615 
616  return newItem;
617 }
ACTION_MENU.
Definition: action_menu.h:44
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:240
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:218
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:240
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:237

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 564 of file action_menu.cpp.

565 {
566  m_icon = aMenu.m_icon;
567  m_title = aMenu.m_title;
569  m_selected = -1; // aMenu.m_selected;
570  m_tool = aMenu.m_tool;
572 
573  // Copy all menu entries
574  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
575  {
576  wxMenuItem* item = aMenu.FindItemByPosition( i );
577  appendCopy( item );
578  }
579 }
bool m_titleDisplayed
Definition: action_menu.h:218
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:225
wxString m_title
Menu title
Definition: action_menu.h:222
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:228
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:231
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:237

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* SELECT_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 95 of file selection_tool.cpp.

96  {
97  return new SELECT_MENU();
98  }

◆ 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:218
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:225
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:205
wxString m_title
Menu title
Definition: action_menu.h:222

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(), ACTION_MENU::SetTitle(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

◆ eventHandler()

virtual OPT_TOOL_EVENT ACTION_MENU::eventHandler ( const wxMenuEvent &  )
inlineprotectedvirtualinherited

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 in DIFF_PAIR_MENU, TRACK_WIDTH_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 179 of file action_menu.h.

180  {
181  return OPT_TOOL_EVENT();
182  }
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:556

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

◆ 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 541 of file action_menu.cpp.

542 {
543  OPT_TOOL_EVENT evt;
544 
545  auto findFunc = [&]( ACTION_MENU* m ) {
546  if( evt )
547  return;
548 
549  const auto it = m->m_toolActions.find( aId );
550 
551  if( it != m->m_toolActions.end() )
552  evt = it->second->MakeEvent();
553  };
554 
555  findFunc( this );
556 
557  if( !evt )
558  runOnSubmenus( findFunc );
559 
560  return evt;
561 }
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:234
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(), and NET_CONTEXT_MENU::update().

◆ 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:228

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:231

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

Referenced by ACTION_MENU::OnMenuEvent(), NET_CONTEXT_MENU::update(), 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( auto ctrl = dynamic_cast<wxTextEntry*>( focus ) )
408  TEXTENTRY_TRICKS::OnCharHook( ctrl, keyEvent );
409  else
410  focus->HandleWindowEvent( keyEvent );
411 
412  if( keyEvent.GetSkipped() )
413  {
414  keyEvent.SetEventType( wxEVT_CHAR );
415  focus->HandleWindowEvent( keyEvent );
416  }
417 
418  // If the event was used as KEY event (not skipped) by the focused window,
419  // just finish.
420  // Otherwise this is actually a wxEVT_COMMAND_MENU_SELECTED, or the
421  // focused window is read only
422  if( !keyEvent.GetSkipped() )
423  return;
424  }
425  }
426 
427  // Store the selected position, so it can be checked by the tools
428  m_selected = aEvent.GetId();
429 
430  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
431 
432  while( parent )
433  {
434  parent->m_selected = m_selected;
435  parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
436  }
437 
438  // Check if there is a TOOL_ACTION for the given ID
439  if( m_selected >= ACTION_ID )
440  evt = findToolAction( m_selected );
441 
442  if( !evt )
443  {
444 #ifdef __WINDOWS__
445  if( !evt )
446  {
447  // Try to find the submenu which holds the selected item
448  wxMenu* menu = nullptr;
449  FindItem( m_selected, &menu );
450 
451  // This conditional compilation is probably not needed.
452  // It will be removed later, for the Kicad V 6.x version.
453  // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid hang
454  // This hang is no longer encountered in wxWidgets 3.0.4 version, and this condition is no longer needed.
455  // And in 3.1.2, we have to remove it, as "menu != this" never happens
456  // ("menu != this" always happens in 3.1.1 and older!).
457  #if wxCHECK_VERSION(3, 1, 2)
458  if( menu )
459  #else
460  if( menu && menu != this )
461  #endif
462  {
463  ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
464  evt = cxmenu->eventHandler( aEvent );
465  }
466  }
467 #else
468  if( !evt )
469  runEventHandlers( aEvent, evt );
470 #endif
471 
472  // Handling non-action menu entries (e.g. items in clarification list)
473  // in some context menus, that have IDs explicitly chosen between
474  // ID_POPUP_MENU_START and ID_POPUP_MENU_END
475  // Note also items in clarification list have an id >= 0 and < wxID_LOWEST
476  // in fact 0 to n-1 for n items in clarification list)
477  // id < 0 are automatically created for menuitems created with wxID_ANY
478  #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be enough and better */
479 
480  if( !evt &&
481  ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) ||
483  {
484  menuText = GetLabelText( aEvent.GetId() );
486  &menuText );
487  }
488  }
489  }
490 
491  // forward the action/update event to the TOOL_MANAGER
492  // clients that don't supply a tool will have to check GetSelected() themselves
493  if( evt && m_tool )
494  {
495  wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() );
496 
497  // Pass the position the menu was opened from into the generated event if it is a select event
498  if( type == wxEVT_COMMAND_MENU_SELECTED )
499  evt->SetMousePosition( g_menu_open_position );
500  else
501  evt->SetMousePosition( getToolManager()->GetMousePosition() );
502 
503  if( g_last_menu_highlighted_id == aEvent.GetId() && !m_isContextMenu )
504  evt->SetHasPosition( false );
505 
506  if( m_tool->GetManager() )
507  m_tool->GetManager()->ProcessEvent( *evt );
508  }
509  else
510  {
511  aEvent.Skip();
512  }
513 }
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:140
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:219
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:228
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: action_menu.h:234
static TOOL_ACTION updateMenu
Definition: actions.h:163
All active tools
Definition: tool_event.h:147
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:231
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 516 of file action_menu.cpp.

517 {
518  aToolEvent = eventHandler( aMenuEvent );
519 
520  if( !aToolEvent )
521  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
522 }
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 525 of file action_menu.cpp.

526 {
527  try
528  {
529  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
530  aFunction( m );
531  m->runOnSubmenus( aFunction );
532  } );
533  }
534  catch( std::exception& e )
535  {
536  wxLogDebug( wxString::Format( "ACTION_MENU runOnSubmenus exception: %s", e.what() ) );
537  }
538 }
ACTION_MENU.
Definition: action_menu.h:44
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:240
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:218
wxString m_title
Menu title
Definition: action_menu.h:222
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(), GRID_MENU::GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), NET_CONTEXT_MENU::NET_CONTEXT_MENU(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_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:231
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(), SCH_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_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 SELECT_MENU::update ( )
inlineoverrideprivatevirtual

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 81 of file selection_tool.cpp.

82  {
83  using S_C = SELECTION_CONDITIONS;
84 
85  const auto& selection = getToolManager()->GetTool<SELECTION_TOOL>()->GetSelection();
86 
87  bool connItem = S_C::OnlyTypes( GENERAL_COLLECTOR::Tracks )( selection );
88  bool sheetSelEnabled = ( S_C::OnlyType( PCB_MODULE_T ) )( selection );
89 
90  Enable( getMenuId( PCB_ACTIONS::selectNet ), connItem );
91  Enable( getMenuId( PCB_ACTIONS::selectConnection ), connItem );
92  Enable( getMenuId( PCB_ACTIONS::selectSameSheet ), sheetSelEnabled );
93  }
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:313
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: action_menu.h:162
SELECTION_TOOL.
static TOOL_ACTION selectNet
Selects all connections belonging to a single net.
Definition: pcb_actions.h:80
static TOOL_ACTION selectConnection
Selects tracks between junctions or expands an existing selection to pads or the entire connection.
Definition: pcb_actions.h:77
Class that groups generic conditions for selected items.
class MODULE, a footprint
Definition: typeinfo.h:89
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
static TOOL_ACTION selectSameSheet
Selects all components on the same sheet as the selected footprint.
Definition: pcb_actions.h:86

References PCB_MODULE_T, PCB_ACTIONS::selectConnection, PCB_ACTIONS::selectNet, PCB_ACTIONS::selectSameSheet, and GENERAL_COLLECTOR::Tracks.

◆ 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:231
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 ACTION_TOOLBAR::onToolRightClick(), 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:51
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:237
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 234 of file action_menu.h.

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

◆ m_dirty

bool ACTION_MENU::m_dirty
protectedinherited

◆ m_forcedPosition

wxPoint ACTION_MENU::m_forcedPosition
protectedinherited

Definition at line 214 of file action_menu.h.

◆ m_icon

const BITMAP_OPAQUE* ACTION_MENU::m_icon
protectedinherited

Optional icon

Definition at line 225 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_isForcedPosition

bool ACTION_MENU::m_isForcedPosition
protectedinherited

Definition at line 213 of file action_menu.h.

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Stores the id number of selected item.

Definition at line 228 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 237 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 file: