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

Public Member Functions

 BUS_UNFOLD_MENU ()
 
void SetShowTitle ()
 
bool PassHelpTextToHandler () override
 
void SetTitle (const wxString &aTitle) override
 Set title for the menu. More...
 
void DisplayTitle (bool aDisplay=true)
 Decide whether a title for a pop up menu should be displayed. More...
 
void SetIcon (BITMAPS aIcon)
 Assign an icon for the entry. More...
 
wxMenuItem * Add (const wxString &aLabel, int aId, BITMAPS aIcon)
 Add a wxWidgets-style entry to the menu. More...
 
wxMenuItem * Add (const wxString &aLabel, const wxString &aToolTip, int aId, BITMAPS aIcon, bool aIsCheckmarkEntry=false)
 
wxMenuItem * Add (const TOOL_ACTION &aAction, bool aIsCheckmarkEntry=false, const wxString &aOverrideLabel=wxEmptyString)
 Add an entry to the menu based on the TOOL_ACTION object. More...
 
wxMenuItem * Add (ACTION_MENU *aMenu)
 Add an action menu as a submenu. More...
 
void AddClose (wxString aAppname="")
 Add a standard close item to the menu with the accelerator key CTRL-W. More...
 
void AddQuitOrClose (KIFACE_I *aKiface, wxString aAppname="")
 Add either a standard Quit or Close item to the menu. More...
 
void Clear ()
 Remove all the entries from the menu (as well as its title). More...
 
bool HasEnabledItems () const
 Returns true if the menu has any enabled items. More...
 
int GetSelected () const
 Return the position of selected item. More...
 
void UpdateAll ()
 Run update handlers for the menu and its submenus. More...
 
void ClearDirty ()
 Clear the dirty flag on the menu and all descendants. More...
 
void SetDirty ()
 
void SetTool (TOOL_INTERACTIVE *aTool)
 Set a tool that is the creator of the menu. More...
 
ACTION_MENUClone () const
 Create a deep, recursive copy of this ACTION_MENU. More...
 
void OnMenuEvent (wxMenuEvent &aEvent)
 
void OnIdle (wxIdleEvent &event)
 

Static Public Attributes

static constexpr bool NORMAL = false
 
static constexpr bool CHECK = true
 

Protected Member Functions

ACTION_MENUcreate () const override
 < Return an instance of this class. It has to be overridden in inheriting classes. More...
 
TOOL_MANAGERgetToolManager () const
 
virtual OPT_TOOL_EVENT eventHandler (const wxMenuEvent &)
 Event handler stub. More...
 
void copyFrom (const ACTION_MENU &aMenu)
 Copy another menus data to this instance. More...
 
wxMenuItem * appendCopy (const wxMenuItem *aSource)
 Append a copy of wxMenuItem. More...
 
void setupEvents ()
 Update hot key settings for TOOL_ACTIONs in this menu. More...
 
void updateHotKeys ()
 Traverse the submenus tree looking for a submenu capable of handling a particular menu event. More...
 
