KiCad PCB EDA Suite
CONDITIONAL_MENU Class Reference

#include <conditional_menu.h>

Inheritance diagram for CONDITIONAL_MENU:
ACTION_MENU

Classes

class  ENTRY
 

Helper class to organize menu entries.

More...
 

Public Member Functions

 CONDITIONAL_MENU (bool isContextMenu, TOOL_INTERACTIVE *aTool)
 
ACTION_MENUcreate () const override
 

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

More...
 
void AddItem (const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
 Function AddItem() More...
 
void AddItem (int aId, const wxString &aText, const wxString &aTooltip, BITMAP_DEF aIcon, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
 
void AddCheckItem (const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
 Function AddCheckItem() More...
 
void AddCheckItem (int aId, const wxString &aText, const wxString &aTooltip, BITMAP_DEF aIcon, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
 
void AddMenu (ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
 Function AddMenu() More...
 
void AddSeparator (int aOrder=ANY_ORDER)
 Function AddSeparator() More...
 
void AddClose (wxString aAppname="")
 Function AddClose() More...
 
void AddQuitOrClose (KIFACE_I *aKiface, wxString aAppname="")
 Functions AddQuitOrClose() More...
 
void Evaluate (SELECTION &aSelection)
 Function Evaluate() More...
 
void Resolve ()
 Function Resolve() More...
 
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)
 

Static Public Attributes

static const int ANY_ORDER = -1
 

Constant to indicate that we do not care about an ENTRY location in the menu.

More...
 

Protected Member Functions

TOOL_MANAGERgetToolManager () const
 

Returns an instance of TOOL_MANAGER class.

More...
 
virtual void update ()
 Update menu state stub. 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_dirty
 
bool m_titleDisplayed
 
bool m_isContextMenu
 
wxString m_title
 

Menu title

More...
 
const BITMAP_OPAQUE * m_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 addEntry (ENTRY aEntry)
 

Inserts the entry, preserving the requested order.

More...
 

Private Attributes

std::list< ENTRYm_entries
 

List of all menu entries.

More...
 

Detailed Description

Definition at line 39 of file conditional_menu.h.

Constructor & Destructor Documentation

◆ CONDITIONAL_MENU()

CONDITIONAL_MENU::CONDITIONAL_MENU ( bool  isContextMenu,
TOOL_INTERACTIVE aTool 
)

Definition at line 32 of file conditional_menu.cpp.

32  :
33  ACTION_MENU( isContextMenu )
34 {
35  m_tool = aTool;
36 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:227
ACTION_MENU(bool isContextMenu)
Default constructor
Definition: action_menu.cpp:43

References ACTION_MENU::m_tool.

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

135 {
136  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
137 
138  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
139 
140  if( aIcon )
141  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
142 
143  return Append( item );
144 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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(), 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(), 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 147 of file action_menu.cpp.

149 {
150  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
151 
152  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, aTooltip, wxITEM_NORMAL );
153 
154  if( aIcon )
155  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
156 
157  return Append( item );
158 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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 161 of file action_menu.cpp.

162 {
164  const BITMAP_OPAQUE* icon = aAction.GetIcon();
165 
166  wxMenuItem* item = new wxMenuItem( this, getMenuId( aAction ), aAction.GetMenuItem(),
167  aAction.GetDescription(),
168  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
169 
170  if( icon )
171  AddBitmapToMenuItem( item, KiBitmap( icon ) );
172 
173  m_toolActions[getMenuId( aAction )] = &aAction;
174 
175  return Append( item );
176 }
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: action_menu.h:161
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:79
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:233
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 179 of file action_menu.cpp.

180 {
181  ACTION_MENU* menuCopy = aMenu->Clone();
182  m_submenus.push_back( menuCopy );
183 
184  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
185 
186  if( aMenu->m_icon )
187  {
188  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
189  AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) );
190  newItem->SetSubMenu( menuCopy );
191  return Append( newItem );
192  }
193  else
194  {
195  return AppendSubMenu( menuCopy, menuCopy->m_title );
196  }
197 }
Class ACTION_MENU.
Definition: action_menu.h:43
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:221
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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:218
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:236
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.

◆ AddCheckItem() [1/2]

void CONDITIONAL_MENU::AddCheckItem ( const TOOL_ACTION aAction,
const SELECTION_CONDITION aCondition,
int  aOrder = ANY_ORDER 
)

Function AddCheckItem()

Adds a checked menu entry to run a TOOL_ACTION on selected items.

Parameters
aActionis a menu entry to be added.
aConditionis a condition that has to be fulfilled to check the menu entry.
aOrderdetermines location of the added item, higher numbers are put on the bottom. You may use ANY_ORDER here if you think it does not matter.

Definition at line 55 of file conditional_menu.cpp.

57 {
58  wxASSERT( aAction.GetId() > 0 ); // Check if action was previously registered in ACTION_MANAGER
59  addEntry( ENTRY( &aAction, aCondition, aOrder, true ) );
60 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
void addEntry(ENTRY aEntry)
Inserts the entry, preserving the requested order.

References addEntry(), and TOOL_ACTION::GetId().

Referenced by AddMenuLanguageList(), EDA_3D_VIEWER::CreateMenuBar(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateMenuBar().

◆ AddCheckItem() [2/2]

void CONDITIONAL_MENU::AddCheckItem ( int  aId,
const wxString &  aText,
const wxString &  aTooltip,
BITMAP_DEF  aIcon,
const SELECTION_CONDITION aCondition,
int  aOrder = ANY_ORDER 
)

Definition at line 76 of file conditional_menu.cpp.

79 {
80  wxMenuItem* item = new wxMenuItem( nullptr, aId, aText, aTooltip, wxITEM_CHECK );
81 
82  if( aIcon )
83  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
84 
85  addEntry( ENTRY( item, aIcon, aCondition, aOrder, true ) );
86 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223
void addEntry(ENTRY aEntry)
Inserts the entry, preserving the requested order.

References AddBitmapToMenuItem(), addEntry(), and KiBitmap().

◆ AddClose()

void CONDITIONAL_MENU::AddClose ( wxString  aAppname = "")

Function AddClose()

Add a standard close item to the menu with the accelerator key CTRL-W. Emits the wxID_CLOSE event.

Parameters
aAppnameis the application name to append to the tooltip

Definition at line 102 of file conditional_menu.cpp.

103 {
104  AddItem( wxID_CLOSE, _( "Close\tCTRL+W" ), wxString::Format( "Close %s", aAppname ), exit_xpm,
106 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
#define _(s)
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 AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()

References _, AddItem(), Format(), and SELECTION_CONDITIONS::ShowAlways().

Referenced by AddQuitOrClose(), EDA_3D_VIEWER::CreateMenuBar(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), and CVPCB_MAINFRAME::ReCreateMenuBar().

◆ addEntry()

void CONDITIONAL_MENU::addEntry ( ENTRY  aEntry)
private

Inserts the entry, preserving the requested order.

Definition at line 239 of file conditional_menu.cpp.

240 {
241  if( aEntry.Order() < 0 ) // Any order, so give it any order number
242  aEntry.SetOrder( m_entries.size() );
243 
244  std::list<ENTRY>::iterator it = m_entries.begin();
245 
246  // Find the right spot for the entry
247  while( it != m_entries.end() && it->Order() <= aEntry.Order() )
248  ++it;
249 
250  m_entries.insert( it, aEntry );
251 }
std::list< ENTRY > m_entries
List of all menu entries.

References m_entries, CONDITIONAL_MENU::ENTRY::Order(), and CONDITIONAL_MENU::ENTRY::SetOrder().

Referenced by AddCheckItem(), AddItem(), AddMenu(), and AddSeparator().

◆ AddItem() [1/2]

void CONDITIONAL_MENU::AddItem ( const TOOL_ACTION aAction,
const SELECTION_CONDITION aCondition,
int  aOrder = ANY_ORDER 
)

Function AddItem()

Adds a menu entry to run a TOOL_ACTION on selected items.

Parameters
aActionis a menu entry to be added.
aConditionis a condition that has to be fulfilled to enable the menu entry.
aOrderdetermines location of the added item, higher numbers are put on the bottom. You may use ANY_ORDER here if you think it does not matter.

Definition at line 47 of file conditional_menu.cpp.

49 {
50  wxASSERT( aAction.GetId() > 0 ); // Check if action was previously registered in ACTION_MANAGER
51  addEntry( ENTRY( &aAction, aCondition, aOrder, false ) );
52 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
void addEntry(ENTRY aEntry)
Inserts the entry, preserving the requested order.

References addEntry(), and TOOL_ACTION::GetId().

Referenced by AddClose(), AddQuitOrClose(), EDA_3D_VIEWER::CreateMenuBar(), LIB_EDIT_TOOL::Init(), PICKER_TOOL::Init(), LIB_MOVE_TOOL::Init(), LIB_PIN_TOOL::Init(), SCH_MOVE_TOOL::Init(), PL_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), LIB_DRAWING_TOOLS::Init(), PAD_TOOL::Init(), MODULE_EDITOR_TOOLS::Init(), LIB_CONTROL::Init(), EE_POINT_EDITOR::Init(), POINT_EDITOR::Init(), PCB_EDITOR_CONTROL::Init(), SCH_DRAWING_TOOLS::Init(), DRAWING_TOOL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), EDIT_TOOL::Init(), PCB_TOOL_BASE::Init(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateMenuBar().

◆ AddItem() [2/2]

void CONDITIONAL_MENU::AddItem ( int  aId,
const wxString &  aText,
const wxString &  aTooltip,
BITMAP_DEF  aIcon,
const SELECTION_CONDITION aCondition,
int  aOrder = ANY_ORDER 
)

Definition at line 63 of file conditional_menu.cpp.

66 {
67  wxMenuItem* item = new wxMenuItem( nullptr, aId, aText, aTooltip, wxITEM_NORMAL );
68 
69  if( aIcon )
70  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
71 
72  addEntry( ENTRY( item, aIcon, aCondition, aOrder, false ) );
73 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223
void addEntry(ENTRY aEntry)
Inserts the entry, preserving the requested order.

References AddBitmapToMenuItem(), addEntry(), and KiBitmap().

◆ AddMenu()

void CONDITIONAL_MENU::AddMenu ( ACTION_MENU aMenu,
const SELECTION_CONDITION aCondition = SELECTION_CONDITIONS::ShowAlways,
int  aOrder = ANY_ORDER 
)

Function AddMenu()

Adds a submenu to the menu. CONDITIONAL_MENU takes ownership of the added menu, so it will be freed when the CONDITIONAL_MENU object is destroyed.

Parameters
aMenuis the submenu to be added.
aExpanddetermines if the added submenu items should be added as individual items or as a submenu.
aConditionis a condition that has to be fulfilled to enable the submenu entry.
aOrderdetermines location of the added menu, higher numbers are put on the bottom. You may use ANY_ORDER here if you think it does not matter.

Definition at line 89 of file conditional_menu.cpp.

91 {
92  addEntry( ENTRY( aMenu, aCondition, aOrder ) );
93 }
void addEntry(ENTRY aEntry)
Inserts the entry, preserving the requested order.

References addEntry().

Referenced by AddMenuLanguageList(), EDA_3D_VIEWER::CreateMenuBar(), SCH_EDIT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), GERBVIEW_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), SELECTION_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(), and PCB_EDIT_FRAME::ReCreateMenuBar().

◆ AddQuitOrClose()

void CONDITIONAL_MENU::AddQuitOrClose ( KIFACE_I aKiface,
wxString  aAppname = "" 
)

Functions AddQuitOrClose()

Adds either a standard Quit or Close item to the menu. If aKiface is NULL or in single-instance then Quite (wxID_QUIT) is used, otherwise Close (wxID_CLOSE) is used.

Parameters
aAppnameis the application name to append to the tooltip

Definition at line 109 of file conditional_menu.cpp.

110 {
111  if( !aKiface || aKiface->IsSingle() ) // not when under a project mgr
112  {
113  // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via
114  // wxID_EXIT
115  AddItem( wxID_EXIT, _( "Quit" ), wxString::Format( "Quit %s", aAppname ), exit_xpm,
117  }
118  else
119  {
120  AddClose( aAppname );
121  }
122 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
bool IsSingle() const
Function IsSingle is this KIFACE_I running under single_top?
Definition: kiface_i.h:115
#define _(s)
void AddClose(wxString aAppname="")
Function AddClose()
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 AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()

References _, AddClose(), AddItem(), Format(), KIFACE_I::IsSingle(), and SELECTION_CONDITIONS::ShowAlways().

Referenced by KICAD_MANAGER_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateMenuBar().

◆ AddSeparator()

void CONDITIONAL_MENU::AddSeparator ( int  aOrder = ANY_ORDER)

◆ appendCopy()

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

Function appendCopy Appends a copy of wxMenuItem.

Definition at line 533 of file action_menu.cpp.

534 {
535  wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
536  aSource->GetHelp(), aSource->GetKind() );
537 
538  // Add the source bitmap if it is not the wxNullBitmap
539  // On Windows, for Checkable Menu items, adding a null bitmap adds also
540  // our predefined checked alternate bitmap
541  const wxBitmap& src_bitmap = aSource->GetBitmap();
542 
543  if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size
544  AddBitmapToMenuItem( newItem, src_bitmap );
545 
546  if( aSource->IsSubMenu() )
547  {
548  ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
549  wxASSERT_MSG( menu, "Submenus are expected to be a ACTION_MENU" );
550 
551  if( menu )
552  {
553  ACTION_MENU* menuCopy = menu->Clone();
554  newItem->SetSubMenu( menuCopy );
555  m_submenus.push_back( menuCopy );
556  }
557  }
558 
559  // wxMenuItem has to be added before enabling/disabling or checking
560  Append( newItem );
561 
562  if( aSource->IsCheckable() )
563  newItem->Check( aSource->IsChecked() );
564 
565  newItem->Enable( aSource->IsEnabled() );
566 
567  return newItem;
568 }
Class ACTION_MENU.
Definition: action_menu.h:43
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:236
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 200 of file action_menu.cpp.

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

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

Referenced by ACTION_MENU::Clone(), Evaluate(), BUS_UNFOLD_MENU::update(), SYMBOL_UNIT_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 251 of file action_menu.cpp.

252 {
253  m_dirty = false;
254  runOnSubmenus( std::bind( &ACTION_MENU::ClearDirty, _1 ) );
255 }
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 272 of file action_menu.cpp.

273 {
274  ACTION_MENU* clone = create();
275  clone->Clear();
276  clone->copyFrom( *this );
277  return clone;
278 }
Class ACTION_MENU.
Definition: action_menu.h:43
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 515 of file action_menu.cpp.

516 {
517  m_icon = aMenu.m_icon;
518  m_title = aMenu.m_title;
520  m_selected = -1; // aMenu.m_selected;
521  m_tool = aMenu.m_tool;
523 
524  // Copy all menu entries
525  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
526  {
527  wxMenuItem* item = aMenu.FindItemByPosition( i );
528  appendCopy( item );
529  }
530 }
bool m_titleDisplayed
Definition: action_menu.h:214
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:221
wxString m_title
Menu title
Definition: action_menu.h:218
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:224
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:227
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:233
size_t i
Definition: json11.cpp:597

References ACTION_MENU::appendCopy(), i, 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 * CONDITIONAL_MENU::create ( ) const
overridevirtual

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

Reimplemented from ACTION_MENU.

Definition at line 39 of file conditional_menu.cpp.

40 {
42  clone->m_entries = m_entries;
43  return clone;
44 }
std::list< ENTRY > m_entries
List of all menu entries.
CONDITIONAL_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool)
bool m_isContextMenu
Definition: action_menu.h:215
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:227

References CONDITIONAL_MENU(), m_entries, ACTION_MENU::m_isContextMenu, and ACTION_MENU::m_tool.

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

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

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().

◆ Evaluate()

void CONDITIONAL_MENU::Evaluate ( SELECTION aSelection)

Function Evaluate()

Updates the contents of the menu based on the supplied conditions.

Definition at line 142 of file conditional_menu.cpp.

143 {
144  Clear();
145 
146  // We try to avoid adding useless separators (when no menuitems between separators)
147  int menu_count = 0; // number of menus since the latest separator
148 
149  for( const ENTRY& entry : m_entries )
150  {
151  const SELECTION_CONDITION& cond = entry.Condition();
152  bool result;
153  wxMenuItem* menuItem = nullptr;
154 
155  try
156  {
157  result = cond( aSelection );
158  }
159  catch( std::exception& )
160  {
161  continue;
162  }
163 
164  if( m_isContextMenu && !result )
165  continue;
166 
167  switch( entry.Type() )
168  {
169  case ENTRY::ACTION:
170  menuItem = Add( *entry.Action(), entry.IsCheckmarkEntry() );
171  menu_count++;
172  break;
173 
174  case ENTRY::MENU:
175  menuItem = Add( entry.Menu() );
176  menu_count++;
177  break;
178 
179  case ENTRY::WXITEM:
180 #ifdef __WXMAC__
181  // Instantiate the Preferences item only on the first Resolve(); after that
182  // wxWidgets will have moved it to the Application menu
183  if( entry.wxItem()->GetId() == wxID_PREFERENCES )
184  {
185  if( &aSelection != &g_resolveDummySelection )
186  continue;
187  }
188 #endif
189  menuItem = new wxMenuItem( this,
190  entry.wxItem()->GetId(),
191  entry.wxItem()->GetItemLabel(),
192  entry.wxItem()->GetHelp(),
193  entry.wxItem()->GetKind() );
194 
195  if( entry.GetIcon() )
196  AddBitmapToMenuItem( menuItem, KiBitmap( entry.GetIcon() ) );
197 
198  // the wxMenuItem must be append only after the bitmap is set:
199  Append( menuItem );
200 
201  menu_count++;
202  break;
203 
204  case ENTRY::SEPARATOR:
205  if( menu_count )
206  menuItem = AppendSeparator();
207 
208  menu_count = 0;
209  break;
210 
211  default:
212  wxASSERT( false );
213  break;
214  }
215 
216  if( menuItem )
217  {
218  if( entry.IsCheckmarkEntry() )
219  menuItem->Check( result );
220  else
221  menuItem->Enable( result );
222  }
223  }
224 
225  // Recursively call Evaluate on all the submenus that are CONDITIONAL_MENUs to ensure
226  // they are updated. This is also required on GTK to make sure the menus have the proper
227  // size when created.
229  [&aSelection]( ACTION_MENU* aMenu )
230  {
231  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( aMenu );
232 
233  if( conditionalMenu )
234  conditionalMenu->Evaluate( aSelection );
235  } );
236 }
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
Class ACTION_MENU.
Definition: action_menu.h:43
SELECTION g_resolveDummySelection
std::list< ENTRY > m_entries
List of all menu entries.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:223
bool m_isContextMenu
Definition: action_menu.h:215
void Evaluate(SELECTION &aSelection)
Function Evaluate()
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
void Clear()
Function Clear() Removes all the entries from the menu (as well as its title).

References CONDITIONAL_MENU::ENTRY::ACTION, ACTION_MENU::Add(), AddBitmapToMenuItem(), ACTION_MENU::Clear(), Evaluate(), g_resolveDummySelection, KiBitmap(), m_entries, ACTION_MENU::m_isContextMenu, CONDITIONAL_MENU::ENTRY::MENU, ACTION_MENU::runOnSubmenus(), CONDITIONAL_MENU::ENTRY::SEPARATOR, and CONDITIONAL_MENU::ENTRY::WXITEM.

Referenced by Evaluate(), Resolve(), and TOOL_MENU::ShowContextMenu().

◆ 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 178 of file action_menu.h.

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

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

493 {
494  OPT_TOOL_EVENT evt;
495 
496  auto findFunc = [&]( ACTION_MENU* m ) {
497  if( evt )
498  return;
499 
500  const auto it = m->m_toolActions.find( aId );
501 
502  if( it != m->m_toolActions.end() )
503  evt = it->second->MakeEvent();
504  };
505 
506  findFunc( this );
507 
508  if( !evt )
509  runOnSubmenus( findFunc );
510 
511  return evt;
512 }
Class ACTION_MENU.
Definition: action_menu.h:43
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:548

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 161 of file action_menu.h.

162  {
163  return aAction.GetId() + ACTION_ID;
164  }
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: action_menu.h:230
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 120 of file action_menu.h.

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

References ACTION_MENU::m_selected.

Referenced by EE_INSPECTION_TOOL::ShowDatasheet().

◆ getToolManager()

TOOL_MANAGER * ACTION_MENU::getToolManager ( ) const
protectedinherited

Returns an instance of TOOL_MANAGER class.

Definition at line 292 of file action_menu.cpp.

293 {
294  wxASSERT( m_tool );
295  return m_tool ? m_tool->GetManager() : nullptr;
296 }
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:227

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

Referenced by ACTION_MENU::OnMenuEvent(), BUS_UNFOLD_MENU::update(), SYMBOL_UNIT_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 214 of file action_menu.cpp.

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

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent &  event)
inherited

Definition at line 343 of file action_menu.cpp.

344 {
346 }
static int g_last_menu_highlighted_id

References g_last_menu_highlighted_id.

Referenced by ACTION_MENU::setupEvents().

◆ OnMenuEvent()

void ACTION_MENU::OnMenuEvent ( wxMenuEvent &  aEvent)
inherited

Definition at line 349 of file action_menu.cpp.

350 {
351  OPT_TOOL_EVENT evt;
352  wxString menuText;
353  wxEventType type = aEvent.GetEventType();
354 
355  if( type == wxEVT_MENU_OPEN )
356  {
357  if( m_dirty && m_tool )
358  getToolManager()->RunAction( ACTIONS::updateMenu, true, this );
359 
361  }
362  else if( type == wxEVT_MENU_HIGHLIGHT )
363  {
364  if( aEvent.GetId() > 0 )
365  g_last_menu_highlighted_id = aEvent.GetId();
366 
367  evt = TOOL_EVENT( TC_COMMAND, TA_CHOICE_MENU_UPDATE, aEvent.GetId() );
368  }
369  else if( type == wxEVT_COMMAND_MENU_SELECTED )
370  {
371  // Store the selected position, so it can be checked by the tools
372  m_selected = aEvent.GetId();
373 
374  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
375 
376  while( parent )
377  {
378  parent->m_selected = m_selected;
379  parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
380  }
381 
382  // Check if there is a TOOL_ACTION for the given ID
383  if( m_selected >= ACTION_ID )
384  evt = findToolAction( m_selected );
385 
386  if( !evt )
387  {
388 #ifdef __WINDOWS__
389  if( !evt )
390  {
391  // Try to find the submenu which holds the selected item
392  wxMenu* menu = nullptr;
393  FindItem( m_selected, &menu );
394 
395  // This conditional compilation is probably not needed.
396  // It will be removed later, for the Kicad V 6.x version.
397  // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid hang
398  // This hang is no longer encountered in wxWidgets 3.0.4 version, and this condition is no longer needed.
399  // And in 3.1.2, we have to remove it, as "menu != this" never happens
400  // ("menu != this" always happens in 3.1.1 and older!).
401  #if wxCHECK_VERSION(3, 1, 2)
402  if( menu )
403  #else
404  if( menu && menu != this )
405  #endif
406  {
407  ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
408  evt = cxmenu->eventHandler( aEvent );
409  }
410  }
411 #else
412  if( !evt )
413  runEventHandlers( aEvent, evt );
414 #endif
415 
416  // Handling non-action menu entries (e.g. items in clarification list)
417  // in some context menus, that have IDs explicitly chosen between
418  // ID_POPUP_MENU_START and ID_POPUP_MENU_END
419  // Note also items in clarification list have an id >= 0 and < wxID_LOWEST
420  // in fact 0 to n-1 for n items in clarification list)
421  // id < 0 are automatically created for menuitems created with wxID_ANY
422  #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be enough and better */
423 
424  if( !evt &&
425  ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) ||
427  {
428  menuText = GetLabelText( aEvent.GetId() );
430  &menuText );
431  }
432  }
433  }
434 
435  // forward the action/update event to the TOOL_MANAGER
436  // clients that don't supply a tool will have to check GetSelected() themselves
437  if( evt && m_tool )
438  {
439 
440  wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() );
441 
442  TOOL_MANAGER* toolMgr = m_tool->GetManager();
443 
444  if( g_last_menu_highlighted_id == aEvent.GetId() && !m_isContextMenu )
445  evt->SetHasPosition( false );
446 
447  if( toolMgr->GetEditFrame() && !toolMgr->GetEditFrame()->GetDoImmediateActions() )
448  {
449  // An tool-selection-event has no position
450  if( evt->GetCommandStr().is_initialized()
451  && evt->GetCommandStr().get() != toolMgr->GetEditFrame()->CurrentToolName() )
452  {
453  evt->SetHasPosition( false );
454  }
455  }
456 
457  if( m_tool->GetManager() )
458  m_tool->GetManager()->ProcessEvent( *evt );
459  }
460  else
461  {
462  aEvent.Skip();
463  }
464 }
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
Class ACTION_MENU.
Definition: action_menu.h:43
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
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:178
Class TOOL_MANAGER.
Definition: tool_manager.h:50
#define ID_CONTEXT_MENU_ID_MAX
bool m_isContextMenu
Definition: action_menu.h:215
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
Class TOOL_EVENT.
Definition: tool_event.h:168
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:224
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: action_menu.h:230
static TOOL_ACTION updateMenu
Definition: actions.h:158
All active tools
Definition: tool_event.h:144
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:227
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:548

References ACTION_MENU::ACTION_ID, AS_GLOBAL, ACTION_MENU::eventHandler(), ACTION_MENU::findToolAction(), g_last_menu_highlighted_id, TOOL_BASE::GetManager(), 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, TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), ACTION_MENU::runEventHandlers(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, TC_COMMAND, and ACTIONS::updateMenu.

Referenced by EDA_BASE_FRAME::OnMenuOpen(), and ACTION_MENU::setupEvents().

◆ Resolve()

void CONDITIONAL_MENU::Resolve ( )

Function Resolve()

Updates the initial contents so that wxWidgets doesn't get its knickers tied in a knot over the menu being empty (mainly an issue on GTK, but also on OSX with the preferences and quit menu items).

Definition at line 128 of file conditional_menu.cpp.

129 {
131  UpdateAll();
132 
133  runOnSubmenus( [] ( ACTION_MENU* aMenu ) {
134  CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( aMenu );
135 
136  if( conditionalMenu )
137  conditionalMenu->Resolve();
138  } );
139 }
Class ACTION_MENU.
Definition: action_menu.h:43
SELECTION g_resolveDummySelection
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
void Evaluate(SELECTION &aSelection)
Function Evaluate()
void Resolve()
Function Resolve()
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.

References Evaluate(), g_resolveDummySelection, Resolve(), ACTION_MENU::runOnSubmenus(), and ACTION_MENU::UpdateAll().

Referenced by EDA_3D_VIEWER::CreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), LIB_VIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), and Resolve().

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

468 {
469  aToolEvent = eventHandler( aMenuEvent );
470 
471  if( !aToolEvent )
472  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
473 }
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:178
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 476 of file action_menu.cpp.

477 {
478  try
479  {
480  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
481  aFunction( m );
482  m->runOnSubmenus( aFunction );
483  } );
484  }
485  catch( std::exception& e )
486  {
487  wxLogDebug( wxString::Format( "ACTION_MENU runOnSubmenus exception: %s", e.what() ) );
488  }
489 }
Class ACTION_MENU.
Definition: action_menu.h:43
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:236
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(), Evaluate(), ACTION_MENU::findToolAction(), Resolve(), ACTION_MENU::runEventHandlers(), ACTION_MENU::SetDirty(), ACTION_MENU::SetTool(), and ACTION_MENU::UpdateAll().

◆ SetDirty()

void ACTION_MENU::SetDirty ( )
inherited

Definition at line 258 of file action_menu.cpp.

259 {
260  m_dirty = true;
261  runOnSubmenus( std::bind( &ACTION_MENU::SetDirty, _1 ) );
262 }
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 86 of file action_menu.cpp.

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

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::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(), 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 265 of file action_menu.cpp.

266 {
267  m_tool = aTool;
268  runOnSubmenus( std::bind( &ACTION_MENU::SetTool, _1, aTool ) );
269 }
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:227
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(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protectedinherited

Initializes handlers for events.

Definition at line 74 of file action_menu.cpp.

75 {
76 // See wxWidgets hack in EDA_BASE_FRAME::OnMenuOpen().
77 // Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
78 // Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
79 // Connect( wxEVT_MENU_CLOSE, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
80 
81  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
82  Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), NULL, this );
83 }
void OnMenuEvent(wxMenuEvent &aEvent)
void OnIdle(wxIdleEvent &event)

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

