Component chooser: show aliases better

- In the listing, display alias names in italics
- In the info panel, display per-alias description correctly, as well as
  root description

Fixes: lp:1676190
* https://bugs.launchpad.net/kicad/+bug/1676190
This commit is contained in:
Chris Pavlina 2017-03-27 07:54:51 -04:00
parent cfac7bd31c
commit d2b0a4b358
3 changed files with 56 additions and 24 deletions

View File

@ -310,6 +310,33 @@ void CMP_TREE_MODEL_ADAPTER::GetValue(
}
bool CMP_TREE_MODEL_ADAPTER::GetAttr(
wxDataViewItem const& aItem,
unsigned int aCol,
wxDataViewItemAttr& aAttr ) const
{
auto node = ToNode( aItem );
wxASSERT( node );
if( node->Type != CMP_TREE_NODE::ALIAS )
{
// Currently only aliases are formatted at all
return false;
}
if( node->Alias && !node->Alias->IsRoot() && aCol == 0 )
{
// Names of non-root aliases are italicized
aAttr.SetItalic( true );
return true;
}
else
{
return false;
}
}
int CMP_TREE_MODEL_ADAPTER::ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString const& aHeading )
{
const int indent = aCol ? 0 : kDataViewIndent;

View File

@ -87,6 +87,7 @@ class PART_LIBS;
* - `GetColumnType()` - get the data type shown in each column
* - `GetValue()` - get the data shown in a cell
* - `SetValue()` - edit the data in a cell (does nothing)
* - `GetAttr()` - get any per-item formatting
* - `Compare()` - compare two rows, for sorting
* - `HasDefaultCompare()` - whether sorted by default
*/
@ -288,6 +289,19 @@ protected:
wxDataViewItem const& aItem,
unsigned int aCol ) override { return false; }
/**
* Get any formatting for an item.
*
* @param aItem item to get formatting for
* @param aCol column number of interest
* @param aAttr receiver for attributes
* @return true iff the item has non-default attributes
*/
virtual bool GetAttr(
wxDataViewItem const& aItem,
unsigned int aCol,
wxDataViewItemAttr& aAttr ) const override;
private:
CMP_FILTER_TYPE m_filter;
bool m_show_units;

View File

@ -31,7 +31,7 @@ static const wxString DescriptionFormat =
"__FIELDS__"
"</table>";
static const wxString AliasOfFormat = "<br><i>" + _( "Alias of " ) + "%s</i>";
static const wxString AliasOfFormat = "<br><i>" + _( "Alias of " ) + "%s (%s)</i>";
static const wxString DescFormat = "<br>%s";
static const wxString KeywordsFormat = "<br>" + _( "Keywords:" ) + " %s";
static const wxString FieldFormat =
@ -90,37 +90,28 @@ protected:
}
else
{
wxString root_name = _( "Unknown" );
wxString root_desc = "";
LIB_PART* root = m_part->GetPart();
const wxString root_name = ( root ? root->GetName() : _( "Unknown" ) );
LIB_ALIAS* root_alias = root ? root->GetAlias( 0 ) : nullptr;
if( root )
root_name = root->GetName();
if( root_alias )
root_desc = root_alias->GetDescription();
m_html.Replace(
"__ALIASOF__", wxString::Format( AliasOfFormat, EscapedHTML( root_name ) ) );
"__ALIASOF__", wxString::Format(
AliasOfFormat, EscapedHTML( root_name ), EscapedHTML( root_desc ) ) );
}
}
void SetHtmlDesc()
{
wxString raw_desc;
if( m_part->IsRoot() )
{
raw_desc = m_part->GetDescription();
}
else
{
LIB_PART* root = m_part->GetPart();
for( size_t i = 0; i < root->GetAliasCount(); ++i )
{
LIB_ALIAS* alias = root->GetAlias( i );
if( alias && !alias->GetDescription().empty() )
{
raw_desc = alias->GetDescription();
break;
}
}
}
wxString raw_desc = m_part->GetDescription();
m_html.Replace( "__DESC__", wxString::Format( DescFormat, EscapedHTML( raw_desc ) ) );
}