Fix width of part selector columns
* Move column width manipulation into the lib tree adapter * Fix issue with GTK where if someone types too fast, the part column gets 0 width. Fixes: lp:1841584 * https://bugs.launchpad.net/kicad/+bug/1841584
This commit is contained in:
parent
7cf42bb308
commit
bb596ebdaf
|
@ -19,12 +19,15 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <lib_tree_model_adapter.h>
|
||||
#include <eda_pattern_match.h>
|
||||
#include <kiface_i.h>
|
||||
#include <lib_tree_model_adapter.h>
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/wupdlock.h>
|
||||
|
||||
|
||||
#define LIST_COLUMN_WIDTH_KEY wxT( "SelectorColumnWidth" )
|
||||
|
||||
static const int kDataViewIndent = 20;
|
||||
|
||||
|
||||
|
@ -75,13 +78,40 @@ LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER()
|
|||
m_col_part( nullptr ),
|
||||
m_col_desc( nullptr ),
|
||||
m_widget( nullptr )
|
||||
{}
|
||||
{
|
||||
// Default column widths
|
||||
m_colWidths[PART_COL] = 360;
|
||||
m_colWidths[DESC_COL] = 2000;
|
||||
|
||||
m_config = Kiface().KifaceSettings();
|
||||
m_configPrefix = typeid( this ).name();
|
||||
|
||||
// Read the column width from the config
|
||||
int colWidth = 0;
|
||||
|
||||
if( m_config->Read( m_configPrefix + LIST_COLUMN_WIDTH_KEY, &colWidth ) )
|
||||
m_colWidths[PART_COL] = colWidth;
|
||||
}
|
||||
|
||||
|
||||
LIB_TREE_MODEL_ADAPTER::~LIB_TREE_MODEL_ADAPTER()
|
||||
{}
|
||||
|
||||
|
||||
void LIB_TREE_MODEL_ADAPTER::SaveColWidths()
|
||||
{
|
||||
if( m_widget )
|
||||
{
|
||||
int colWidth = m_widget->GetColumn( PART_COL )->GetWidth();
|
||||
m_config->Write( m_configPrefix + LIST_COLUMN_WIDTH_KEY, colWidth );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogDebug( "Error saving column size, tree view doesn't exist" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LIB_TREE_MODEL_ADAPTER::SetFilter( CMP_FILTER_TYPE aFilter )
|
||||
{
|
||||
m_filter = aFilter;
|
||||
|
@ -184,14 +214,21 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( wxString const& aSearch )
|
|||
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();
|
||||
int partWidth = aDataViewCtrl->GetColumn( PART_COL )->GetWidth();
|
||||
int descWidth = aDataViewCtrl->GetColumn( DESC_COL )->GetWidth();
|
||||
|
||||
// Only use the widths read back if they are non-zero.
|
||||
// GTK returns the displayed width of the column, which is not calculated immediately
|
||||
// this leads to cases of 0 column width if the user types too fast in the filter
|
||||
if( descWidth > 0 )
|
||||
{
|
||||
m_colWidths[PART_COL] = partWidth;
|
||||
m_colWidths[DESC_COL] = descWidth;
|
||||
}
|
||||
}
|
||||
|
||||
m_widget = aDataViewCtrl;
|
||||
|
@ -199,8 +236,10 @@ void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
|
|||
aDataViewCtrl->AssociateModel( this );
|
||||
aDataViewCtrl->ClearColumns();
|
||||
|
||||
m_col_part = aDataViewCtrl->AppendTextColumn( partHead, 0, wxDATAVIEW_CELL_INERT, partWidth );
|
||||
m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, 1, wxDATAVIEW_CELL_INERT, descWidth );
|
||||
m_col_part = aDataViewCtrl->AppendTextColumn( partHead, PART_COL, wxDATAVIEW_CELL_INERT,
|
||||
m_colWidths[PART_COL] );
|
||||
m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT,
|
||||
m_colWidths[DESC_COL] );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -114,6 +114,22 @@ public:
|
|||
CMP_FILTER_POWER, ///< list components flagged PWR
|
||||
};
|
||||
|
||||
/**
|
||||
* This enum defines the order of the columns in the tree view
|
||||
*/
|
||||
enum TREE_COLS
|
||||
{
|
||||
PART_COL = 0, ///< Part name column
|
||||
DESC_COL, ///< Part description column
|
||||
NUM_COLS ///< The number of tree columns
|
||||
};
|
||||
|
||||
/**
|
||||
* Save the column widths to the config file. This requires the tree view to still be
|
||||
* valid.
|
||||
*/
|
||||
void SaveColWidths();
|
||||
|
||||
/**
|
||||
* Set the component filter type. Must be set before adding libraries
|
||||
*
|
||||
|
@ -273,7 +289,7 @@ protected:
|
|||
*/
|
||||
wxDataViewItem GetParent( wxDataViewItem const& aItem ) const override;
|
||||
|
||||
unsigned int GetColumnCount() const override { return 2; }
|
||||
unsigned int GetColumnCount() const override { return NUM_COLS; }
|
||||
|
||||
/**
|
||||
* Return the type of data stored in the column as indicated by wxVariant::GetType()
|
||||
|
@ -322,6 +338,11 @@ private:
|
|||
wxDataViewColumn* m_col_desc;
|
||||
wxDataViewCtrl* m_widget;
|
||||
|
||||
int m_colWidths[NUM_COLS];
|
||||
|
||||
wxConfigBase* m_config;
|
||||
wxString m_configPrefix;
|
||||
|
||||
/**
|
||||
* Find any results worth highlighting and expand them, according to given
|
||||
* criteria (f(CMP_TREE_NODE const*) -> bool)
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
#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,
|
||||
|
@ -43,9 +40,6 @@ 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
|
||||
|
@ -116,11 +110,6 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAP
|
|||
|
||||
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 )
|
||||
|
@ -148,8 +137,8 @@ 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 );
|
||||
// Save the column widths to the config file
|
||||
m_adapter->SaveColWidths();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -158,9 +158,6 @@ protected:
|
|||
void onContextMenu( wxDataViewEvent& aEvent );
|
||||
|
||||
protected:
|
||||
wxConfigBase* m_config;
|
||||
wxString m_configPrefix;
|
||||
|
||||
LIB_TABLE* m_lib_table;
|
||||
LIB_TREE_MODEL_ADAPTER::PTR m_adapter;
|
||||
|
||||
|
|
Loading…
Reference in New Issue