KiCad PCB EDA Suite
Loading...
Searching...
No Matches
POSITIONING_TOOLS_MENU Class Reference

#include <edit_tool.h>

Inheritance diagram for POSITIONING_TOOLS_MENU:
CONDITIONAL_MENU ACTION_MENU

Public Member Functions

 POSITIONING_TOOLS_MENU (TOOL_INTERACTIVE *aTool)
 
ACTION_MENUcreate () const override
 < Return 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)
 Add a menu entry to run a TOOL_ACTION on selected items. More...
 
void AddItem (int aId, const wxString &aText, const wxString &aTooltip, BITMAPS aIcon, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
 
void AddCheckItem (const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
 Add a checked menu entry to run a TOOL_ACTION on selected items. More...
 
void AddCheckItem (int aId, const wxString &aText, const wxString &aTooltip, BITMAPS 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)
 Add a submenu to the menu. More...
 
void AddSeparator (int aOrder=ANY_ORDER)
 Add a separator to the menu. More...
 
void AddSeparator (const SELECTION_CONDITION &aCondition, int aOrder)
 
void Evaluate (SELECTION &aSelection)
 Update the contents of the menu based on the supplied conditions. More...
 
void Resolve ()
 Update 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). More...
 
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 (const wxString &aAppname="")
 Add a standard close item to the menu with the accelerator key CTRL-W. More...
 
void AddQuitOrClose (KIFACE_BASE *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...
 
virtual void UpdateTitle ()
 Used by some menus to just-in-time translate their titles. 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)
 
virtual bool PassHelpTextToHandler ()
 

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...
 
static constexpr bool NORMAL = false
 
static constexpr bool CHECK = true
 

Protected Member Functions

TOOL_MANAGERgetToolManager () 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...
 
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 addEntry (ENTRY aEntry)
 List of all menu entries. More...
 

Private Attributes

std::list< ENTRYm_entries
 

Detailed Description

Definition at line 51 of file edit_tool.h.

Constructor & Destructor Documentation

◆ POSITIONING_TOOLS_MENU()

Member Function Documentation

◆ Add() [1/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. This should be a new instance (use Clone()) if required as the menu is destructed after use.

Definition at line 184 of file action_menu.cpp.

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

◆ Add() [2/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 163 of file action_menu.cpp.

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

◆ Add() [3/4]

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

Definition at line 148 of file action_menu.cpp.

References AddBitmapToMenuItem(), and KiBitmap().

◆ Add() [4/4]

◆ AddCheckItem() [1/2]

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

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

The condition for checking the menu entry should be supplied through a #ACTION_CONDITION registered with the ACTION_MANAGER.

Parameters
aActionis a menu entry to be added.
aConditionis a condition that has to be fulfilled to show the menu entry in the menu.
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.

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

Referenced by DRAWING_TOOL::Init().

◆ AddCheckItem() [2/2]

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

◆ AddClose()

void ACTION_MENU::AddClose ( const 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 204 of file action_menu.cpp.

References _, and ACTION_MENU::Add().

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

◆ addEntry()

void CONDITIONAL_MENU::addEntry ( ENTRY  aEntry)
privateinherited

◆ AddItem() [1/2]

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

◆ AddItem() [2/2]

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

◆ AddMenu()

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

Add 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 show the submenu entry in the menu.
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.

References CONDITIONAL_MENU::addEntry().

Referenced by SCH_EDIT_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), GERBVIEW_SELECTION_TOOL::Init(), BOARD_EDITOR_CONTROL::Init(), BOARD_INSPECTION_TOOL::Init(), CONVERT_TOOL::Init(), DRAWING_TOOL::Init(), EDIT_TOOL::Init(), GROUP_TOOL::Init(), and ALIGN_DISTRIBUTE_TOOL::Init().

◆ AddQuitOrClose()

void ACTION_MENU::AddQuitOrClose ( KIFACE_BASE 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 220 of file action_menu.cpp.

References _, ACTION_MENU::Add(), ACTION_MENU::AddClose(), and KIFACE_BASE::IsSingle().

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

◆ AddSeparator() [1/2]

void CONDITIONAL_MENU::AddSeparator ( const SELECTION_CONDITION aCondition,
int  aOrder 
)
inherited

Definition at line 102 of file conditional_menu.cpp.

References CONDITIONAL_MENU::addEntry().

◆ AddSeparator() [2/2]

◆ appendCopy()

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

Append a copy of wxMenuItem.

Initialize handlers for events.

Definition at line 639 of file action_menu.cpp.

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

Referenced by ACTION_MENU::copyFrom().

◆ Clear()

void ACTION_MENU::Clear ( )
inherited

◆ ClearDirty()

void ACTION_MENU::ClearDirty ( )
inherited

Clear the dirty flag on the menu and all descendants.

Definition at line 281 of file action_menu.cpp.

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

Referenced by ACTION_MENU::ClearDirty(), and TOOL_MENU::ShowContextMenu().

◆ Clone()

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

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 * CONDITIONAL_MENU::create ( ) const
overridevirtualinherited

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

Reimplemented in LOCK_CONTEXT_MENU.

Definition at line 39 of file conditional_menu.cpp.

References CONDITIONAL_MENU::m_entries, and ACTION_MENU::m_tool.

◆ DisplayTitle()

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

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

Definition at line 98 of file action_menu.cpp.

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

Referenced by SELECTION_TOOL::doSelectionMenu(), and ACTION_MENU::SetTitle().

◆ Evaluate()

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

Definition at line 214 of file action_menu.h.

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

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int  aId)
protectedinherited

Definition at line 596 of file action_menu.cpp.

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

References ACTION_MENU::m_selected.

◆ getToolManager()

◆ HasEnabledItems()

bool ACTION_MENU::HasEnabledItems ( ) const
inherited

Returns true if the menu has any enabled items.

Definition at line 252 of file action_menu.cpp.

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent &  event)
inherited

◆ OnMenuEvent()

◆ PassHelpTextToHandler()

virtual bool ACTION_MENU::PassHelpTextToHandler ( )
inlinevirtualinherited

Reimplemented in BUS_UNFOLD_MENU.

Definition at line 186 of file action_menu.h.

Referenced by ACTION_MENU::OnMenuEvent().

◆ Resolve()

void CONDITIONAL_MENU::Resolve ( )
inherited

Update 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 111 of file conditional_menu.cpp.

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

Referenced by CONDITIONAL_MENU::Resolve().

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

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

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

◆ runOnSubmenus()

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

◆ SetDirty()

void ACTION_MENU::SetDirty ( )
inherited

◆ SetIcon()

◆ SetTitle()

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

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

Referenced by TOOL_INTERACTIVE::SetContextMenu(), ACTION_MENU::SetTool(), 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.

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 SYMBOL_UNIT_MENU, BUS_UNFOLD_MENU, HIGHLIGHT_MENU, GRID_MENU, ZOOM_MENU, TRACK_WIDTH_MENU, DIFF_PAIR_MENU, VIA_SIZE_MENU, and GROUP_CONTEXT_MENU.

Definition at line 204 of file action_menu.h.

Referenced by ACTION_MENU::UpdateAll().

◆ UpdateAll()

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

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

◆ UpdateTitle()

virtual void ACTION_MENU::UpdateTitle ( )
inlinevirtualinherited

Used by some menus to just-in-time translate their titles.

Reimplemented in GRID_MENU, and ZOOM_MENU.

Definition at line 163 of file action_menu.h.

Member Data Documentation

◆ ANY_ORDER

const int CONDITIONAL_MENU::ANY_ORDER = -1
staticinherited

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

Definition at line 45 of file conditional_menu.h.

◆ CHECK

◆ m_dirty

bool ACTION_MENU::m_dirty
protectedinherited

◆ m_entries

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

◆ m_forcedPosition

wxPoint ACTION_MENU::m_forcedPosition
protectedinherited

Definition at line 249 of file action_menu.h.

◆ m_icon

BITMAPS ACTION_MENU::m_icon
protectedinherited

Stores the id number of selected item.

Definition at line 260 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 254 of file action_menu.h.

Referenced by ACTION_MENU::OnMenuEvent().

◆ m_isForcedPosition

bool ACTION_MENU::m_isForcedPosition
protectedinherited

Definition at line 248 of file action_menu.h.

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Creator of the menu.

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

Optional icon.

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

◆ m_toolActions

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

List of submenus.

Definition at line 269 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
staticconstexprinherited

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