Referenced by ACTION_MENU::ACTION_MENU().

◆ update()

virtual void ACTION_MENU::update ( )
inlineprotectedvirtualinherited

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 in DIFF_PAIR_MENU, TRACK_WIDTH_MENU, ZONE_CONTEXT_MENU, SELECT_MENU, SYMBOL_UNIT_MENU, BUS_UNFOLD_MENU, HIGHLIGHT_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 170 of file action_menu.h.

171  {
172  }

Referenced by ACTION_MENU::UpdateAll().

◆ UpdateAll()

void ACTION_MENU::UpdateAll ( )
inherited

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

Definition at line 233 of file action_menu.cpp.

234 {
235  try
236  {
237  update();
238  }
239  catch( std::exception& e )
240  {
241  wxLogDebug( wxString::Format( "ACTION_MENU update handler exception: %s", e.what() ) );
242  }
243 
244  if( m_tool )
245  updateHotKeys();
246 
247  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
248 }
virtual void update()
Update menu state stub.
Definition: action_menu.h:170
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:227
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 Resolve(), TOOL_MENU::ShowContextMenu(), KICAD_MANAGER_CONTROL::UpdateMenu(), GERBVIEW_SELECTION_TOOL::UpdateMenu(), PL_SELECTION_TOOL::UpdateMenu(), EE_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 299 of file action_menu.cpp.

