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.
This commit is contained in:
Ian McInerney 2023-06-30 00:06:03 +01:00
parent 8b8586f54b
commit e17cd5abc6
7 changed files with 39 additions and 13 deletions

View File

@ -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;

View File

@ -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 ) );

View File

@ -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(

View File

@ -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 );

View File

@ -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();

View File

@ -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<wxString> m_menuText;
std::optional<wxString> m_tooltip;
std::optional<wxString> m_description;
std::optional<BITMAPS> 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<wxString> 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.

View File

@ -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 );