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

#include <conditional_menu.h>

Inheritance diagram for CONDITIONAL_MENU:
ACTION_MENU LOCK_CONTEXT_MENU

Classes

class  ENTRY
 < Helper class to organize menu entries.Inserts the entry, preserving the requested order. More...
 

Public Member Functions

 CONDITIONAL_MENU (TOOL_INTERACTIVE *aTool)
 
ACTION_MENUcreate () const override
 Return an instance of this class. It has to be overridden in inheriting classes.
 
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.
 
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.
 
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.
 
void AddSeparator (int aOrder=ANY_ORDER)
 Add a separator to the menu.
 
void AddSeparator (const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
 
void Evaluate (const SELECTION &aSelection)
 Update the contents of the menu based on the supplied conditions.
 
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).
 
void SetTitle (const wxString &aTitle) override
 Set title for the menu.
 
wxString GetTitle () const
 
void DisplayTitle (bool aDisplay=true)
 Decide whether a title for a pop up menu should be displayed.
 
void SetIcon (BITMAPS aIcon)
 Assign an icon for the entry.
 
wxMenuItem * Add (const wxString &aLabel, int aId, BITMAPS aIcon)
 Add a wxWidgets-style entry to the menu.
 
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.
 
wxMenuItem * Add (ACTION_MENU *aMenu)
 Add an action menu as a submenu.
 
void AddClose (const wxString &aAppname="")
 Add a standard close item to the menu with the accelerator key CTRL-W.
 
void AddQuitOrClose (KIFACE_BASE *aKiface, wxString aAppname="")
 Add either a standard Quit or Close item to the menu.
 
void AddQuit (const wxString &aAppname="")
 Add a standard Quit item to the menu.
 
void Clear ()
 Remove all the entries from the menu (as well as its title).
 
bool HasEnabledItems () const
 Return true if the menu has any enabled items.
 
int GetSelected () const
 Return the position of selected item.
 
void UpdateAll ()
 Run update handlers for the menu and its submenus.
 
virtual void UpdateTitle ()
 Used by some menus to just-in-time translate their titles.
 
void ClearDirty ()
 Clear the dirty flag on the menu and all descendants.
 
void SetDirty ()
 
void SetTool (TOOL_INTERACTIVE *aTool)
 Set a tool that is the creator of the menu.
 
ACTION_MENUClone () const
 Create a deep, recursive copy of this ACTION_MENU.
 
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.
 
static constexpr bool NORMAL = false
 
static constexpr bool CHECK = true
 

Protected Member Functions

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

Protected Attributes

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

Private Member Functions

void addEntry (ENTRY aEntry)
 List of all menu entries.
 

Private Attributes

std::list< ENTRYm_entries
 

Detailed Description

Definition at line 41 of file conditional_menu.h.

Constructor & Destructor Documentation

◆ CONDITIONAL_MENU()

CONDITIONAL_MENU::CONDITIONAL_MENU ( TOOL_INTERACTIVE * aTool)

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

References ACTION_MENU(), KIUI::AddBitmapToMenuItem(), KiBitmapBundle(), m_icon, m_submenus, and 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

Definition at line 180 of file action_menu.cpp.

References KIUI::AddBitmapToMenuItem(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetMenuItem(), TOOL_ACTION::GetTooltip(), TOOL_ACTION::GetUIId(), KiBitmapBundle(), and 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 165 of file action_menu.cpp.

References KIUI::AddBitmapToMenuItem(), and KiBitmapBundle().

◆ Add() [4/4]

◆ AddCheckItem() [1/2]

void CONDITIONAL_MENU::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.

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

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

Referenced by DRAWING_TOOL::Init(), and PCB_VIEWER_TOOLS::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 )

Definition at line 77 of file conditional_menu.cpp.

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

◆ AddClose()

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

◆ addEntry()

void CONDITIONAL_MENU::addEntry ( ENTRY aEntry)
private

◆ AddItem() [1/2]

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

◆ 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 )

Definition at line 64 of file conditional_menu.cpp.

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

◆ AddMenu()

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

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

References ACTION_MENU::ACTION_MENU(), and addEntry().

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

◆ AddQuit()

void ACTION_MENU::AddQuit ( const wxString & aAppname = "")
inherited

Add a standard Quit item to the menu.

Emits the wxID_EXIT event.

Parameters
aAppnameis the application name to append to the tooltip.

Definition at line 254 of file action_menu.cpp.

References _, Add(), and exit.

Referenced by BITMAP2CMP_FRAME::doReCreateMenuBar(), PCB_CALCULATOR_FRAME::doReCreateMenuBar(), and PL_EDITOR_FRAME::doReCreateMenuBar().

◆ 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_EXIT) is used, otherwise close (wxID_CLOSE) is used.

Parameters
aAppnameis the application name to append to the tooltip.

Definition at line 236 of file action_menu.cpp.

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

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

◆ AddSeparator() [1/2]

void CONDITIONAL_MENU::AddSeparator ( const SELECTION_CONDITION & aCondition,
int aOrder = ANY_ORDER )

Definition at line 103 of file conditional_menu.cpp.

References addEntry().

◆ AddSeparator() [2/2]

◆ appendCopy()

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

Append a copy of wxMenuItem.

Definition at line 656 of file action_menu.cpp.

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

Referenced by 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 308 of file action_menu.cpp.

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

Referenced by ClearDirty().

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

References ACTION_MENU(), appendCopy(), m_icon, m_selected, m_title, m_titleDisplayed, m_tool, and m_toolActions.

Referenced by Clone().

◆ create()

ACTION_MENU * CONDITIONAL_MENU::create ( ) const
overridevirtual

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

