From a30ae6a2373c0d434be0e42e8433a9531374fa2d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 10 Feb 2021 15:02:28 +0000 Subject: [PATCH] Pass un-pretty-printed bus names through menu help text. Fixes https://gitlab.com/kicad/code/kicad/issues/7412 --- common/tool/action_menu.cpp | 20 ++++++++++++-------- eeschema/tools/sch_line_wire_bus_tool.cpp | 12 +++++------- include/tool/action_menu.h | 2 ++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 4d28378a12..84d0658610 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -496,19 +496,23 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) runEventHandlers( aEvent, evt ); #endif - // Handling non-action menu entries (e.g. items in clarification list) - // in some context menus, that have IDs explicitly chosen between - // ID_POPUP_MENU_START and ID_POPUP_MENU_END - // Note also items in clarification list have an id >= 0 and < wxID_LOWEST - // in fact 0 to n-1 for n items in clarification list) - // id < 0 are automatically created for menuitems created with wxID_ANY - #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be enough and better */ + // Handling non-ACTION menu entries. Two ranges of ids are supported: + // between 0 and ID_CONTEXT_MENU_ID_MAX + // between ID_POPUP_MENU_START and ID_POPUP_MENU_END + + #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be plenty */ if( !evt && ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) || ( m_selected >= ID_POPUP_MENU_START && m_selected <= ID_POPUP_MENU_END ) ) ) { - menuText = GetLabelText( aEvent.GetId() ); + ACTION_MENU* actionMenu = dynamic_cast( GetParent() ); + + if( actionMenu && actionMenu->PassHelpTextToHandler() ) + menuText = GetHelpString( aEvent.GetId() ); + else + menuText = GetLabelText( aEvent.GetId() ); + evt = TOOL_EVENT( TC_COMMAND, TA_CHOICE_MENU_CHOICE, m_selected, AS_GLOBAL, &menuText ); } diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index df287bf44c..840fad40bd 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -49,7 +49,6 @@ #include #include #include - #include #include #include @@ -61,10 +60,8 @@ #include #include #include - #include #include -#include #include #include @@ -84,6 +81,7 @@ public: m_showTitle = true; } + bool PassHelpTextToHandler() override { return true; } protected: ACTION_MENU* create() const override @@ -139,19 +137,19 @@ private: for( const auto& member : connection->Members() ) { int id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ ); - wxString name = SCH_CONNECTION::PrintBusForUI( member->FullLocalName() ); + wxString name = member->FullLocalName(); if( member->Type() == CONNECTION_TYPE::BUS ) { ACTION_MENU* submenu = new ACTION_MENU( true ); submenu->SetTool( m_tool ); - AppendSubMenu( submenu, name ); + AppendSubMenu( submenu, SCH_CONNECTION::PrintBusForUI( name ), name ); for( const auto& sub_member : member->Members() ) { id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ ); - name = SCH_CONNECTION::PrintBusForUI( sub_member->FullLocalName() ); - submenu->Append( id, name, wxEmptyString ); + name = sub_member->FullLocalName(); + submenu->Append( id, SCH_CONNECTION::PrintBusForUI( name ), name ); } } else diff --git a/include/tool/action_menu.h b/include/tool/action_menu.h index e0de6c3b60..727b4294cb 100644 --- a/include/tool/action_menu.h +++ b/include/tool/action_menu.h @@ -170,6 +170,8 @@ public: void OnMenuEvent( wxMenuEvent& aEvent ); void OnIdle( wxIdleEvent& event ); + virtual bool PassHelpTextToHandler() { return false; } + static constexpr bool CHECK = true; protected: