Display descriptions in second column of library trees.
Also fixes some bugs in how the columns are sized. Fixes https://gitlab.com/kicad/code/kicad/issues/12090
This commit is contained in:
parent
ee8116e55f
commit
753f2f3e4c
|
@ -79,11 +79,11 @@ LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent,
|
||||||
m_widget( nullptr )
|
m_widget( nullptr )
|
||||||
{
|
{
|
||||||
// Default column widths
|
// Default column widths
|
||||||
m_colWidths[PART_COL] = 360;
|
m_colWidths[NAME_COL] = 300;
|
||||||
m_colWidths[DESC_COL] = 2000;
|
m_colWidths[DESC_COL] = 2000;
|
||||||
|
|
||||||
APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings();
|
APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings();
|
||||||
m_colWidths[PART_COL] = cfg->m_LibTree.column_width;
|
m_colWidths[NAME_COL] = cfg->m_LibTree.column_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ void LIB_TREE_MODEL_ADAPTER::SaveColWidths()
|
||||||
if( m_widget )
|
if( m_widget )
|
||||||
{
|
{
|
||||||
APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings();
|
APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings();
|
||||||
cfg->m_LibTree.column_width = m_widget->GetColumn( PART_COL )->GetWidth();
|
cfg->m_LibTree.column_width = m_widget->GetColumn( NAME_COL )->GetWidth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,28 +236,30 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
|
||||||
|
|
||||||
void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
|
void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
|
||||||
{
|
{
|
||||||
wxString partHead = _( "Item" );
|
wxString itemHead = _( "Item" );
|
||||||
wxString descHead = _( "Description" );
|
wxString descHead = _( "Description" );
|
||||||
|
|
||||||
// The extent of the text doesn't take into account the space on either side
|
// The extent of the text doesn't take into account the space on either side
|
||||||
// in the header, so artificially pad it
|
// in the header, so artificially pad it
|
||||||
wxSize partHeadMinWidth = KIUI::GetTextSize( partHead + "MMM", aDataViewCtrl );
|
wxSize itemHeadMinWidth = KIUI::GetTextSize( itemHead + wxT( "MMM" ), aDataViewCtrl );
|
||||||
|
wxSize descHeadMinWidth = KIUI::GetTextSize( descHead + wxT( "MMM" ), aDataViewCtrl );
|
||||||
|
|
||||||
// Ensure the part column is wider than the smallest allowable width
|
// Ensure the part column is wider than the smallest allowable width
|
||||||
if( m_colWidths[PART_COL] < partHeadMinWidth.x )
|
if( m_colWidths[NAME_COL] < itemHeadMinWidth.x )
|
||||||
m_colWidths[PART_COL] = partHeadMinWidth.x;
|
m_colWidths[NAME_COL] = itemHeadMinWidth.x;
|
||||||
|
|
||||||
m_widget = aDataViewCtrl;
|
m_widget = aDataViewCtrl;
|
||||||
aDataViewCtrl->SetIndent( kDataViewIndent );
|
aDataViewCtrl->SetIndent( kDataViewIndent );
|
||||||
aDataViewCtrl->AssociateModel( this );
|
aDataViewCtrl->AssociateModel( this );
|
||||||
aDataViewCtrl->ClearColumns();
|
aDataViewCtrl->ClearColumns();
|
||||||
|
|
||||||
m_col_part = aDataViewCtrl->AppendTextColumn( partHead, PART_COL, wxDATAVIEW_CELL_INERT,
|
m_col_part = aDataViewCtrl->AppendTextColumn( itemHead, NAME_COL, wxDATAVIEW_CELL_INERT,
|
||||||
m_colWidths[PART_COL] );
|
m_colWidths[NAME_COL] );
|
||||||
m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT,
|
m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT,
|
||||||
m_colWidths[DESC_COL] );
|
m_colWidths[DESC_COL] );
|
||||||
|
|
||||||
m_col_part->SetMinWidth( partHeadMinWidth.x );
|
m_col_part->SetMinWidth( itemHeadMinWidth.x );
|
||||||
|
m_col_desc->SetMinWidth( descHeadMinWidth.x );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -350,7 +352,14 @@ unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren( const wxDataViewItem& aItem,
|
||||||
|
|
||||||
void LIB_TREE_MODEL_ADAPTER::FinishTreeInitialization()
|
void LIB_TREE_MODEL_ADAPTER::FinishTreeInitialization()
|
||||||
{
|
{
|
||||||
m_col_part->SetWidth( m_colWidths[PART_COL] );
|
m_col_part->SetWidth( m_colWidths[NAME_COL] );
|
||||||
|
m_col_desc->SetWidth( m_colWidths[DESC_COL] );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LIB_TREE_MODEL_ADAPTER::OnSize( wxSizeEvent& aEvent )
|
||||||
|
{
|
||||||
|
m_colWidths[NAME_COL] = m_col_part->GetWidth();
|
||||||
m_col_desc->SetWidth( m_colWidths[DESC_COL] );
|
m_col_desc->SetWidth( m_colWidths[DESC_COL] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,14 +378,14 @@ void LIB_TREE_MODEL_ADAPTER::RefreshTree()
|
||||||
// GTK returns the displayed width of the column, which is not calculated immediately
|
// GTK returns the displayed width of the column, which is not calculated immediately
|
||||||
if( descWidth > 0 )
|
if( descWidth > 0 )
|
||||||
{
|
{
|
||||||
m_colWidths[PART_COL] = partWidth;
|
m_colWidths[NAME_COL] = partWidth;
|
||||||
m_colWidths[DESC_COL] = descWidth;
|
m_colWidths[DESC_COL] = descWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_colWidths[PART_COL] += walk;
|
m_colWidths[NAME_COL] += walk;
|
||||||
m_colWidths[DESC_COL] -= walk;
|
m_colWidths[DESC_COL] -= walk;
|
||||||
|
|
||||||
m_col_part->SetWidth( m_colWidths[PART_COL] );
|
m_col_part->SetWidth( m_colWidths[NAME_COL] );
|
||||||
m_col_desc->SetWidth( m_colWidths[DESC_COL] );
|
m_col_desc->SetWidth( m_colWidths[DESC_COL] );
|
||||||
walk = -walk;
|
walk = -walk;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,7 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable,
|
||||||
|
|
||||||
SetSizer( sizer );
|
SetSizer( sizer );
|
||||||
|
|
||||||
|
m_tree_ctrl->Bind( wxEVT_SIZE, &LIB_TREE::onSize, this );
|
||||||
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
|
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
|
||||||
m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
|
m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
|
||||||
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
|
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
|
||||||
|
@ -472,6 +473,12 @@ void LIB_TREE::onTreeActivate( wxDataViewEvent& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LIB_TREE::onSize( wxSizeEvent& aEvent )
|
||||||
|
{
|
||||||
|
m_adapter->OnSize( aEvent );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void LIB_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent )
|
void LIB_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent )
|
||||||
{
|
{
|
||||||
const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
|
const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
|
||||||
|
|
|
@ -194,10 +194,20 @@ void SYMBOL_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem co
|
||||||
LIB_TREE_NODE* node = ToNode( aItem );
|
LIB_TREE_NODE* node = ToNode( aItem );
|
||||||
wxASSERT( node );
|
wxASSERT( node );
|
||||||
|
|
||||||
if( aCol == 0 && node->m_Pinned )
|
switch( aCol )
|
||||||
aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
|
{
|
||||||
else
|
case NAME_COL:
|
||||||
aVariant = UnescapeString( node->m_Name );
|
if( node->m_Pinned )
|
||||||
|
aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
|
||||||
|
else
|
||||||
|
aVariant = UnescapeString( node->m_Name );
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DESC_COL:
|
||||||
|
aVariant = node->m_Desc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataVie
|
||||||
|
|
||||||
switch( aCol )
|
switch( aCol )
|
||||||
{
|
{
|
||||||
case 0:
|
case NAME_COL:
|
||||||
if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
|
if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
|
||||||
node->m_Name = m_frame->GetCurSymbol()->GetLibId().GetLibItemName();
|
node->m_Name = m_frame->GetCurSymbol()->GetLibId().GetLibItemName();
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataVie
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case DESC_COL:
|
||||||
if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
|
if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
|
||||||
{
|
{
|
||||||
node->m_Desc = m_frame->GetCurSymbol()->GetDescription();
|
node->m_Desc = m_frame->GetCurSymbol()->GetDescription();
|
||||||
|
@ -294,7 +294,7 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un
|
||||||
}
|
}
|
||||||
|
|
||||||
// The remaining attributes are only for the name column
|
// The remaining attributes are only for the name column
|
||||||
if( aCol != 0 )
|
if( aCol != NAME_COL )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LIB_SYMBOL* curSymbol = m_frame->GetCurSymbol();
|
LIB_SYMBOL* curSymbol = m_frame->GetCurSymbol();
|
||||||
|
|
|
@ -127,8 +127,8 @@ public:
|
||||||
*/
|
*/
|
||||||
enum TREE_COLS
|
enum TREE_COLS
|
||||||
{
|
{
|
||||||
PART_COL = 0, ///< Part name column
|
NAME_COL = 0, ///< Library or library item name column
|
||||||
DESC_COL, ///< Part description column
|
DESC_COL, ///< Library or library description column
|
||||||
NUM_COLS ///< The number of tree columns
|
NUM_COLS ///< The number of tree columns
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void FinishTreeInitialization();
|
void FinishTreeInitialization();
|
||||||
|
|
||||||
|
void OnSize( wxSizeEvent& aEvent );
|
||||||
/**
|
/**
|
||||||
* Return the alias for the given item.
|
* Return the alias for the given item.
|
||||||
*
|
*
|
||||||
|
|
|
@ -171,6 +171,7 @@ protected:
|
||||||
|
|
||||||
void onTreeSelect( wxDataViewEvent& aEvent );
|
void onTreeSelect( wxDataViewEvent& aEvent );
|
||||||
void onTreeActivate( wxDataViewEvent& aEvent );
|
void onTreeActivate( wxDataViewEvent& aEvent );
|
||||||
|
void onSize( wxSizeEvent& aEvent );
|
||||||
|
|
||||||
void onDetailsLink( wxHtmlLinkEvent& aEvent );
|
void onDetailsLink( wxHtmlLinkEvent& aEvent );
|
||||||
void onPreselect( wxCommandEvent& aEvent );
|
void onPreselect( wxCommandEvent& aEvent );
|
||||||
|
|
|
@ -110,6 +110,21 @@ void FP_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const&
|
||||||
aVariant = GetPinningSymbol() + node->m_Name;
|
aVariant = GetPinningSymbol() + node->m_Name;
|
||||||
else
|
else
|
||||||
aVariant = node->m_Name;
|
aVariant = node->m_Name;
|
||||||
|
|
||||||
|
switch( aCol )
|
||||||
|
{
|
||||||
|
case NAME_COL:
|
||||||
|
if( node->m_Pinned )
|
||||||
|
aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
|
||||||
|
else
|
||||||
|
aVariant = UnescapeString( node->m_Name );
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DESC_COL:
|
||||||
|
aVariant = node->m_Desc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewIte
|
||||||
|
|
||||||
switch( aCol )
|
switch( aCol )
|
||||||
{
|
{
|
||||||
case 0:
|
case NAME_COL:
|
||||||
if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
|
if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
|
||||||
{
|
{
|
||||||
// Do not use GetLoadedFPID(); it returns m_footprintNameWhenLoaded.
|
// Do not use GetLoadedFPID(); it returns m_footprintNameWhenLoaded.
|
||||||
|
@ -203,7 +203,7 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewIte
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case DESC_COL:
|
||||||
if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
|
if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
|
||||||
{
|
{
|
||||||
node->m_Desc = m_frame->GetBoard()->GetFirstFootprint()->GetDescription();
|
node->m_Desc = m_frame->GetBoard()->GetFirstFootprint()->GetDescription();
|
||||||
|
|
Loading…
Reference in New Issue