void runEventHandlers (const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
 Run a function on the menu and all its submenus. More...
 
void runOnSubmenus (std::function< void(ACTION_MENU *)> aFunction)
 Check if any of submenus contains a TOOL_ACTION with a specific ID. More...
 
OPT_TOOL_EVENT findToolAction (int aId)
 

Protected Attributes

bool m_isForcedPosition
 
wxPoint m_forcedPosition
 
bool m_dirty
 
bool m_titleDisplayed
 
bool m_isContextMenu
 Menu title. More...
 
wxString m_title
 Optional icon. More...
 
BITMAPS m_icon
 Stores the id number of selected item. More...
 
int m_selected
 Creator of the menu. More...
 
TOOL_INTERACTIVEm_tool
 Associates tool actions with menu item IDs. Non-owning. More...
 
std::map< int, const TOOL_ACTION * > m_toolActions
 List of submenus. More...
 
std::list< ACTION_MENU * > m_submenus
 

Private Member Functions

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

Private Attributes

bool m_showTitle
 

Detailed Description

Definition at line 69 of file sch_line_wire_bus_tool.cpp.

Constructor & Destructor Documentation

◆ BUS_UNFOLD_MENU()

BUS_UNFOLD_MENU::BUS_UNFOLD_MENU ( )
inline

Definition at line 72 of file sch_line_wire_bus_tool.cpp.

72  :
73  ACTION_MENU( true ),
74  m_showTitle( false )
75  {
77  SetTitle( _( "Unfold from Bus" ) );
78  }
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
#define _(s)
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:91
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
< Default constructor
Definition: action_menu.cpp:47

References _, add_line2bus, ACTION_MENU::SetIcon(), and ACTION_MENU::SetTitle().

Referenced by create().

Member Function Documentation

◆ Add() [1/4]

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

Add a wxWidgets-style entry to the menu.

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

Definition at line 139 of file action_menu.cpp.

140 {
141  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
142 
143  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
144 
145  if( !!aIcon )
146  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
147 
148  return Append( item );
149 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References AddBitmapToMenuItem(), and KiBitmap().

Referenced by ACTION_MENU::AddClose(), AddMenuLanguageList(), ACTION_MENU::AddQuitOrClose(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), CONDITIONAL_MENU::Evaluate(), GROUP_CONTEXT_MENU::GROUP_CONTEXT_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), NET_CONTEXT_MENU::NET_CONTEXT_MENU(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), and CVPCB_MAINFRAME::setupTools().

◆ Add() [2/4]

wxMenuItem * ACTION_MENU::Add ( const wxString &  aLabel,
const wxString &  aToolTip,
int  aId,
BITMAPS  aIcon,
bool  aIsCheckmarkEntry = false 
)
inherited

Definition at line 152 of file action_menu.cpp.

154 {
155  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
156 
157  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, aTooltip,
158  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
159 
160  if( !!aIcon )
161  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
162 
163  return Append( item );
164 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References AddBitmapToMenuItem(), and KiBitmap().

◆ Add() [3/4]

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

Add an entry to the menu based 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.
aIsCheckmarkEntryis true to indicate a check menu entry, false for normal menu entry
aOverrideLabelis the label to show in the menu (overriding the action's menu text) when non-empty

ID numbers for tool actions are assigned above ACTION_BASE_UI_ID inside TOOL_EVENT

Definition at line 167 of file action_menu.cpp.

169 {
171  BITMAPS icon = aAction.GetIcon();
172 
173  // Allow the label to be overridden at point of use
174  wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.GetMenuItem() : aOverrideLabel;
175 
176  wxMenuItem* item = new wxMenuItem( this, aAction.GetUIId(), menuLabel,
177  aAction.GetDescription(),
178  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
179  if( !!icon )
180  AddBitmapToMenuItem( item, KiBitmap( icon ) );
181 
182  m_toolActions[aAction.GetUIId()] = &aAction;
183 
184  return Append( item );
185 }
int GetUIId() const
Definition: tool_action.h:130
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
const BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:179
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:97
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
wxString GetMenuItem() const
Definition: tool_action.cpp:89

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

◆ Add() [4/4]

wxMenuItem * ACTION_MENU::Add ( ACTION_MENU aMenu)
inherited

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

189 {
190  ACTION_MENU* menuCopy = aMenu->Clone();
191  m_submenus.push_back( menuCopy );
192 
193  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
194 
195  if( !!aMenu->m_icon )
196  {
197  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
198  AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) );
199  newItem->SetSubMenu( menuCopy );
200  return Append( newItem );
201  }
202  else
203  {
204  return AppendSubMenu( menuCopy, menuCopy->m_title );
205  }
206 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:254
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxString m_title
Optional icon.
Definition: action_menu.h:251
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

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

◆ AddClose()

void ACTION_MENU::AddClose ( wxString  aAppname = "")
inherited

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

210 {
211  Add( _( "Close" ) + "\tCtrl+W",
212  wxString::Format( _( "Close %s" ), aAppname ),
213  wxID_CLOSE,
214  BITMAPS::exit );
215 }
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.

References _, ACTION_MENU::Add(), exit, and Format().

Referenced by ACTION_MENU::AddQuitOrClose(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), and CVPCB_MAINFRAME::ReCreateMenuBar().

◆ AddQuitOrClose()

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

Add either a standard Quit or Close item to the menu.

If aKiface is NULL or in single-instance then quit (wxID_QUIT) is used, otherwise close (wxID_CLOSE) is used.

Parameters
aAppnameis the application name to append to the tooltip.

Definition at line 218 of file action_menu.cpp.

219 {
220  if( !aKiface || aKiface->IsSingle() ) // not when under a project mgr
221  {
222  // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via
223  // wxID_EXIT
224  Add( _( "Quit" ) + "\tCtrl+Q",
225  wxString::Format( _( "Quit %s" ), aAppname ),
226  wxID_EXIT,
227  BITMAPS::exit );
228  }
229  else
230  {
231  AddClose( aAppname );
232  }
233 }
bool IsSingle() const
Is this KIFACE_I running under single_top?
Definition: kiface_i.h:104
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
void AddClose(wxString aAppname="")
Add a standard close item to the menu with the accelerator key CTRL-W.

References _, ACTION_MENU::Add(), ACTION_MENU::AddClose(), exit, Format(), and KIFACE_I::IsSingle().

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

◆ appendCopy()

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

Append a copy of wxMenuItem.

Initialize handlers for events.

Definition at line 632 of file action_menu.cpp.

633 {
634  wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
635  aSource->GetHelp(), aSource->GetKind() );
636 
637  // Add the source bitmap if it is not the wxNullBitmap
638  // On Windows, for Checkable Menu items, adding a bitmap adds also
639  // our predefined checked alternate bitmap
640  // On other OS, wxITEM_CHECK and wxITEM_RADIO Menu items do not use custom bitmaps.
641 #if defined(_WIN32)
642  // On Windows, AddBitmapToMenuItem() uses the unchecked bitmap for wxITEM_CHECK and wxITEM_RADIO menuitems
643  // and autoamtically adds a checked bitmap.
644  // For other menuitrms, use the "checked" bitmap.
645  bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK || aSource->GetKind() == wxITEM_RADIO ) ? false : true;
646  const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
647 #else
648  const wxBitmap& src_bitmap = aSource->GetBitmap();
649 #endif
650 
651  if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size
652  AddBitmapToMenuItem( newItem, src_bitmap );
653 
654  if( aSource->IsSubMenu() )
655  {
656  ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
657  wxASSERT_MSG( menu, "Submenus are expected to be a ACTION_MENU" );
658 
659  if( menu )
660  {
661  ACTION_MENU* menuCopy = menu->Clone();
662  newItem->SetSubMenu( menuCopy );
663  m_submenus.push_back( menuCopy );
664  }
665  }
666 
667  // wxMenuItem has to be added before enabling/disabling or checking
668  Append( newItem );
669 
670  if( aSource->IsCheckable() )
671  newItem->Check( aSource->IsChecked() );
672 
673  newItem->Enable( aSource->IsEnabled() );
674 
675  return newItem;
676 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266
ACTION_MENU * Clone() const
Create 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

Remove all the entries from the menu (as well as its title).

It leaves the menu in the initial state.

Definition at line 236 of file action_menu.cpp.

237 {
238  m_titleDisplayed = false;
239 
240  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
241  Destroy( FindItemByPosition( i ) );
242 
243  m_toolActions.clear();
244  m_submenus.clear();
245 
246  wxASSERT( GetMenuItemCount() == 0 );
247 }
bool m_titleDisplayed
Definition: action_menu.h:247
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263

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

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

◆ ClearDirty()

void ACTION_MENU::ClearDirty ( )
inherited

Clear the dirty flag on the menu and all descendants.

Definition at line 286 of file action_menu.cpp.

287 {
288  m_dirty = false;
289  runOnSubmenus( std::bind( &ACTION_MENU::ClearDirty, _1 ) );
290 }
void ClearDirty()
Clear the dirty flag on the menu and all descendants.
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

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

Referenced by TOOL_MENU::ShowContextMenu().

◆ Clone()

ACTION_MENU * ACTION_MENU::Clone ( ) const
inherited

Create a deep, recursive copy of this ACTION_MENU.

Definition at line 307 of file action_menu.cpp.

308 {
309  ACTION_MENU* clone = create();
310  clone->Clear();
311  clone->copyFrom( *this );
312  return clone;
313 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
virtual ACTION_MENU * create() const
< Return an instance of this class. It has to be overridden in inheriting classes.
void copyFrom(const ACTION_MENU &aMenu)
Copy another menus data to this instance.
void Clear()
Remove 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

Copy another menus data to this instance.

Old entries are preserved and ones form aMenu are copied.

Definition at line 614 of file action_menu.cpp.

615 {
616  m_icon = aMenu.m_icon;
617  m_title = aMenu.m_title;
619  m_selected = -1; // aMenu.m_selected;
620  m_tool = aMenu.m_tool;
622 
623  // Copy all menu entries
624  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
625  {
626  wxMenuItem* item = aMenu.FindItemByPosition( i );
627  appendCopy( item );
628  }
629 }
bool m_titleDisplayed
Definition: action_menu.h:247
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:254
wxString m_title
Optional icon.
Definition: action_menu.h:251
int m_selected
Creator of the menu.
Definition: action_menu.h:257
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Append a copy of wxMenuItem.
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263

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* BUS_UNFOLD_MENU::create ( ) const
inlineoverrideprotectedvirtual

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

Returns an instance of TOOL_MANAGER class.

Reimplemented from ACTION_MENU.

Definition at line 88 of file sch_line_wire_bus_tool.cpp.

89  {
90  return new BUS_UNFOLD_MENU();
91  }

References BUS_UNFOLD_MENU().

◆ DisplayTitle()

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

Decide whether a title for a pop up menu should be displayed.

Definition at line 102 of file action_menu.cpp.

103 {
104  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
105  {
106  // Destroy the menu entry keeping the title..
107  wxMenuItem* item = FindItemByPosition( 0 );
108  wxASSERT( item->GetItemLabelText() == GetTitle() );
109  Destroy( item );
110  // ..and separator
111  item = FindItemByPosition( 0 );
112  wxASSERT( item->IsSeparator() );
113  Destroy( item );
114  m_titleDisplayed = false;
115  }
116 
117  else if( aDisplay && !m_title.IsEmpty() )
118  {
119  if( m_titleDisplayed )
120  {
121  // Simply update the title
122  FindItemByPosition( 0 )->SetItemLabel( m_title );
123  }
124  else
125  {
126  // Add a separator and a menu entry to display the title
127  InsertSeparator( 0 );
128  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
129 
130  if( !!m_icon )
131  AddBitmapToMenuItem( FindItemByPosition( 0 ), KiBitmap( m_icon ) );
132 
133  m_titleDisplayed = true;
134  }
135  }
136 }
bool m_titleDisplayed
Definition: action_menu.h:247
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:254
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxString m_title
Optional icon.
Definition: action_menu.h:251
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

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

◆ 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, VIA_SIZE_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 208 of file action_menu.h.

209  {
210  return OPT_TOOL_EVENT();
211  }
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:543

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

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int  aId)
protectedinherited

Definition at line 591 of file action_menu.cpp.

592 {
593  OPT_TOOL_EVENT evt;
594 
595  auto findFunc = [&]( ACTION_MENU* m ) {
596  if( evt )
597  return;
598 
599  const auto it = m->m_toolActions.find( aId );
600 
601  if( it != m->m_toolActions.end() )
602  evt = it->second->MakeEvent();
603  };
604 
605  findFunc( this );
606 
607  if( !evt )
608  runOnSubmenus( findFunc );
609 
610  return evt;
611 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:543

References ACTION_MENU::runOnSubmenus().

Referenced by ACTION_MENU::OnMenuEvent().

◆ GetSelected()

int ACTION_MENU::GetSelected ( ) const
inlineinherited

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

150  {
151  return m_selected;
152  }
int m_selected
Creator of the menu.
Definition: action_menu.h:257

References ACTION_MENU::m_selected.

◆ getToolManager()

TOOL_MANAGER * ACTION_MENU::getToolManager ( ) const
protectedinherited

Definition at line 327 of file action_menu.cpp.

328 {
329  wxASSERT( m_tool );
330  return m_tool ? m_tool->GetManager() : nullptr;
331 }
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260

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

Referenced by VIA_SIZE_MENU::eventHandler(), ACTION_MENU::OnMenuEvent(), GROUP_CONTEXT_MENU::update(), VIA_SIZE_MENU::update(), SYMBOL_UNIT_MENU::update(), update(), and ACTION_MENU::updateHotKeys().

◆ HasEnabledItems()

bool ACTION_MENU::HasEnabledItems ( ) const
inherited

Returns true if the menu has any enabled items.

Definition at line 250 of file action_menu.cpp.

251 {
252  bool hasEnabled = false;
253 
254  auto& items = GetMenuItems();
255 
256  for( auto item : items )
257  {
258  if( item->IsEnabled() && !item->IsSeparator() )
259  {
260  hasEnabled = true;
261  break;
262  }
263  }
264 
265  return hasEnabled;
266 }

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent &  event)
inherited

Definition at line 382 of file action_menu.cpp.

383 {
385  g_menu_open_position.x = 0.0;
386  g_menu_open_position.y = 0.0;
387 }
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 390 of file action_menu.cpp.

391 {
392  OPT_TOOL_EVENT evt;
393  wxString menuText;
394  wxEventType type = aEvent.GetEventType();
395  wxWindow* focus = wxWindow::FindFocus();
396 
397  if( type == wxEVT_MENU_OPEN )
398  {
399  if( m_dirty && m_tool )
400  getToolManager()->RunAction( ACTIONS::updateMenu, true, this );
401 
402  wxMenu* parent = dynamic_cast<wxMenu*>( GetParent() );
403 
404  // Don't update the position if this menu has a parent
405  if( !parent && m_tool )
407 
409  }
410  else if( type == wxEVT_MENU_HIGHLIGHT )
411  {
412  if( aEvent.GetId() > 0 )
413  g_last_menu_highlighted_id = aEvent.GetId();
414 
415  evt = TOOL_EVENT( TC_COMMAND, TA_CHOICE_MENU_UPDATE, aEvent.GetId() );
416  }
417  else if( type == wxEVT_COMMAND_MENU_SELECTED )
418  {
419  // Despite our attempts to catch the theft of text editor CHAR_HOOK and CHAR events
420  // in TOOL_DISPATCHER::DispatchWxEvent, wxWidgets sometimes converts those it knows
421  // about into menu commands without ever generating the appropriate CHAR_HOOK and CHAR
422  // events first.
423  if( dynamic_cast<wxTextEntry*>( focus )
424  || dynamic_cast<wxStyledTextCtrl*>( focus )
425  || dynamic_cast<wxListView*>( focus ) )
426  {
427  // Original key event has been lost, so we have to re-create it from the menu's
428  // wxAcceleratorEntry.
429  wxMenuItem* menuItem = FindItem( aEvent.GetId() );
430  wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() : nullptr;
431 
432  if( acceleratorKey )
433  {
434  wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
435  keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
436  keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
437  keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
438  keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
439 
440  if( auto ctrl = dynamic_cast<wxTextEntry*>( focus ) )
441  TEXTENTRY_TRICKS::OnCharHook( ctrl, keyEvent );
442  else
443  focus->HandleWindowEvent( keyEvent );
444 
445  if( keyEvent.GetSkipped() )
446  {
447  keyEvent.SetEventType( wxEVT_CHAR );
448  focus->HandleWindowEvent( keyEvent );
449  }
450 
451  // If the event was used as KEY event (not skipped) by the focused window,
452  // just finish.
453  // Otherwise this is actually a wxEVT_COMMAND_MENU_SELECTED, or the
454  // focused window is read only
455  if( !keyEvent.GetSkipped() )
456  return;
457  }
458  }
459 
460  // Store the selected position, so it can be checked by the tools
461  m_selected = aEvent.GetId();
462 
463  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
464 
465  while( parent )
466  {
467  parent->m_selected = m_selected;
468  parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
469  }
470 
471  // Check if there is a TOOL_ACTION for the given ID
473  evt = findToolAction( m_selected );
474 
475  if( !evt )
476  {
477 #ifdef __WINDOWS__
478  if( !evt )
479  {
480  // Try to find the submenu which holds the selected item
481  wxMenu* menu = nullptr;
482  FindItem( m_selected, &menu );
483 
484  // This conditional compilation is probably not needed.
485  // It will be removed later, for the Kicad V 6.x version.
486  // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid hang
487  // This hang is no longer encountered in wxWidgets 3.0.4 version, and this condition is no longer needed.
488  // And in 3.1.2, we have to remove it, as "menu != this" never happens
489  // ("menu != this" always happens in 3.1.1 and older!).
490  #if wxCHECK_VERSION(3, 1, 2)
491  if( menu )
492  #else
493  if( menu && menu != this )
494  #endif
495  {
496  ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
497  evt = cxmenu->eventHandler( aEvent );
498  }
499  }
500 #else
501  if( !evt )
502  runEventHandlers( aEvent, evt );
503 #endif
504 
505  // Handling non-ACTION menu entries. Two ranges of ids are supported:
506  // between 0 and ID_CONTEXT_MENU_ID_MAX
507  // between ID_POPUP_MENU_START and ID_POPUP_MENU_END
508 
509  #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be plenty */
510 
511  if( !evt &&
512  ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) ||
514  {
515  ACTION_MENU* actionMenu = dynamic_cast<ACTION_MENU*>( GetParent() );
516 
517  if( actionMenu && actionMenu->PassHelpTextToHandler() )
518  menuText = GetHelpString( aEvent.GetId() );
519  else
520  menuText = GetLabelText( aEvent.GetId() );
521 
523  &menuText );
524  }
525  }
526  }
527 
528  // forward the action/update event to the TOOL_MANAGER
529  // clients that don't supply a tool will have to check GetSelected() themselves
530  if( evt && m_tool )
531  {
532  wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() );
533 
534  // WARNING: if you're squeamish, look away.
535  // What follows is a series of egregious hacks necessitated by a lack of information from
536  // wxWidgets on where context-menu-commands and command-key-events originated.
537 
538  // If it's a context menu then fetch the mouse position from our context-menu-position
539  // hack.
540  if( m_isContextMenu )
541  {
542  evt->SetMousePosition( g_menu_open_position );
543  }
544  // Otherwise, if g_last_menu_highlighted_id matches then it's a menubar menu event and has
545  // no position.
546  else if( g_last_menu_highlighted_id == aEvent.GetId() )
547  {
548  evt->SetHasPosition( false );
549  }
550  // Otherwise it's a command-key-event and we need to get the mouse position from the tool
551  // manager so that immediate actions work.
552  else
553  {
554  evt->SetMousePosition( getToolManager()->GetMousePosition() );
555  }
556 
557  if( m_tool->GetManager() )
558  m_tool->GetManager()->ProcessEvent( *evt );
559  }
560  else
561  {
562  aEvent.Skip();
563  }
564 }
OPT_TOOL_EVENT findToolAction(int aId)
static int g_last_menu_highlighted_id
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
VECTOR2D GetMousePosition() const
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Run a function on the menu and all its submenus.
static int GetBaseUIId()
Definition: tool_action.h:135
TOOL_MANAGER * GetManager() const
Return 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:208
virtual bool PassHelpTextToHandler()
Definition: action_menu.h:180
#define ID_CONTEXT_MENU_ID_MAX
bool m_isContextMenu
Menu title.
Definition: action_menu.h:248
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
Generic, UI-independent tool event.
Definition: tool_event.h:152
static VECTOR2D g_menu_open_position
int m_selected
Creator of the menu.
Definition: action_menu.h:257
static TOOL_ACTION updateMenu
Definition: actions.h:167
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
Global action (toolbar/main menu event, global shortcut)
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)
TOOL_MANAGER * getToolManager() const
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:543