Reimplemented from ACTION_MENU.

Reimplemented in LOCK_CONTEXT_MENU.

Definition at line 40 of file conditional_menu.cpp.

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

References KIUI::AddBitmapToMenuItem(), GetTitle(), KiBitmapBundle(), m_icon, m_title, and m_titleDisplayed.

Referenced by SELECTION_TOOL::doSelectionMenu(), DRAWING_TOOL::DrawVia(), and 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 DIFF_PAIR_MENU, GRID_MENU, SEARCH_PANE_MENU, TRACK_WIDTH_MENU, VIA_SIZE_MENU, and ZOOM_MENU.

Definition at line 224 of file action_menu.h.

Referenced by OnMenuEvent(), and runEventHandlers().

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int aId)
protectedinherited

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

Definition at line 613 of file action_menu.cpp.

References ACTION_MENU(), and runOnSubmenus().

Referenced by 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 160 of file action_menu.h.

References m_selected.

◆ GetTitle()

wxString ACTION_MENU::GetTitle ( ) const
inlineinherited

Definition at line 66 of file action_menu.h.

References m_title.

Referenced by DisplayTitle().

◆ getToolManager()

◆ HasEnabledItems()

bool ACTION_MENU::HasEnabledItems ( ) const
inherited

Return true if the menu has any enabled items.

Definition at line 279 of file action_menu.cpp.

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent & event)
inherited

Definition at line 406 of file action_menu.cpp.

References g_last_menu_highlighted_id, and g_menu_open_position.

Referenced by setupEvents(), and ~ACTION_MENU().

◆ OnMenuEvent()

◆ PassHelpTextToHandler()

virtual bool ACTION_MENU::PassHelpTextToHandler ( )
inlinevirtualinherited

Reimplemented in BUS_UNFOLD_MENU.

Definition at line 196 of file action_menu.h.

Referenced by OnMenuEvent().

◆ Resolve()

void CONDITIONAL_MENU::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).

Definition at line 112 of file conditional_menu.cpp.

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

Referenced by Resolve().

◆ runEventHandlers()

void ACTION_MENU::runEventHandlers ( const wxMenuEvent & aMenuEvent,
OPT_TOOL_EVENT & aToolEvent )
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 587 of file action_menu.cpp.

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

Referenced by OnMenuEvent(), and runEventHandlers().

◆ runOnSubmenus()

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

Run a function on the menu and all its submenus.

Definition at line 596 of file action_menu.cpp.

References ACTION_MENU(), and m_submenus.

Referenced by ClearDirty(), CONDITIONAL_MENU::Evaluate(), findToolAction(), CONDITIONAL_MENU::Resolve(), runEventHandlers(), SetDirty(), SetTool(), and UpdateAll().

◆ SetDirty()

void ACTION_MENU::SetDirty ( )
inherited

Definition at line 315 of file action_menu.cpp.

References m_dirty, runOnSubmenus(), and SetDirty().

Referenced by SetDirty().

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

References m_tool, runOnSubmenus(), SetTool(), and TOOL_INTERACTIVE.

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

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protectedinherited

Initialize handlers for events.

Definition at line 95 of file action_menu.cpp.

References OnIdle(), and OnMenuEvent().

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

Definition at line 214 of file action_menu.h.

Referenced by UpdateAll().

◆ UpdateAll()

◆ updateHotKeys()

void ACTION_MENU::updateHotKeys ( )
protectedinherited

Update hot key settings for TOOL_ACTIONs in this menu.

Definition at line 355 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().

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

Member Data Documentation

◆ 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 45 of file conditional_menu.h.

◆ CHECK

◆ m_dirty

bool ACTION_MENU::m_dirty
protectedinherited

Definition at line 261 of file action_menu.h.

Referenced by ACTION_MENU(), ClearDirty(), OnMenuEvent(), and SetDirty().

◆ m_entries

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

Definition at line 254 of file conditional_menu.h.

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

◆ m_forcedPosition

wxPoint ACTION_MENU::m_forcedPosition
protectedinherited

Definition at line 259 of file action_menu.h.

◆ m_icon

BITMAPS ACTION_MENU::m_icon
protectedinherited

Optional icon.

Definition at line 270 of file action_menu.h.

Referenced by ACTION_MENU(), Add(), copyFrom(), DisplayTitle(), and SetIcon().

◆ m_isContextMenu

bool ACTION_MENU::m_isContextMenu
protectedinherited

Definition at line 264 of file action_menu.h.

Referenced by ACTION_MENU(), and OnMenuEvent().

◆ m_isForcedPosition

bool ACTION_MENU::m_isForcedPosition
protectedinherited

Definition at line 258 of file action_menu.h.

Referenced by ACTION_MENU().

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Store the id number of selected item.

Definition at line 273 of file action_menu.h.

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

◆ m_submenus

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

List of submenus.

Definition at line 282 of file action_menu.h.

Referenced by Add(), appendCopy(), Clear(), runOnSubmenus(), and ~ACTION_MENU().

◆ m_title

wxString ACTION_MENU::m_title
protectedinherited

Menu title.

Definition at line 267 of file action_menu.h.

Referenced by Add(), copyFrom(), DisplayTitle(), GetTitle(), and SetTitle().

◆ m_titleDisplayed

bool ACTION_MENU::m_titleDisplayed
protectedinherited

Definition at line 263 of file action_menu.h.

Referenced by ACTION_MENU(), Clear(), copyFrom(), DisplayTitle(), and SetTitle().

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

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

◆ NORMAL

bool ACTION_MENU::NORMAL = false
staticconstexprinherited

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