![]() |
KiCad PCB EDA Suite
|
Defines the structure of a menu based on ACTIONs. More...
#include <action_menu.h>
Public Member Functions | |
ACTION_MENU (bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr) | |
< Default constructor More... | |
~ACTION_MENU () override | |
ACTION_MENU (const ACTION_MENU &aMenu)=delete | |
ACTION_MENU & | operator= (const ACTION_MENU &aMenu)=delete |
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 (const BITMAP_OPAQUE *aIcon) |
Assign an icon for the entry. More... | |
wxMenuItem * | Add (const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon) |
Add a wxWidgets-style entry to the menu. More... | |
wxMenuItem * | Add (const wxString &aLabel, const wxString &aToolTip, int aId, const BITMAP_OPAQUE *aIcon, bool aIsCheckmarkEntry=false) |
wxMenuItem * | Add (const TOOL_ACTION &aAction, bool aIsCheckmarkEntry=false) |
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_MENU * | Clone () const |
Create a deep, recursive copy of this ACTION_MENU. More... | |
void | OnMenuEvent (wxMenuEvent &aEvent) |
void | OnIdle (wxIdleEvent &event) |
virtual bool | PassHelpTextToHandler () |
Static Public Attributes | |
static constexpr bool | CHECK = true |
Protected Member Functions | |
virtual ACTION_MENU * | create () const |
< Return an instance of this class. It has to be overridden in inheriting classes. More... | |
TOOL_MANAGER * | getToolManager () const |
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) |
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... | |
const BITMAP_OPAQUE * | m_icon |
Stores the id number of selected item. More... | |
int | m_selected |
Creator of the menu. More... | |
TOOL_INTERACTIVE * | m_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 |
Friends | |
class | TOOL_INTERACTIVE |
Defines the structure of a menu based on ACTIONs.
Definition at line 45 of file action_menu.h.
ACTION_MENU::ACTION_MENU | ( | bool | isContextMenu, |
TOOL_INTERACTIVE * | aTool = nullptr |
||
) |
< Default constructor
Definition at line 46 of file action_menu.cpp.
References setupEvents().
Referenced by create(), and BUS_UNFOLD_MENU::update().
|
override |
|
delete |
wxMenuItem * ACTION_MENU::Add | ( | const wxString & | aLabel, |
int | aId, | ||
const BITMAP_OPAQUE * | aIcon | ||
) |
Add a wxWidgets-style entry to the menu.
After highlighting/selecting the entry, a wxWidgets event is generated.
Definition at line 137 of file action_menu.cpp.
References AddBitmapToMenuItem(), and KiBitmap().
Referenced by AddClose(), AddMenuLanguageList(), AddQuitOrClose(), EDA_3D_VIEWER::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().
wxMenuItem * ACTION_MENU::Add | ( | const wxString & | aLabel, |
const wxString & | aToolTip, | ||
int | aId, | ||
const BITMAP_OPAQUE * | aIcon, | ||
bool | aIsCheckmarkEntry = false |
||
) |
Definition at line 150 of file action_menu.cpp.
References AddBitmapToMenuItem(), and KiBitmap().
wxMenuItem * ACTION_MENU::Add | ( | const TOOL_ACTION & | aAction, |
bool | aIsCheckmarkEntry = false |
||
) |
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.
aAction | is the action to be added to menu entry. |
ID numbers for tool actions are assigned above ACTION_BASE_UI_ID inside TOOL_EVENT
Definition at line 165 of file action_menu.cpp.
References AddBitmapToMenuItem(), TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetMenuItem(), TOOL_ACTION::GetUIId(), KiBitmap(), and m_toolActions.
wxMenuItem * ACTION_MENU::Add | ( | ACTION_MENU * | aMenu | ) |
Add an action menu as a submenu.
The difference between this function and wxMenu::AppendSubMenu() is the capability to handle icons.
aMenu | is the submenu to be added. |
Definition at line 182 of file action_menu.cpp.
References AddBitmapToMenuItem(), Clone(), KiBitmap(), m_icon, m_submenus, and m_title.
void ACTION_MENU::AddClose | ( | wxString | aAppname = "" | ) |
Add a standard close item to the menu with the accelerator key CTRL-W.
Emits the wxID_CLOSE event.
aAppname | is the application name to append to the tooltip. |
Definition at line 203 of file action_menu.cpp.
References _, Add(), exit_xpm, and Format().
Referenced by AddQuitOrClose(), EDA_3D_VIEWER::CreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), and CVPCB_MAINFRAME::ReCreateMenuBar().
void ACTION_MENU::AddQuitOrClose | ( | KIFACE_I * | aKiface, |
wxString | aAppname = "" |
||
) |
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.
aAppname | is the application name to append to the tooltip. |
Definition at line 212 of file action_menu.cpp.
References _, Add(), AddClose(), exit_xpm, 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().
|
protected |
Append a copy of wxMenuItem.
Initialize handlers for events.
Definition at line 626 of file action_menu.cpp.
References AddBitmapToMenuItem(), Clone(), and m_submenus.
Referenced by copyFrom().
void ACTION_MENU::Clear | ( | ) |
Remove all the entries from the menu (as well as its title).
It leaves the menu in the initial state.
Definition at line 230 of file action_menu.cpp.
References m_submenus, m_titleDisplayed, and m_toolActions.
Referenced by Clone(), CONDITIONAL_MENU::Evaluate(), VIA_SIZE_MENU::update(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), TRACK_WIDTH_MENU::update(), and DIFF_PAIR_MENU::update().
void ACTION_MENU::ClearDirty | ( | ) |
Clear the dirty flag on the menu and all descendants.
Definition at line 280 of file action_menu.cpp.
References m_dirty, and runOnSubmenus().
Referenced by TOOL_MENU::ShowContextMenu().
ACTION_MENU * ACTION_MENU::Clone | ( | ) | const |
Create a deep, recursive copy of this ACTION_MENU.
Definition at line 301 of file action_menu.cpp.
References Clear(), copyFrom(), and create().
Referenced by Add(), appendCopy(), and TOOL_MANAGER::DispatchContextMenu().
|
protected |
Copy another menus data to this instance.
Old entries are preserved and ones form aMenu are copied.
Definition at line 608 of file action_menu.cpp.
References appendCopy(), m_icon, m_selected, m_title, m_titleDisplayed, m_tool, and m_toolActions.
Referenced by Clone().
|
protectedvirtual |
< Return an instance of this class. It has to be overridden in inheriting classes.
Returns an instance of TOOL_MANAGER class.
Reimplemented in DIFF_PAIR_MENU, TRACK_WIDTH_MENU, LOCK_CONTEXT_MENU, HIGHLIGHT_MENU, ZONE_CONTEXT_MENU, BUS_UNFOLD_MENU, SELECT_MENU, SYMBOL_UNIT_MENU, NET_CONTEXT_MENU, VIA_SIZE_MENU, GROUP_CONTEXT_MENU, CONDITIONAL_MENU, GRID_MENU, and ZOOM_MENU.
Definition at line 310 of file action_menu.cpp.
References ACTION_MENU(), and Format().
Referenced by Clone().
void ACTION_MENU::DisplayTitle | ( | bool | aDisplay = true | ) |
Decide whether a title for a pop up menu should be displayed.
Definition at line 100 of file action_menu.cpp.
References AddBitmapToMenuItem(), KiBitmap(), m_icon, m_title, and m_titleDisplayed.
Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), and SetTitle().
|
inlineprotectedvirtual |
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 200 of file action_menu.h.
Referenced by OnMenuEvent(), and runEventHandlers().
|
protected |
Definition at line 585 of file action_menu.cpp.
References runOnSubmenus().
Referenced by OnMenuEvent().
|
inline |
Return the position of selected item.
If the returned value is negative, that means that menu was dismissed.
Definition at line 142 of file action_menu.h.
References m_selected.
|
protected |
Definition at line 321 of file action_menu.cpp.
References TOOL_BASE::GetManager(), and m_tool.
Referenced by VIA_SIZE_MENU::eventHandler(), OnMenuEvent(), GROUP_CONTEXT_MENU::update(), VIA_SIZE_MENU::update(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), and updateHotKeys().
bool ACTION_MENU::HasEnabledItems | ( | ) | const |
Returns true if the menu has any enabled items.
Definition at line 244 of file action_menu.cpp.
void ACTION_MENU::OnIdle | ( | wxIdleEvent & | event | ) |
Definition at line 376 of file action_menu.cpp.
References g_last_menu_highlighted_id, g_menu_open_position, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by setupEvents().
void ACTION_MENU::OnMenuEvent | ( | wxMenuEvent & | aEvent | ) |
Definition at line 384 of file action_menu.cpp.
References AS_GLOBAL, eventHandler(), findToolAction(), g_last_menu_highlighted_id, g_menu_open_position, TOOL_ACTION::GetBaseUIId(), TOOL_BASE::GetManager(), TOOL_MANAGER::GetMousePosition(), getToolManager(), ID_CONTEXT_MENU_ID_MAX, ID_POPUP_MENU_END, ID_POPUP_MENU_START, kicadTraceToolStack, m_dirty, m_isContextMenu, m_selected, m_tool, TEXTENTRY_TRICKS::OnCharHook(), PassHelpTextToHandler(), TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), runEventHandlers(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, TC_COMMAND, and ACTIONS::updateMenu.
Referenced by TOOL_DISPATCHER::DispatchWxEvent(), and setupEvents().
|
delete |
|
inlinevirtual |
Reimplemented in BUS_UNFOLD_MENU.
Definition at line 173 of file action_menu.h.
Referenced by OnMenuEvent().
|
protected |
Run a function on the menu and all its submenus.
Definition at line 561 of file action_menu.cpp.
References eventHandler(), and runOnSubmenus().
Referenced by OnMenuEvent().
|
protected |
Check if any of submenus contains a TOOL_ACTION with a specific ID.
Definition at line 570 of file action_menu.cpp.
References m_submenus.
Referenced by ClearDirty(), CONDITIONAL_MENU::Evaluate(), findToolAction(), CONDITIONAL_MENU::Resolve(), runEventHandlers(), SetDirty(), SetTool(), and UpdateAll().
void ACTION_MENU::SetDirty | ( | ) |
Definition at line 287 of file action_menu.cpp.
References m_dirty, and runOnSubmenus().
Referenced by TOOL_MENU::ShowContextMenu().
void ACTION_MENU::SetIcon | ( | const BITMAP_OPAQUE * | aIcon | ) |
Assign an icon for the entry.
aIcon | is the icon to be assigned. NULL is used to remove icon. |
Definition at line 71 of file action_menu.cpp.
References m_icon.
Referenced by AddMenuLanguageList(), BUS_UNFOLD_MENU::BUS_UNFOLD_MENU(), EDA_3D_VIEWER::CreateMenuBar(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), GRID_MENU::GRID_MENU(), GROUP_CONTEXT_MENU::GROUP_CONTEXT_MENU(), 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().
|
override |
Set title for the menu.
The title is shown as a text label shown on the top of the menu.
aTitle | is the new title. |
Definition at line 89 of file action_menu.cpp.
References DisplayTitle(), m_title, and m_titleDisplayed.
Referenced by AddMenuLanguageList(), BUS_UNFOLD_MENU::BUS_UNFOLD_MENU(), EDA_3D_VIEWER::CreateMenuBar(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), GRID_MENU::GRID_MENU(), 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().
void ACTION_MENU::SetTool | ( | TOOL_INTERACTIVE * | aTool | ) |
Set a tool that is the creator of the menu.
aTool | is the tool that created the menu. |
Definition at line 294 of file action_menu.cpp.
References m_tool, and runOnSubmenus().
Referenced by ALIGN_DISTRIBUTE_TOOL::Init(), GERBVIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), TOOL_INTERACTIVE::SetContextMenu(), CVPCB_MAINFRAME::setupTools(), SCH_LINE_WIRE_BUS_TOOL::UnfoldBus(), and BUS_UNFOLD_MENU::update().
|
protected |
Update hot key settings for TOOL_ACTIONs in this menu.
Definition at line 77 of file action_menu.cpp.
References NULL, OnIdle(), and OnMenuEvent().
Referenced by ACTION_MENU().
|
inlineprotectedvirtual |
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, BUS_UNFOLD_MENU, SYMBOL_UNIT_MENU, VIA_SIZE_MENU, HIGHLIGHT_MENU, GROUP_CONTEXT_MENU, GRID_MENU, and ZOOM_MENU.
Definition at line 190 of file action_menu.h.
Referenced by UpdateAll().
void ACTION_MENU::UpdateAll | ( | ) |
Run update handlers for the menu and its submenus.
Definition at line 263 of file action_menu.cpp.
References m_tool, runOnSubmenus(), update(), and updateHotKeys().
Referenced by ACTION_TOOLBAR::onToolRightClick(), CONDITIONAL_MENU::Resolve(), TOOL_MENU::ShowContextMenu(), KICAD_MANAGER_CONTROL::UpdateMenu(), PL_SELECTION_TOOL::UpdateMenu(), EDA_3D_CONTROLLER::UpdateMenu(), GERBVIEW_SELECTION_TOOL::UpdateMenu(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu(), EE_SELECTION_TOOL::UpdateMenu(), CVPCB_CONTROL::UpdateMenu(), and PCB_SELECTION_TOOL::UpdateMenu().
|
protected |
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 328 of file action_menu.cpp.
References TOOL_MANAGER::GetHotKey(), getToolManager(), m_toolActions, MD_ALT, MD_CTRL, MD_MODIFIER_MASK, and MD_SHIFT.
Referenced by UpdateAll().
|
friend |
Definition at line 260 of file action_menu.h.
|
static |
Definition at line 175 of file action_menu.h.
Referenced by EDA_3D_VIEWER::CreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateVToolbar().
|
protected |
Definition at line 237 of file action_menu.h.
Referenced by ClearDirty(), OnMenuEvent(), and SetDirty().
|
protected |
Definition at line 235 of file action_menu.h.
|
protected |
Stores the id number of selected item.
Definition at line 246 of file action_menu.h.
Referenced by Add(), copyFrom(), DisplayTitle(), and SetIcon().
|
protected |
|
protected |
Definition at line 234 of file action_menu.h.
|
protected |
Creator of the menu.
Definition at line 249 of file action_menu.h.
Referenced by copyFrom(), GetSelected(), and OnMenuEvent().
|
protected |
Definition at line 258 of file action_menu.h.
Referenced by Add(), appendCopy(), Clear(), runOnSubmenus(), and ~ACTION_MENU().
|
protected |
Optional icon.
Definition at line 243 of file action_menu.h.
Referenced by Add(), copyFrom(), DisplayTitle(), and SetTitle().
|
protected |
Definition at line 239 of file action_menu.h.
Referenced by Clear(), copyFrom(), DisplayTitle(), and SetTitle().
|
protected |
Associates tool actions with menu item IDs. Non-owning.
Definition at line 252 of file action_menu.h.
Referenced by copyFrom(), CONDITIONAL_MENU::create(), getToolManager(), OnMenuEvent(), SetTool(), BUS_UNFOLD_MENU::update(), and UpdateAll().
|
protected |
List of submenus.
Definition at line 255 of file action_menu.h.
Referenced by Add(), Clear(), copyFrom(), and updateHotKeys().