References AS_GLOBAL, ACTION_MENU::eventHandler(), ACTION_MENU::findToolAction(), g_last_menu_highlighted_id, g_menu_open_position, TOOL_ACTION::GetBaseUIId(), 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(), ACTION_MENU::PassHelpTextToHandler(), 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().

◆ PassHelpTextToHandler()

bool BUS_UNFOLD_MENU::PassHelpTextToHandler ( )
inlineoverridevirtual

Reimplemented from ACTION_MENU.

Definition at line 85 of file sch_line_wire_bus_tool.cpp.

85 { return true; }

◆ runEventHandlers()

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

Run a function on the menu and all its submenus.

Definition at line 567 of file action_menu.cpp.

568 {
569  aToolEvent = eventHandler( aMenuEvent );
570 
571  if( !aToolEvent )
572  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
573 }
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Run a function on the menu and all its submenus.
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition: action_menu.h:208
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

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

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

Definition at line 576 of file action_menu.cpp.

577 {
578  try
579  {
580  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
581  aFunction( m );
582  m->runOnSubmenus( aFunction );
583  } );
584  }
585  catch( std::exception& )
586  {
587  }
588 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266

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

294 {
295  m_dirty = true;
296  runOnSubmenus( std::bind( &ACTION_MENU::SetDirty, _1 ) );
297 }
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.
void SetDirty()

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