300 {
301  TOOL_MANAGER* toolMgr = getToolManager();
302 
303  for( auto& ii : m_toolActions )
304  {
305  int id = ii.first;
306  const TOOL_ACTION& action = *ii.second;
307  int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
308 
309  if( key )
310  {
311  int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
312  int flags = 0;
313  wxMenuItem* item = FindChildItem( id );
314 
315  if( item )
316  {
317  flags |= ( mod & MD_ALT ) ? wxACCEL_ALT : 0;
318  flags |= ( mod & MD_CTRL ) ? wxACCEL_CTRL : 0;
319  flags |= ( mod & MD_SHIFT ) ? wxACCEL_SHIFT : 0;
320 
321  if( !flags )
322  flags = wxACCEL_NORMAL;
323 
324  wxAcceleratorEntry accel( flags, key, id, item );
325  item->SetAccel( &accel );
326  }
327  }
328  }
329 }
int GetHotKey(const TOOL_ACTION &aAction)
Class 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:233
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
Class TOOL_ACTION.
Definition: tool_action.h:46
#define mod(a, n)
Definition: greymap.cpp:24

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

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 230 of file action_menu.h.

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

◆ ANY_ORDER

const int CONDITIONAL_MENU::ANY_ORDER = -1
static

Constant to indicate that we do not care about an ENTRY location in the menu.

Definition at line 43 of file conditional_menu.h.

◆ m_dirty

bool ACTION_MENU::m_dirty
protectedinherited

◆ m_entries

std::list<ENTRY> CONDITIONAL_MENU::m_entries
private

List of all menu entries.

Definition at line 261 of file conditional_menu.h.

Referenced by addEntry(), create(), and Evaluate().

◆ m_icon

const BITMAP_OPAQUE* ACTION_MENU::m_icon
protectedinherited

Optional icon

Definition at line 221 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

Definition at line 215 of file action_menu.h.

Referenced by create(), Evaluate(), and ACTION_MENU::OnMenuEvent().

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Stores the id number of selected item.

Definition at line 224 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

TOOL_INTERACTIVE* ACTION_MENU::m_tool
protectedinherited

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