Return control of Symbol and Footprint chooser col widths to user.

The auto-calculation wasn't working out and even with it some users
wanted control.

Fixes: lp:1796774
* https://bugs.launchpad.net/kicad/+bug/1796774
This commit is contained in:
Jeff Young 2019-08-26 11:57:07 +01:00
parent 67db6c49b5
commit 6b6e9eddee
13 changed files with 113 additions and 222 deletions

View File

@ -119,8 +119,7 @@ LIB_TREE_NODE::LIB_TREE_NODE()
Score( kLowestDefaultScore ),
Normalized( false ),
Unit( 0 ),
IsRoot( false ),
VisLen( 0 )
IsRoot( false )
{}

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2014-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -20,10 +20,7 @@
*/
#include <lib_tree_model_adapter.h>
#include <eda_pattern_match.h>
#include <wx/progdlg.h>
#include <wx/tokenzr.h>
#include <wx/wupdlock.h>
@ -97,17 +94,6 @@ void LIB_TREE_MODEL_ADAPTER::ShowUnits( bool aShow )
}
void LIB_TREE_MODEL_ADAPTER::UpdateWidth( int aCol )
{
auto col = m_widget->GetColumn( aCol );
if( col )
{
col->SetWidth( ColWidth( m_tree, aCol, col->GetTitle() ) );
}
}
void LIB_TREE_MODEL_ADAPTER::SetPreselectNode( LIB_ID const& aLibId, int aUnit )
{
m_preselect_lib_id = aLibId;
@ -119,18 +105,10 @@ void LIB_TREE_MODEL_ADAPTER::DoAddLibrary( wxString const& aNodeName, wxString c
std::vector<LIB_TREE_ITEM*> const& aItemList,
bool presorted )
{
auto& lib_node = m_tree.AddLib( aNodeName, aDesc );
LIB_TREE_NODE_LIB& lib_node = m_tree.AddLib( aNodeName, aDesc );
lib_node.VisLen = wxTheApp->GetTopWindow()->GetTextExtent( lib_node.Name ).x;
for( auto item: aItemList )
{
if( item )
{
auto& child_node = lib_node.AddItem( item );
child_node.VisLen = wxTheApp->GetTopWindow()->GetTextExtent( child_node.Name ).x;
}
}
for( LIB_TREE_ITEM* item: aItemList )
lib_node.AddItem( item );
lib_node.AssignIntrinsicRanks( presorted );
}
@ -200,29 +178,35 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch )
m_widget->EnsureVisible( item );
}
UpdateWidth( 0 );
}
void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
{
wxString partHead = _( "Item" );
int partWidth = 360;
wxString descHead = _( "Description" );
int descWidth = 2000;
if( aDataViewCtrl->GetColumnCount() > 0 )
{
partWidth = aDataViewCtrl->GetColumn( 0 )->GetWidth();
descWidth = aDataViewCtrl->GetColumn( 1 )->GetWidth();
}
m_widget = aDataViewCtrl;
aDataViewCtrl->SetIndent( kDataViewIndent );
aDataViewCtrl->AssociateModel( this );
aDataViewCtrl->ClearColumns();
wxString part_head = _( "Item" );
wxString desc_head = _( "Description" );
m_col_part = aDataViewCtrl->AppendTextColumn( part_head, 0, wxDATAVIEW_CELL_INERT, 360 );
m_col_desc = aDataViewCtrl->AppendTextColumn( desc_head, 1, wxDATAVIEW_CELL_INERT, 2000 );
m_col_part = aDataViewCtrl->AppendTextColumn( partHead, 0, wxDATAVIEW_CELL_INERT, partWidth );
m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, 1, wxDATAVIEW_CELL_INERT, descWidth );
}
LIB_ID LIB_TREE_MODEL_ADAPTER::GetAliasFor( const wxDataViewItem& aSelection ) const
{
auto node = ToNode( aSelection );
const LIB_TREE_NODE* node = ToNode( aSelection );
LIB_ID emptyId;
@ -235,14 +219,14 @@ LIB_ID LIB_TREE_MODEL_ADAPTER::GetAliasFor( const wxDataViewItem& aSelection ) c
int LIB_TREE_MODEL_ADAPTER::GetUnitFor( const wxDataViewItem& aSelection ) const
{
auto node = ToNode( aSelection );
const LIB_TREE_NODE* node = ToNode( aSelection );
return node ? node->Unit : 0;
}
LIB_TREE_NODE::TYPE LIB_TREE_MODEL_ADAPTER::GetTypeFor( const wxDataViewItem& aSelection ) const
{
auto node = ToNode( aSelection );
const LIB_TREE_NODE* node = ToNode( aSelection );
return node ? node->Type : LIB_TREE_NODE::INVALID;
}
@ -251,7 +235,7 @@ int LIB_TREE_MODEL_ADAPTER::GetItemCount() const
{
int n = 0;
for( auto& lib: m_tree.Children )
for( const std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.Children )
n += lib->Children.size();
return n;
@ -377,52 +361,6 @@ bool LIB_TREE_MODEL_ADAPTER::GetAttr( wxDataViewItem const& aItem,
}
int LIB_TREE_MODEL_ADAPTER::ColWidth( LIB_TREE_NODE& aTree, int aCol, wxString const& aHeading )
{
if( aCol == 0 )
{
int padding = m_widget->GetTextExtent( "M" ).x;
int indent = m_widget->GetIndent();
int longest = m_widget->GetTextExtent( aHeading ).x;
for( auto& node : aTree.Children )
{
auto item = ToItem( &*node );
if( !item.IsOk() )
continue;
if( node->Score > 0 )
{
// Ensure the text size is up to date:
if( node->VisLen == 0 )
node->VisLen = m_widget->GetTextExtent( node->Name ).x;
longest = std::max( longest, node->VisLen + padding + indent );
}
if( !m_widget->IsExpanded( item ) )
continue;
for( auto& childNode : node->Children )
{
if( childNode->Score > 0 )
{
if( childNode->VisLen == 0 )
childNode->VisLen = m_widget->GetTextExtent( childNode->Name ).x;
longest = std::max( longest, childNode->VisLen + padding + 2 * indent );
}
}
}
return longest;
}
else
return 2000;
}
void LIB_TREE_MODEL_ADAPTER::FindAndExpand( LIB_TREE_NODE& aNode,
std::function<bool( LIB_TREE_NODE const* )> aFunc,
LIB_TREE_NODE** aHighScore )

View File

@ -134,13 +134,6 @@ public:
*/
void ShowUnits( bool aShow );
/**
* Update the column size based on the displayed contents
*
* @param aCol Which column to resize
*/
void UpdateWidth( int aCol );
/**
* Set the component name to be selected if there are no search results.
* May be set at any time; updates at the next UpdateSearchString().
@ -329,16 +322,6 @@ private:
wxDataViewColumn* m_col_desc;
wxDataViewCtrl* m_widget;
/**
* Compute the width required for the given column of a node and its
* children.
*
* @param aTree - root node of the tree
* @param aCol - column number
* @param aHeading - heading text, to set the minimum width
*/
int ColWidth( LIB_TREE_NODE& aTree, int aCol, wxString const& aHeading );
/**
* Find any results worth highlighting and expand them, according to given
* criteria (f(CMP_TREE_NODE const*) -> bool)

View File

@ -1,4 +1,4 @@
/* -*- c++ -*-
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
@ -26,10 +26,13 @@
#include <wxdataviewctrl_helpers.h>
#include <wx/artprov.h>
#include <wx/sizer.h>
#include <wx/statbmp.h>
#include <wx/html/htmlwin.h>
#include <tool/tool_interactive.h>
#include <tool/tool_manager.h>
#include <kiface_i.h>
#define LIST_COLUMN_WIDTH_KEY wxT( "SelectorColumnWidth" )
LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAPTER::PTR& aAdapter,
WIDGETS aWidgets, wxHtmlWindow* aDetails )
@ -40,6 +43,9 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAP
m_query_ctrl( nullptr ),
m_details_ctrl( nullptr )
{
m_config = Kiface().KifaceSettings();
m_configPrefix = typeid( m_adapter ).name();
auto sizer = new wxBoxSizer( wxVERTICAL );
// Search text control
@ -73,7 +79,7 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAP
// Tree control
m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxDV_SINGLE | wxDV_NO_HEADER );
wxDV_SINGLE );
m_adapter->AttachTo( m_tree_ctrl );
if( aWidgets & DETAILS )
@ -107,11 +113,14 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAP
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_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_EXPANDED, &LIB_TREE::onExpandCollapse, this );
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_COLLAPSED, &LIB_TREE::onExpandCollapse, this );
Bind( COMPONENT_PRESELECTED, &LIB_TREE::onPreselect, this );
int colWidth = 0;
if( m_config->Read( m_configPrefix + LIST_COLUMN_WIDTH_KEY, &colWidth ) )
m_tree_ctrl->GetColumn( 0 )->SetWidth( colWidth );
// If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
// handler will intermittently fire.
if( m_query_ctrl )
@ -124,7 +133,6 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAP
// There may be a part preselected in the model. Make sure it is displayed.
postPreselectEvent();
m_adapter->UpdateWidth( 0 );
Layout();
sizer->Fit( this );
@ -138,6 +146,13 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAP
}
LIB_TREE::~LIB_TREE()
{
int colWidth = m_tree_ctrl->GetColumn( 0 )->GetWidth();
m_config->Write( m_configPrefix + LIST_COLUMN_WIDTH_KEY, colWidth );
}
LIB_ID LIB_TREE::GetSelectedLibId( int* aUnit ) const
{
auto sel = m_tree_ctrl->GetSelection();
@ -223,7 +238,6 @@ void LIB_TREE::selectIfValid( const wxDataViewItem& aTreeId )
if( aTreeId.IsOk() )
{
m_tree_ctrl->EnsureVisible( aTreeId );
m_adapter->UpdateWidth( 0 );
m_tree_ctrl->Select( aTreeId );
postPreselectEvent();
}
@ -233,10 +247,7 @@ void LIB_TREE::selectIfValid( const wxDataViewItem& aTreeId )
void LIB_TREE::centerIfValid( const wxDataViewItem& aTreeId )
{
if( aTreeId.IsOk() )
{
m_tree_ctrl->EnsureVisible( aTreeId );
m_adapter->UpdateWidth( 0 );
}
}
@ -360,12 +371,6 @@ void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent )
}
void LIB_TREE::onExpandCollapse( wxDataViewEvent& aEvent )
{
m_adapter->UpdateWidth( 0 );
}
void LIB_TREE::onTreeActivate( wxDataViewEvent& aEvent )
{
if( !GetSelectedLibId().IsValid() )

View File

@ -1,4 +1,4 @@
/* -*- c++ -*-
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
@ -58,6 +58,8 @@ public:
LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAPTER::PTR& aAdapter,
WIDGETS aWidgets = ALL, wxHtmlWindow *aDetails = nullptr );
~LIB_TREE() override;
/**
* For multi-unit components, if the user selects the component itself
* rather than picking an individual unit, 0 will be returned in aUnit.
@ -150,21 +152,23 @@ protected:
void onTreeSelect( wxDataViewEvent& aEvent );
void onTreeActivate( wxDataViewEvent& aEvent );
void onExpandCollapse( wxDataViewEvent& aEvent );
void onDetailsLink( wxHtmlLinkEvent& aEvent );
void onPreselect( wxCommandEvent& aEvent );
void onContextMenu( wxDataViewEvent& aEvent );
LIB_TABLE* m_lib_table;
protected:
wxConfigBase* m_config;
wxString m_configPrefix;
LIB_TABLE* m_lib_table;
LIB_TREE_MODEL_ADAPTER::PTR m_adapter;
wxTextCtrl* m_query_ctrl;
wxDataViewCtrl* m_tree_ctrl;
wxHtmlWindow* m_details_ctrl;
wxTextCtrl* m_query_ctrl;
wxDataViewCtrl* m_tree_ctrl;
wxHtmlWindow* m_details_ctrl;
///> State of the widget before any filters applied
STATE m_unfilteredState;
STATE m_unfilteredState;
};
///> Custom event sent when a new component is preselected

View File

@ -23,19 +23,14 @@
*/
#include <dialog_choose_component.h>
#include <algorithm>
#include <set>
#include <wx/utils.h>
#include <wx/button.h>
#include <wx/dataview.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/splitter.h>
#include <wx/timer.h>
#include <wx/utils.h>
#include <class_library.h>
#include <sch_base_frame.h>
#include <template_fieldnames.h>
@ -45,10 +40,13 @@
#include <widgets/footprint_select_widget.h>
#include <widgets/symbol_preview_widget.h>
#include <wx/clipbrd.h>
#include <kiface_i.h>
#define SYM_CHOOSER_HSASH wxT( "SymbolChooserHSashPosition" )
#define SYM_CHOOSER_VSASH wxT( "SymbolChooserVSashPosition" )
#define SYM_CHOOSER_WIDTH_KEY wxT( "SymbolChooserWidth" )
#define SYM_CHOOSER_HEIGHT_KEY wxT( "SymbolChooserHeight" )
wxSize DIALOG_CHOOSE_COMPONENT::m_last_dlg_size( -1, -1 );
int DIALOG_CHOOSE_COMPONENT::m_h_sash_pos = 0;
int DIALOG_CHOOSE_COMPONENT::m_v_sash_pos = 0;
std::mutex DIALOG_CHOOSE_COMPONENT::g_Mutex;
@ -72,6 +70,8 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const
m_show_footprints( aShowFootprints ),
m_external_browser_requested( false )
{
m_config = Kiface().KifaceSettings();
auto sizer = new wxBoxSizer( wxVERTICAL );
// Use a slightly different layout, with a details pane spanning the entire window,
@ -147,15 +147,14 @@ DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const
// We specify the width of the right window (m_symbol_view_panel), because specify
// the width of the left window does not work as expected when SetSashGravity() is called
m_hsplitter->SetSashPosition( m_h_sash_pos ? m_h_sash_pos : HorizPixelsFromDU( 240 ) );
m_hsplitter->SetSashPosition( m_config->Read( SYM_CHOOSER_HSASH, HorizPixelsFromDU( 220 ) ) );
if( m_vsplitter )
m_vsplitter->SetSashPosition( m_v_sash_pos ? m_v_sash_pos : VertPixelsFromDU( 170 ) );
m_vsplitter->SetSashPosition( m_config->Read( SYM_CHOOSER_VSASH, VertPixelsFromDU( 230 ) ) );
if( m_last_dlg_size == wxSize( -1, -1 ) )
SetSizeInDU( 360, 280 );
else
SetSize( m_last_dlg_size );
wxSize dlgSize( m_config->Read( SYM_CHOOSER_WIDTH_KEY, HorizPixelsFromDU( 390 ) ),
m_config->Read( SYM_CHOOSER_HEIGHT_KEY, VertPixelsFromDU( 300 ) ) );
SetSize( dlgSize );
SetInitialFocus( m_tree );
okButton->SetDefault();
@ -204,11 +203,13 @@ DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT()
m_dbl_click_timer->Stop();
delete m_dbl_click_timer;
m_last_dlg_size = GetSize();
m_h_sash_pos = m_hsplitter->GetSashPosition();
m_config->Write( SYM_CHOOSER_WIDTH_KEY, GetSize().x );
m_config->Write( SYM_CHOOSER_HEIGHT_KEY, GetSize().y );
m_config->Write( SYM_CHOOSER_HSASH, m_hsplitter->GetSashPosition() );
if( m_vsplitter )
m_v_sash_pos = m_vsplitter->GetSashPosition();
m_config->Write( SYM_CHOOSER_VSASH, m_vsplitter->GetSashPosition() );
}
@ -229,7 +230,6 @@ wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent )
if ( fp_list )
{
if( m_allow_field_edits )
m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( panel, fp_list, true );
@ -431,10 +431,13 @@ void DIALOG_CHOOSE_COMPONENT::OnFootprintSelected( wxCommandEvent& aEvent )
m_field_edits.erase(
std::remove_if( m_field_edits.begin(), m_field_edits.end(),
[]( std::pair<int, wxString> const& i ) { return i.first == FOOTPRINT; } ),
[]( std::pair<int, wxString> const& i )
{
return i.first == FOOTPRINT;
} ),
m_field_edits.end() );
m_field_edits.push_back( std::make_pair( FOOTPRINT, m_fp_override ) );
m_field_edits.emplace_back( std::make_pair( FOOTPRINT, m_fp_override ) );
ShowFootprint( m_fp_override );
}
@ -446,7 +449,6 @@ void DIALOG_CHOOSE_COMPONENT::OnComponentPreselected( wxCommandEvent& aEvent )
LIB_ID id = m_tree->GetSelectedLibId( &unit );
if( id.IsValid() )
{
m_symbol_preview->DisplaySymbol( id, unit );

View File

@ -1,8 +1,8 @@
/* -*- c++ -*-
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2014-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -70,9 +70,7 @@ class SCH_DRAW_PANEL;
* libNicknames = libs->GetLogicalLibs();
*
* for( auto nickname : libNicknames )
* {
* adapter->AddLibrary( nickname );
* }
*
* // Create and display dialog
* DIALOG_CHOOSE_COMPONENT dlg( this, title, adapter, 1 );
@ -183,11 +181,7 @@ protected:
*/
void PopulateFootprintSelector( LIB_ID const& aLibId );
/**
* Display a given symbol into the schematic symbol preview.
* when no symbol selected, display a tooltip
*/
void RenderPreview( LIB_PART* aComponent, int aUnit );
wxConfigBase* m_config;
wxTimer* m_dbl_click_timer;
SYMBOL_PREVIEW_WIDGET* m_symbol_preview;
@ -200,9 +194,6 @@ protected:
LIB_TREE* m_tree;
wxHtmlWindow* m_details;
static int m_h_sash_pos; // remember sash positions during a session
static int m_v_sash_pos;
SCH_BASE_FRAME* m_parent;
int m_deMorganConvert;
bool m_allow_field_edits;
@ -211,9 +202,6 @@ protected:
wxString m_fp_override;
std::vector<std::pair<int, wxString>> m_field_edits;
// Remember the dialog size during a session
static wxSize m_last_dlg_size;
};
#endif /* DIALOG_CHOOSE_COMPONENT_H */