Referenced by TOOL_MENU::ShowContextMenu().

◆ SetIcon()

◆ SetShowTitle()

void BUS_UNFOLD_MENU::SetShowTitle ( )
inline

Definition at line 80 of file sch_line_wire_bus_tool.cpp.

81  {
82  m_showTitle = true;
83  }

References m_showTitle.

Referenced by SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ SetTitle()

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

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

92 {
93  // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version
94  m_title = aTitle;
95 
96  // Update the menu title
97  if( m_titleDisplayed )
98  DisplayTitle( true );
99 }
bool m_titleDisplayed
Definition: action_menu.h:247
wxString m_title
Optional icon.
Definition: action_menu.h:251
void DisplayTitle(bool aDisplay=true)
Decide whether a title for a pop up menu should be displayed.

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

Referenced by AddMenuLanguageList(), BUS_UNFOLD_MENU(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), GRID_MENU::GRID_MENU(), GROUP_CONTEXT_MENU::GROUP_CONTEXT_MENU(), ROUTER_TOOL::Init(), LENGTH_TUNER_TOOL::Init(), CONVERT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), NET_CONTEXT_MENU::NET_CONTEXT_MENU(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), SPECIAL_TOOLS_CONTEXT_MENU::SPECIAL_TOOLS_CONTEXT_MENU(), SYMBOL_UNIT_MENU::SYMBOL_UNIT_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), VIA_SIZE_MENU::VIA_SIZE_MENU(), and ZOOM_MENU::ZOOM_MENU().

