From e17cd5abc604290620a2883fd350902e44f31b65 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 30 Jun 2023 00:06:03 +0100 Subject: [PATCH] Allow action description to be different from tooltip The tooltip should be short and easy to read, the description can be longer and more detailed. --- common/dialogs/panel_hotkeys_editor.cpp | 2 +- common/tool/action_menu.cpp | 2 +- common/tool/action_toolbar.cpp | 8 ++++---- common/tool/tool_action.cpp | 15 ++++++++++++++- common/widgets/widget_hotkey_list.cpp | 2 +- include/tool/tool_action.h | 19 ++++++++++++++++--- kicad/dialogs/panel_kicad_launcher.cpp | 4 ++-- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/common/dialogs/panel_hotkeys_editor.cpp b/common/dialogs/panel_hotkeys_editor.cpp index 6ac7f13c5a..3d76ee075a 100644 --- a/common/dialogs/panel_hotkeys_editor.cpp +++ b/common/dialogs/panel_hotkeys_editor.cpp @@ -248,7 +248,7 @@ void PANEL_HOTKEYS_EDITOR::dumpHotkeys() stream << wxT( " |" ) << endl; } - stream << wxT( " | " ) << hk.m_Actions[0]->GetDescription( false ) << endl; + stream << wxT( " | " ) << hk.m_Actions[0]->GetDescription() << endl; } stream << wxT( "|===" ) << endl << endl; diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 20ee35d807..ee6ead6d09 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -170,7 +170,7 @@ wxMenuItem* ACTION_MENU::Add( const TOOL_ACTION& aAction, bool aIsCheckmarkEntry wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.GetMenuItem() : aOverrideLabel; wxMenuItem* item = new wxMenuItem( this, aAction.GetUIId(), menuLabel, - aAction.GetDescription(), + aAction.GetTooltip(), aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL ); if( !!icon ) AddBitmapToMenuItem( item, KiBitmap( icon ) ); diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index 61db032ac4..f24c405e01 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -130,7 +130,7 @@ void ACTION_TOOLBAR_PALETTE::AddAction( const TOOL_ACTION& aAction ) button->SetBitmap( normalBmp ); button->SetDisabledBitmap( disabledBmp ); button->SetPadding( padding ); - button->SetToolTip( aAction.GetDescription() ); + button->SetToolTip( aAction.GetTooltip() ); button->AcceptDragInAsClick(); m_buttons[aAction.GetUIId()] = button; @@ -237,7 +237,7 @@ void ACTION_TOOLBAR::Add( const TOOL_ACTION& aAction, bool aIsToggleEntry, bool AddTool( toolId, wxEmptyString, bmp, MakeDisabledBitmap( bmp ), aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, - aAction.GetDescription(), wxEmptyString, nullptr ); + aAction.GetTooltip(), wxEmptyString, nullptr ); m_toolKinds[ toolId ] = aIsToggleEntry; m_toolActions[ toolId ] = &aAction; @@ -251,7 +251,7 @@ void ACTION_TOOLBAR::AddButton( const TOOL_ACTION& aAction ) wxBitmap bmp = KiScaledBitmap( aAction.GetIcon(), GetParent() ); AddTool( toolId, wxEmptyString, bmp, MakeDisabledBitmap( bmp ), - wxITEM_NORMAL, aAction.GetDescription(), wxEmptyString, nullptr ); + wxITEM_NORMAL, aAction.GetTooltip(), wxEmptyString, nullptr ); m_toolKinds[ toolId ] = false; m_toolActions[ toolId ] = &aAction; @@ -333,7 +333,7 @@ void ACTION_TOOLBAR::doSelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aA return; // Update the item information - item->SetShortHelp( aAction.GetDescription() ); + item->SetShortHelp( aAction.GetTooltip() ); item->SetBitmap( KiScaledBitmap( aAction.GetIcon(), GetParent() ) ); #if wxCHECK_VERSION( 3, 1, 6 ) item->SetDisabledBitmap( diff --git a/common/tool/tool_action.cpp b/common/tool/tool_action.cpp index 744a2b897e..5e29c6e4c3 100644 --- a/common/tool/tool_action.cpp +++ b/common/tool/tool_action.cpp @@ -85,6 +85,9 @@ TOOL_ACTION::TOOL_ACTION( const TOOL_ACTION_ARGS& aArgs ) : if( aArgs.m_param.has_value() ) m_param = aArgs.m_param; + if( aArgs.m_description.has_value() ) + m_description = aArgs.m_description; + ACTION_MANAGER::GetActionList().push_back( this ); } @@ -127,7 +130,17 @@ wxString TOOL_ACTION::GetMenuItem() const } -wxString TOOL_ACTION::GetDescription( bool aIncludeHotkey ) const +wxString TOOL_ACTION::GetDescription() const +{ + // If no description provided, use the tooltip without a hotkey + if( !m_description.has_value() ) + return GetTooltip( false ); + + return wxGetTranslation( m_description.value() ); +} + + +wxString TOOL_ACTION::GetTooltip( bool aIncludeHotkey ) const { wxString tooltip = wxGetTranslation( m_tooltip ); diff --git a/common/widgets/widget_hotkey_list.cpp b/common/widgets/widget_hotkey_list.cpp index 7fffacb50a..9c4e0eaa60 100644 --- a/common/widgets/widget_hotkey_list.cpp +++ b/common/widgets/widget_hotkey_list.cpp @@ -291,7 +291,7 @@ void WIDGET_HOTKEY_LIST::updateFromClientData() const HOTKEY& changed_hk = hkdata->GetChangedHotkey(); wxString label = changed_hk.m_Actions[ 0 ]->GetLabel(); wxString key_text = KeyNameFromKeyCode( changed_hk.m_EditKeycode ); - wxString description = changed_hk.m_Actions[ 0 ]->GetDescription( false ); + wxString description = changed_hk.m_Actions[ 0 ]->GetDescription(); if( label.IsEmpty() ) label = changed_hk.m_Actions[ 0 ]->GetName(); diff --git a/include/tool/tool_action.h b/include/tool/tool_action.h index 117c8f0c09..bc9f9c88c9 100644 --- a/include/tool/tool_action.h +++ b/include/tool/tool_action.h @@ -122,6 +122,15 @@ public: return *this; } + /** + * The description of the action. + */ + TOOL_ACTION_ARGS& Description( wxString aDescription ) + { + m_description = aDescription; + return *this; + } + /** * The bitmap to use as the icon for the action in toolbars and menus. */ @@ -174,6 +183,7 @@ protected: std::optional m_menuText; std::optional m_tooltip; + std::optional m_description; std::optional m_icon; @@ -275,7 +285,8 @@ public: wxString GetLabel() const; wxString GetMenuItem() const; - wxString GetDescription( bool aIncludeHotkey = true ) const; + wxString GetTooltip( bool aIncludeHotkey = true ) const; + wxString GetDescription() const; TOOL_ACTION_SCOPE GetScope() const { return m_scope; } @@ -353,8 +364,10 @@ protected: int m_hotKey; // The current hotkey (post-user-settings-application) const std::string m_legacyName; // Name for reading legacy hotkey settings - wxString m_label; - wxString m_tooltip; + wxString m_label; // Menu label + wxString m_tooltip; // User-facing tooltip help text + std::optional m_description; // Description of the action + BITMAPS m_icon; // Icon for the menu entry int m_id; // Unique ID for maps. Assigned by ACTION_MANAGER. diff --git a/kicad/dialogs/panel_kicad_launcher.cpp b/kicad/dialogs/panel_kicad_launcher.cpp index ce63e42f5b..3b09061f1c 100644 --- a/kicad/dialogs/panel_kicad_launcher.cpp +++ b/kicad/dialogs/panel_kicad_launcher.cpp @@ -68,7 +68,7 @@ void PANEL_KICAD_LAUNCHER::CreateLaunchers() btn->SetBitmap( aBitmap ); btn->SetDisabledBitmap( wxBitmap( aBitmap.ConvertToImage().ConvertToGreyscale() ) ); btn->SetPadding( 5 ); - btn->SetToolTip( aAction.GetDescription() ); + btn->SetToolTip( aAction.GetTooltip() ); auto handler = [&]( wxEvent& aEvent ) @@ -88,7 +88,7 @@ void PANEL_KICAD_LAUNCHER::CreateLaunchers() wxStaticText* label = new wxStaticText( this, wxID_ANY, aAction.GetLabel() ); wxStaticText* help; - label->SetToolTip( aAction.GetDescription() ); + label->SetToolTip( aAction.GetTooltip() ); label->SetFont( titleFont ); help = new wxStaticText( this, wxID_ANY, aHelpText );