View File

@ -295,12 +295,9 @@ public:
* Function SelectFootprintFromLibTree
* opens a dialog to select a footprint.
*
* @param aPreslect = if valid, the LIB_ID to select (otherwise the global history is
* used)
* @param aAllowBroswer = allow selection via the footprint viewer (false when already
* called from footprint viewer)
* @param aPreslect = if valid, the LIB_ID to select (otherwise the global history is used)
*/
MODULE* SelectFootprintFromLibTree( LIB_ID aPreselect = LIB_ID(), bool aAllowBroswer = true );
MODULE* SelectFootprintFromLibTree( LIB_ID aPreselect = LIB_ID() );
/**
* Adds the given module to the board.

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -23,35 +23,29 @@
*/
#include <dialog_choose_footprint.h>
#include <algorithm>
#include <set>
#include <wx/utils.h>
#include <wx/button.h>
#include <wx/dataview.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/splitter.h>
#include <wx/timer.h>
#include <wx/utils.h>
#include <pcb_base_frame.h>
#include <fp_lib_table.h>
#include <widgets/lib_tree.h>
#include <widgets/footprint_preview_widget.h>
#include <widgets/footprint_select_widget.h>
#include <kiface_i.h>
wxSize DIALOG_CHOOSE_FOOTPRINT::m_last_dlg_size( -1, -1 );
int DIALOG_CHOOSE_FOOTPRINT::m_h_sash_pos = 0;
int DIALOG_CHOOSE_FOOTPRINT::m_v_sash_pos = 0;
#define FP_CHOOSER_HSASH wxT( "FootprintChooserHSashPosition" )
#define FP_CHOOSER_VSASH wxT( "FootprintChooserVSashPosition" )
#define FP_CHOOSER_WIDTH_KEY wxT( "FootprintChooserWidth" )
#define FP_CHOOSER_HEIGHT_KEY wxT( "FootprintChooserHeight" )
DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent,
const wxString& aTitle,
FP_TREE_MODEL_ADAPTER::PTR& aAdapter,
bool aAllowBrowser )
FP_TREE_MODEL_ADAPTER::PTR& aAdapter )
: DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
m_browser_button( nullptr ),
@ -60,6 +54,8 @@ DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent,
m_parent( aParent ),
m_external_browser_requested( false )
{
m_config = Kiface().KifaceSettings();
auto sizer = new wxBoxSizer( wxVERTICAL );
wxHtmlWindow* details = nullptr;
@ -99,11 +95,8 @@ DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent,
auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
if( aAllowBrowser )
{
m_browser_button = new wxButton( this, wxID_ANY, _( "Select with Browser" ) );
buttonsSizer->Add( m_browser_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
}
m_browser_button = new wxButton( this, wxID_ANY, _( "Select with Browser" ) );
buttonsSizer->Add( m_browser_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
auto sdbSizer = new wxStdDialogButtonSizer();
auto okButton = new wxButton( this, wxID_OK );
@ -120,23 +113,20 @@ DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent,
Bind( wxEVT_TIMER, &DIALOG_CHOOSE_FOOTPRINT::OnCloseTimer, this, m_dbl_click_timer->GetId() );
Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected, this );
Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected, this );
if( m_browser_button )
m_browser_button->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_CHOOSE_FOOTPRINT::OnUseBrowser, this );
m_browser_button->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_CHOOSE_FOOTPRINT::OnUseBrowser, this );
Layout();
// We specify the width of the right window (m_symbol_view_panel), because specify
// the width of the left window does not work as expected when SetSashGravity() is called
m_hsplitter->SetSashPosition( m_h_sash_pos ? m_h_sash_pos : HorizPixelsFromDU( 220 ) );
m_hsplitter->SetSashPosition( m_config->Read( FP_CHOOSER_HSASH, HorizPixelsFromDU( 220 ) ) );
if( m_vsplitter )
m_vsplitter->SetSashPosition( m_v_sash_pos ? m_v_sash_pos : VertPixelsFromDU( 230 ) );
m_vsplitter->SetSashPosition( m_config->Read( FP_CHOOSER_VSASH, VertPixelsFromDU( 230 ) ) );
if( m_last_dlg_size == wxSize( -1, -1 ) )
SetSizeInDU( 440, 340 );
else
SetSize( m_last_dlg_size );
wxSize dlgSize( m_config->Read( FP_CHOOSER_WIDTH_KEY, HorizPixelsFromDU( 440 ) ),
m_config->Read( FP_CHOOSER_HEIGHT_KEY, VertPixelsFromDU( 340 ) ) );
SetSize( dlgSize );
SetInitialFocus( m_tree );
okButton->SetDefault();
@ -148,20 +138,20 @@ DIALOG_CHOOSE_FOOTPRINT::~DIALOG_CHOOSE_FOOTPRINT()
Unbind( wxEVT_TIMER, &DIALOG_CHOOSE_FOOTPRINT::OnCloseTimer, this );
Unbind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected, this );
Unbind( COMPONENT_SELECTED, &DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected, this );
if( m_browser_button )
m_browser_button->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_CHOOSE_FOOTPRINT::OnUseBrowser, this );
m_browser_button->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_CHOOSE_FOOTPRINT::OnUseBrowser, this );
// I am not sure the following two lines are necessary,
// but they will not hurt anyone
m_dbl_click_timer->Stop();
delete m_dbl_click_timer;
m_last_dlg_size = GetSize();
m_h_sash_pos = m_hsplitter->GetSashPosition();
m_config->Write( FP_CHOOSER_WIDTH_KEY, GetSize().x );
m_config->Write( FP_CHOOSER_HEIGHT_KEY, GetSize().y );
m_config->Write( FP_CHOOSER_HSASH, m_hsplitter->GetSashPosition() );
if( m_vsplitter )
m_v_sash_pos = m_vsplitter->GetSashPosition();
m_config->Write( FP_CHOOSER_VSASH, m_vsplitter->GetSashPosition() );
}