◆ SetTool()

void ACTION_MENU::SetTool ( TOOL_INTERACTIVE aTool)
inherited

Set a tool that is the creator of the menu.

Parameters
aToolis the tool that created the menu.

Definition at line 300 of file action_menu.cpp.

301 {
302  m_tool = aTool;
303  runOnSubmenus( std::bind( &ACTION_MENU::SetTool, _1, aTool ) );
304 }
void SetTool(TOOL_INTERACTIVE *aTool)
Set a tool that is the creator of the menu.
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

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

Referenced by TOOL_INTERACTIVE::SetContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protectedinherited

Update hot key settings for TOOL_ACTIONs in this menu.

Definition at line 79 of file action_menu.cpp.

80 {
81 // See wxWidgets hack in TOOL_DISPATCHER::DispatchWxEvent().
82 // Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
83 // Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
84 // Connect( wxEVT_MENU_CLOSE, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
85 
86  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
87  Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), NULL, this );
88 }
#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 BUS_UNFOLD_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 94 of file sch_line_wire_bus_tool.cpp.

95  {
98  KICAD_T busType[] = { SCH_LINE_LOCATE_BUS_T, EOT };
99  EE_SELECTION& selection = selTool->RequestSelection( busType );
100  SCH_LINE* bus = (SCH_LINE*) selection.Front();
101 
102  Clear();
103 
104  // TODO(JE) remove once real-time is enabled
105  if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
106  {
108 
109  // Pick up the pointer again because it may have been changed by SchematicCleanUp
110  selection = selTool->RequestSelection( busType );
111  bus = (SCH_LINE*) selection.Front();
112  }
113 
114  if( !bus )
115  {
116  Append( ID_POPUP_SCH_UNFOLD_BUS, _( "No bus selected" ), wxEmptyString );
117  Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
118  return;
119  }
120 
121  SCH_CONNECTION* connection = bus->Connection();
122 
123  if( !connection || !connection->IsBus() || connection->Members().empty() )
124  {
125  Append( ID_POPUP_SCH_UNFOLD_BUS, _( "Bus has no members" ), wxEmptyString );
126  Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
127  return;
128  }
129 
130  int idx = 0;
131 
132  if( m_showTitle )
133  {
134  Append( ID_POPUP_SCH_UNFOLD_BUS, _( "Unfold from Bus" ), wxEmptyString );
135  Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
136  }
137 
138  for( const std::shared_ptr<SCH_CONNECTION>& member : connection->Members() )
139  {
140  int id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
141  wxString name = member->FullLocalName();
142 
143  if( member->Type() == CONNECTION_TYPE::BUS )
144  {
145  ACTION_MENU* submenu = new ACTION_MENU( true, m_tool );
146  AppendSubMenu( submenu, SCH_CONNECTION::PrintBusForUI( name ), name );
147 
148  for( const std::shared_ptr<SCH_CONNECTION>& sub_member : member->Members() )
149  {
150  id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
151  name = sub_member->FullLocalName();
152  submenu->Append( id, SCH_CONNECTION::PrintBusForUI( name ), name );
153  }
154  }
155  else
156  {
157  Append( id, name, wxEmptyString );
158  }
159  }
160  }
static wxString PrintBusForUI(const wxString &aString)
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
Schematic editor (Eeschema) main window.
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:131
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Return either an existing selection (filtered), or the selection at the current cursor if the existin...
#define _(s)
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
static bool m_allowRealTime
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:294
const char * name
Definition: DXF_plotter.cpp:59
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
< Default constructor
Definition: action_menu.cpp:47
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
TOOL_MANAGER * getToolManager() const
void Clear()
Remove all the entries from the menu (as well as its title).
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
bool IsBus() const
This item represents a bus vector.
EDA_ITEM * Front() const
Definition: selection.h:144

References _, ACTION_MENU::ACTION_MENU(), BUS, ACTION_MENU::Clear(), SCH_ITEM::Connection(), EOT, SELECTION::Front(), ADVANCED_CFG::GetCfg(), TOOL_MANAGER::GetTool(), TOOL_MANAGER::GetToolHolder(), ACTION_MENU::getToolManager(), ID_POPUP_SCH_UNFOLD_BUS, SCH_CONNECTION::IsBus(), CONNECTION_GRAPH::m_allowRealTime, m_showTitle, ACTION_MENU::m_tool, SCH_CONNECTION::Members(), name, NO_CLEANUP, SCH_CONNECTION::PrintBusForUI(), SCH_EDIT_FRAME::RecalculateConnections(), EE_SELECTION_TOOL::RequestSelection(), and SCH_LINE_LOCATE_BUS_T.

◆ UpdateAll()

void ACTION_MENU::UpdateAll ( )
inherited

Run update handlers for the menu and its submenus.

Definition at line 269 of file action_menu.cpp.

270 {
271  try
272  {
273  update();
274  }
275  catch( std::exception& )
276  {
277  }
278 
279  if( m_tool )
280  updateHotKeys();
281 
282  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
283 }
virtual void update()
Update menu state stub.
Definition: action_menu.h:198
void UpdateAll()
Run update handlers for the menu and its submenus.
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.
void updateHotKeys()
Traverse the submenus tree looking for a submenu capable of handling a particular menu event.