View File

@ -1,4 +1,4 @@
/* -*- c++ -*-
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
@ -94,7 +94,7 @@ public:
* for documentation.
*/
DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent, const wxString& aTitle,
FP_TREE_MODEL_ADAPTER::PTR& aAdapter, bool aAllowBrowser );
FP_TREE_MODEL_ADAPTER::PTR& aAdapter );
~DIALOG_CHOOSE_FOOTPRINT();
@ -133,22 +133,18 @@ protected:
*/
void OnComponentSelected( wxCommandEvent& aEvent );
wxConfigBase* m_config;
wxTimer* m_dbl_click_timer;
wxButton* m_browser_button;
wxSplitterWindow* m_hsplitter;
wxSplitterWindow* m_vsplitter;
static int m_h_sash_pos; // remember sash positions during a session
static int m_v_sash_pos;
FOOTPRINT_PREVIEW_WIDGET* m_preview_ctrl;
LIB_TREE* m_tree;
LIB_TREE* m_tree;
PCB_BASE_FRAME* m_parent;
bool m_external_browser_requested;
// Remember the dialog size during a session
static wxSize m_last_dlg_size;
};
#endif /* DIALOG_CHOOSE_FOOTPRINT_H */

View File

@ -18,8 +18,6 @@
*/
#include <wx/tokenzr.h>
#include <wx/progdlg.h>
#include <eda_pattern_match.h>
#include <fp_lib_table.h>
#include <footprint_info.h>
@ -39,10 +37,6 @@ FP_TREE_MODEL_ADAPTER::FP_TREE_MODEL_ADAPTER( LIB_TABLE* aLibs )
{}
FP_TREE_MODEL_ADAPTER::~FP_TREE_MODEL_ADAPTER()
{}
void FP_TREE_MODEL_ADAPTER::AddLibraries()
{
for( const auto& libName : m_libs->GetLogicalLibs() )

View File

@ -31,11 +31,6 @@ class FP_LIB_TABLE;
class FP_TREE_MODEL_ADAPTER : public LIB_TREE_MODEL_ADAPTER
{
public:
/**
* Destructor. Do NOT delete this class manually; it is reference-counted by wxObject.
*/
~FP_TREE_MODEL_ADAPTER();
/**
* Factory function: create a model adapter in a reference-counting container.
*

View File

@ -195,7 +195,7 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
}
MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect, bool aAllowBrowser )
MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect )
{
FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
wxString moduleName;
@ -240,7 +240,7 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect, bool aAll
wxString title;
title.Printf( _( "Choose Footprint (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_FOOTPRINT dialog( this, title, adapterPtr, aAllowBrowser );
DIALOG_CHOOSE_FOOTPRINT dialog( this, title, adapterPtr );
if( dialog.ShowQuasiModal() == wxID_CANCEL )
return NULL;