References 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(), PL_SELECTION_TOOL::UpdateMenu(), GERBVIEW_SELECTION_TOOL::UpdateMenu(), EDA_3D_CONTROLLER::UpdateMenu(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu(), EE_SELECTION_TOOL::UpdateMenu(), CVPCB_CONTROL::UpdateMenu(), and PCB_SELECTION_TOOL::UpdateMenu().

◆ updateHotKeys()

void ACTION_MENU::updateHotKeys ( )
protectedinherited

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

335 {
336  TOOL_MANAGER* toolMgr = getToolManager();
337 
338  for( auto& ii : m_toolActions )
339  {
340  int id = ii.first;
341  const TOOL_ACTION& action = *ii.second;
342  int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
343 
344  if( key )
345  {
346  int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
347  int flags = 0;
348  wxMenuItem* item = FindChildItem( id );
349 
350  if( item )
351  {
352  flags |= ( mod & MD_ALT ) ? wxACCEL_ALT : 0;
353  flags |= ( mod & MD_CTRL ) ? wxACCEL_CTRL : 0;
354  flags |= ( mod & MD_SHIFT ) ? wxACCEL_SHIFT : 0;
355 
356  if( !flags )
357  flags = wxACCEL_NORMAL;
358 
359  wxAcceleratorEntry accel( flags, key, id, item );
360  item->SetAccel( &accel );
361  }
362  }
363  }
364 }
Master controller class:
Definition: tool_manager.h:54
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263
TOOL_MANAGER * getToolManager() const
Represent a single user action.
Definition: tool_action.h:67
int GetHotKey(const TOOL_ACTION &aAction) const

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

◆ CHECK

◆ m_dirty

bool ACTION_MENU::m_dirty
protectedinherited

◆ m_forcedPosition

wxPoint ACTION_MENU::m_forcedPosition
protectedinherited

Definition at line 243 of file action_menu.h.

◆ m_icon

BITMAPS ACTION_MENU::m_icon
protectedinherited

Stores the id number of selected item.

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

Menu title.

Definition at line 248 of file action_menu.h.

Referenced by ACTION_MENU::OnMenuEvent().

◆ m_isForcedPosition

bool ACTION_MENU::m_isForcedPosition
protectedinherited

Definition at line 242 of file action_menu.h.

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Creator of the menu.

Definition at line 257 of file action_menu.h.

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

◆ m_showTitle

bool BUS_UNFOLD_MENU::m_showTitle
private

Definition at line 162 of file sch_line_wire_bus_tool.cpp.

Referenced by SetShowTitle(), and update().

◆ m_submenus

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

◆ m_title

wxString ACTION_MENU::m_title
protectedinherited

Optional icon.

Definition at line 251 of file action_menu.h.

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

◆ m_titleDisplayed

bool ACTION_MENU::m_titleDisplayed
protectedinherited

◆ m_tool

TOOL_INTERACTIVE* ACTION_MENU::m_tool
protectedinherited

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

Definition at line 260 of file action_menu.h.

Referenced by ACTION_MENU::copyFrom(), CONDITIONAL_MENU::create(), ACTION_MENU::getToolManager(), ACTION_MENU::OnMenuEvent(), ACTION_MENU::SetTool(), update(), and ACTION_MENU::UpdateAll().

◆ m_toolActions

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

List of submenus.

Definition at line 263 of file action_menu.h.

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

◆ NORMAL

constexpr bool ACTION_MENU::NORMAL = false
staticinherited

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