ADDED: Column selection and reordering in symbol chooser

This commit is contained in:
Jon Evans 2022-09-23 23:45:00 -04:00
parent 8e96751af2
commit 375b530dad
14 changed files with 1334 additions and 26 deletions

View File

@ -136,6 +136,8 @@ set( COMMON_DLG_SRCS
dialogs/dialog_unit_entry_base.cpp
dialogs/eda_list_dialog.cpp
dialogs/eda_list_dialog_base.cpp
dialogs/eda_reorderable_list_dialog.cpp
dialogs/eda_reorderable_list_dialog_base.cpp
dialogs/eda_view_switcher.cpp
dialogs/eda_view_switcher_base.cpp
dialogs/html_message_box.cpp

View File

@ -0,0 +1,264 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 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
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <bitmaps.h>
#include <macros.h>
#include <dialogs/eda_reorderable_list_dialog.h>
static int DEFAULT_SINGLE_COL_WIDTH = 260;
EDA_REORDERABLE_LIST_DIALOG::EDA_REORDERABLE_LIST_DIALOG( wxWindow* aParent, const wxString& aTitle,
const std::vector<wxString>& aAllItems,
const std::vector<wxString>& aEnabledItems ) :
EDA_REORDERABLE_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle ),
m_availableItems( aAllItems ),
m_enabledItems( aEnabledItems ),
m_selectedAvailable( 0 ),
m_selectedEnabled( 0 )
{
m_btnUp->SetBitmap( KiBitmap( BITMAPS::small_up ) );
m_btnDown->SetBitmap( KiBitmap( BITMAPS::small_down ) );
// DIALOG_SHIM needs a unique hash_key because classname is not sufficient
// because so many dialogs share this same class, with different numbers of
// columns, different column names, and column widths.
m_hash_key = TO_UTF8( aTitle );
m_availableListBox->InsertColumn( 0, wxEmptyString, wxLIST_FORMAT_LEFT,
DEFAULT_SINGLE_COL_WIDTH );
m_enabledListBox->InsertColumn( 0, wxEmptyString, wxLIST_FORMAT_LEFT,
DEFAULT_SINGLE_COL_WIDTH );
updateItems();
SetupStandardButtons();
// this line fixes an issue on Linux Ubuntu using Unity (dialog not shown),
// and works fine on all systems
GetSizer()->Fit( this );
Centre();
}
void EDA_REORDERABLE_LIST_DIALOG::updateItems()
{
m_availableListBox->DeleteAllItems();
m_enabledListBox->DeleteAllItems();
std::set<wxString> enabledSet;
for( size_t idx = 0; idx < m_enabledItems.size(); ++idx )
{
wxListItem info;
info.m_itemId = idx;
info.m_col = 0;
info.m_text = m_enabledItems[idx];
info.m_width = DEFAULT_SINGLE_COL_WIDTH;
info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_WIDTH;
m_enabledListBox->InsertItem( info );
if( m_selectedEnabled == static_cast<long>( idx ) )
m_enabledListBox->SetItemState( idx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
enabledSet.insert( m_enabledItems[idx] );
}
m_availableItems.erase( std::remove_if( m_availableItems.begin(), m_availableItems.end(),
[&]( const wxString& aItem ) -> bool
{
return enabledSet.count( aItem );
} ),
m_availableItems.end() );
for( size_t idx = 0; idx < m_availableItems.size(); ++idx )
{
wxListItem info;
info.m_itemId = idx;
info.m_col = 0;
info.m_text = m_availableItems[idx];
info.m_width = DEFAULT_SINGLE_COL_WIDTH;
info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_WIDTH;
m_availableListBox->InsertItem( info );
if( m_selectedAvailable == static_cast<long>( idx ) )
m_availableListBox->SetItemState( idx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
}
if( !m_availableItems.empty() )
m_availableListBox->EnsureVisible( m_selectedAvailable );
if( !m_enabledItems.empty() )
m_enabledListBox->EnsureVisible( m_selectedEnabled );
m_btnAdd->Enable( !m_availableItems.empty() );
m_btnRemove->Enable( !m_enabledItems.empty() );
}
void EDA_REORDERABLE_LIST_DIALOG::onAddItem( wxCommandEvent& aEvent )
{
wxListItem info;
if( !getSelectedItem( m_availableListBox, info ) )
return;
m_availableItems.erase( m_availableItems.begin() + info.m_itemId );
m_availableListBox->DeleteItem( m_selectedAvailable );
long pos = std::min( m_selectedEnabled + 1, static_cast<long>( m_enabledItems.size() ) );
info.m_itemId = pos;
info.m_mask = wxLIST_MASK_TEXT;
m_enabledItems.insert( m_enabledItems.begin() + pos, info.m_text );
m_enabledListBox->InsertItem( info );
updateButtons();
}
void EDA_REORDERABLE_LIST_DIALOG::onRemoveItem( wxCommandEvent& aEvent )
{
wxListItem info;
if( !getSelectedItem( m_enabledListBox, info ) || info.m_itemId == 0 )
return;
m_enabledItems.erase( m_enabledItems.begin() + info.m_itemId );
m_enabledListBox->DeleteItem( m_selectedEnabled );
m_selectedEnabled = std::min( m_selectedEnabled,
static_cast<long>( m_enabledItems.size() - 1 ) );
m_enabledListBox->SetItemState( m_selectedEnabled, wxLIST_STATE_SELECTED,
wxLIST_STATE_SELECTED );
long pos = std::max( long( 0 ), m_selectedAvailable );
info.m_itemId = pos;
m_availableItems.insert( m_availableItems.begin() + pos, info.m_text );
m_availableListBox->InsertItem( info );
updateButtons();
}
void EDA_REORDERABLE_LIST_DIALOG::onMoveUp( wxCommandEvent& aEvent )
{
wxListItem info;
if( !getSelectedItem( m_enabledListBox, info ) || info.m_itemId == 0 )
return;
auto current = m_enabledItems.begin() + info.m_itemId;
auto prev = m_enabledItems.begin() + info.m_itemId - 1;
std::iter_swap( current, prev );
m_selectedEnabled--;
updateButtons();
updateItems();
}
void EDA_REORDERABLE_LIST_DIALOG::onMoveDown( wxCommandEvent& aEvent )
{
wxListItem info;
if( !getSelectedItem( m_enabledListBox, info )
|| info.m_itemId == static_cast<long>( m_enabledItems.size() ) - 1 )
{
return;
}
auto current = m_enabledItems.begin() + info.m_itemId;
auto prev = m_enabledItems.begin() + info.m_itemId + 1;
std::iter_swap( current, prev );
m_selectedEnabled++;
updateButtons();
updateItems();
}
bool EDA_REORDERABLE_LIST_DIALOG::getSelectedItem( wxListCtrl* aList, wxListItem& aInfo )
{
long item = aList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
if( item < 0 )
return false;
aInfo.m_mask = wxLIST_MASK_DATA | wxLIST_MASK_STATE | wxLIST_MASK_TEXT;
aInfo.m_itemId = item;
aInfo.m_col = 0;
if( !aList->GetItem( aInfo ) )
return false;
return true;
}
void EDA_REORDERABLE_LIST_DIALOG::onEnabledListItemSelected( wxListEvent& event )
{
wxListItem info;
if( !getSelectedItem( m_enabledListBox, info ) )
{
m_selectedEnabled = -1;
return;
}
m_selectedEnabled = info.m_itemId;
updateButtons();
}
void EDA_REORDERABLE_LIST_DIALOG::onAvailableListItemSelected( wxListEvent& event )
{
wxListItem info;
if( !getSelectedItem( m_availableListBox, info ) )
{
m_selectedAvailable = -1;
return;
}
m_selectedAvailable = info.m_itemId;
updateButtons();
}
void EDA_REORDERABLE_LIST_DIALOG::updateButtons()
{
m_btnUp->Enable( !m_enabledItems.empty() && m_selectedEnabled > 0 );
m_btnDown->Enable( !m_enabledItems.empty() && m_selectedEnabled > 0 &&
m_selectedEnabled < static_cast<int>( m_enabledItems.size() ) - 1 );
m_btnAdd->Enable( !m_availableItems.empty() && m_selectedAvailable >= 0 );
m_btnRemove->Enable( !m_enabledItems.empty() && m_selectedEnabled > 0 );
}

View File

@ -0,0 +1,123 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "eda_reorderable_list_dialog_base.h"
///////////////////////////////////////////////////////////////////////////
EDA_REORDERABLE_LIST_DIALOG_BASE::EDA_REORDERABLE_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizerMain;
bSizerMain = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bTop;
bTop = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bLeftSide;
bLeftSide = new wxBoxSizer( wxVERTICAL );
m_availableListLabel = new wxStaticText( this, wxID_ANY, _("Available:"), wxDefaultPosition, wxDefaultSize, 0 );
m_availableListLabel->Wrap( -1 );
bLeftSide->Add( m_availableListLabel, 0, wxALL, 5 );
m_availableListBox = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_HRULES|wxLC_NO_HEADER|wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VRULES|wxBORDER_SIMPLE|wxVSCROLL );
m_availableListBox->SetMinSize( wxSize( 280,150 ) );
bLeftSide->Add( m_availableListBox, 0, wxALL, 5 );
bTop->Add( bLeftSide, 1, wxEXPAND, 5 );
wxBoxSizer* bMiddleButtons;
bMiddleButtons = new wxBoxSizer( wxVERTICAL );
m_btnAdd = new wxButton( this, wxID_ANY, _(">>"), wxDefaultPosition, wxSize( 48,-1 ), 0 );
bMiddleButtons->Add( m_btnAdd, 0, wxALL, 5 );
m_btnRemove = new wxButton( this, wxID_ANY, _("<<"), wxDefaultPosition, wxSize( 48,-1 ), 0 );
bMiddleButtons->Add( m_btnRemove, 0, wxALL, 5 );
bTop->Add( bMiddleButtons, 0, wxALIGN_CENTER_VERTICAL, 5 );
wxBoxSizer* bRightSide;
bRightSide = new wxBoxSizer( wxVERTICAL );
m_enabledListLabel = new wxStaticText( this, wxID_ANY, _("Enabled:"), wxDefaultPosition, wxDefaultSize, 0 );
m_enabledListLabel->Wrap( -1 );
bRightSide->Add( m_enabledListLabel, 0, wxALL, 5 );
m_enabledListBox = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_HRULES|wxLC_NO_HEADER|wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VRULES|wxBORDER_SIMPLE|wxVSCROLL );
m_enabledListBox->SetMinSize( wxSize( 280,150 ) );
bRightSide->Add( m_enabledListBox, 3, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxHORIZONTAL );
m_btnUp = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
m_btnUp->SetToolTip( _("Move up") );
bSizer4->Add( m_btnUp, 0, wxALL, 5 );
m_btnDown = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
m_btnDown->SetToolTip( _("Move down") );
bSizer4->Add( m_btnDown, 0, wxALL, 5 );
bRightSide->Add( bSizer4, 1, wxEXPAND, 5 );
bTop->Add( bRightSide, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 );
bSizerMain->Add( bTop, 1, wxEXPAND, 5 );
m_ButtonsSizer = new wxBoxSizer( wxHORIZONTAL );
m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK );
m_sdbSizer->AddButton( m_sdbSizerOK );
m_sdbSizerCancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer->AddButton( m_sdbSizerCancel );
m_sdbSizer->Realize();
m_ButtonsSizer->Add( m_sdbSizer, 1, wxALL, 5 );
bSizerMain->Add( m_ButtonsSizer, 0, wxEXPAND, 5 );
this->SetSizer( bSizerMain );
this->Layout();
bSizerMain->Fit( this );
this->Centre( wxBOTH );
// Connect Events
m_availableListBox->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onAvailableListItemSelected ), NULL, this );
m_btnAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onAddItem ), NULL, this );
m_btnRemove->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onRemoveItem ), NULL, this );
m_enabledListBox->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onEnabledListItemSelected ), NULL, this );
m_btnUp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onMoveUp ), NULL, this );
m_btnDown->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onMoveDown ), NULL, this );
}
EDA_REORDERABLE_LIST_DIALOG_BASE::~EDA_REORDERABLE_LIST_DIALOG_BASE()
{
// Disconnect Events
m_availableListBox->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onAvailableListItemSelected ), NULL, this );
m_btnAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onAddItem ), NULL, this );
m_btnRemove->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onRemoveItem ), NULL, this );
m_enabledListBox->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onEnabledListItemSelected ), NULL, this );
m_btnUp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onMoveUp ), NULL, this );
m_btnDown->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( EDA_REORDERABLE_LIST_DIALOG_BASE::onMoveDown ), NULL, this );
}

View File

@ -0,0 +1,695 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="16" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
<property name="disconnect_mode">source_name</property>
<property name="disconnect_php_events">0</property>
<property name="disconnect_python_events">0</property>
<property name="embedded_files_path">res</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="file">eda_reorderable_list_dialog_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="image_path_wrapper_function_name"></property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">eda_reorderable_list_dialog_base</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
<property name="relative_path">1</property>
<property name="skip_lua_events">1</property>
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_array_enum">0</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
<property name="center">wxBOTH</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="event_handler">decl_pure_virtual</property>
<property name="extra_style"></property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">EDA_REORDERABLE_LIST_DIALOG_BASE</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title"></property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizerMain</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bTop</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bLeftSide</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Available:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_availableListLabel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxListCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">280,150</property>
<property name="moveable">1</property>
<property name="name">m_availableListBox</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxLC_HRULES|wxLC_NO_HEADER|wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VRULES</property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxBORDER_SIMPLE|wxVSCROLL</property>
<event name="OnListItemSelected">onAvailableListItemSelected</event>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bMiddleButtons</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">&gt;&gt;</property>
<property name="margins">-1,-1</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_btnAdd</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size">48,-1</property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onAddItem</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">&lt;&lt;</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_btnRemove</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size">48,-1</property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onRemoveItem</event>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bRightSide</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Enabled:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_enabledListLabel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</property>
<property name="proportion">3</property>
<object class="wxListCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">280,150</property>
<property name="moveable">1</property>
<property name="name">m_enabledListBox</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxLC_HRULES|wxLC_NO_HEADER|wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VRULES</property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxBORDER_SIMPLE|wxVSCROLL</property>
<event name="OnListItemSelected">onEnabledListItemSelected</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer4</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxBitmapButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Up</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_btnUp</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Move up</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onMoveUp</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxBitmapButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Down</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_btnDown</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Move down</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onMoveDown</event>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">m_ButtonsSizer</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">public</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">1</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
<property name="No">0</property>
<property name="OK">1</property>
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="minimum_size"></property>
<property name="name">m_sdbSizer</property>
<property name="permission">protected</property>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>

View File

@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include "dialog_shim.h"
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/listctrl.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/bmpbuttn.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class EDA_REORDERABLE_LIST_DIALOG_BASE
///////////////////////////////////////////////////////////////////////////////
class EDA_REORDERABLE_LIST_DIALOG_BASE : public DIALOG_SHIM
{
private:
protected:
wxStaticText* m_availableListLabel;
wxListCtrl* m_availableListBox;
wxButton* m_btnAdd;
wxButton* m_btnRemove;
wxStaticText* m_enabledListLabel;
wxListCtrl* m_enabledListBox;
wxBitmapButton* m_btnUp;
wxBitmapButton* m_btnDown;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel;
// Virtual event handlers, override them in your derived class
virtual void onAvailableListItemSelected( wxListEvent& event ) = 0;
virtual void onAddItem( wxCommandEvent& event ) = 0;
virtual void onRemoveItem( wxCommandEvent& event ) = 0;
virtual void onEnabledListItemSelected( wxListEvent& event ) = 0;
virtual void onMoveUp( wxCommandEvent& event ) = 0;
virtual void onMoveDown( wxCommandEvent& event ) = 0;
public:
wxBoxSizer* m_ButtonsSizer;
EDA_REORDERABLE_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~EDA_REORDERABLE_LIST_DIALOG_BASE();
};

View File

@ -77,10 +77,20 @@ LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent,
m_colWidths[ wxT( "Item" ) ] = 300;
m_colWidths[ wxT( "Description" ) ] = 600;
m_availableColumns = { wxT( "Item" ), wxT( "Description" ) };
APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings();
for( const std::pair<const wxString, int>& pair : cfg->m_LibTree.column_widths )
m_colWidths[pair.first] = pair.second;
m_shownColumns = cfg->m_LibTree.columns;
if( m_shownColumns.empty() )
m_shownColumns = m_availableColumns;
if( m_shownColumns[0] != wxT( "Item" ) )
m_shownColumns.insert( m_shownColumns.begin(), wxT( "Item" ) );
}
@ -88,22 +98,18 @@ LIB_TREE_MODEL_ADAPTER::~LIB_TREE_MODEL_ADAPTER()
{}
void LIB_TREE_MODEL_ADAPTER::SaveColWidths()
void LIB_TREE_MODEL_ADAPTER::SaveSettings()
{
if( m_widget )
{
APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings();
cfg->m_LibTree.columns.clear();
cfg->m_LibTree.columns = GetShownColumns();
cfg->m_LibTree.column_widths.clear();
// TODO(JE) ordering?
for( const std::pair<const wxString, wxDataViewColumn*>& pair : m_colNameMap )
{
cfg->m_LibTree.columns.emplace_back( pair.first );
cfg->m_LibTree.column_widths[pair.first] = pair.second->GetWidth();
}
}
}
@ -245,19 +251,25 @@ void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
m_widget = aDataViewCtrl;
aDataViewCtrl->SetIndent( kDataViewIndent );
aDataViewCtrl->AssociateModel( this );
aDataViewCtrl->ClearColumns();
recreateColumns();
}
// These two columns are always added; other columns may be added by specific libraries.
// Do not use translated names here.
void LIB_TREE_MODEL_ADAPTER::recreateColumns()
{
m_widget->ClearColumns();
m_columns.clear();
m_colIdxMap.clear();
m_colNameMap.clear();
// The Item column is always shown
doAddColumn( wxT( "Item" ) );
// TODO(JE) make Description optional
doAddColumn( wxT( "Description" ) );
for( auto& it : m_colNameMap )
for( const wxString& colName : m_shownColumns )
{
if( !it.second )
doAddColumn( it.first, false );
if( !m_colNameMap.count( colName ) )
doAddColumn( colName, false );
}
}
@ -327,6 +339,18 @@ void LIB_TREE_MODEL_ADAPTER::addColumnIfNecessary( const wxString& aHeader )
// Columns will be created later
m_colNameMap[aHeader] = nullptr;
m_availableColumns.emplace_back( aHeader );
}
void LIB_TREE_MODEL_ADAPTER::SetShownColumns( const std::vector<wxString>& aColumnNames )
{
bool recreate = m_shownColumns != aColumnNames;
m_shownColumns = aColumnNames;
if( recreate && m_widget )
recreateColumns();
}
@ -548,10 +572,6 @@ void LIB_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant,
break;
case DESC_COL:
aVariant = node->m_Desc;
break;
default:
if( m_colIdxMap.count( aCol ) )
{
@ -559,6 +579,8 @@ void LIB_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant,
if( node->m_Fields.count( key ) )
aVariant = node->m_Fields.at( key );
else if( key == wxT( "Description" ) )
aVariant = node->m_Desc;
else
aVariant = wxEmptyString;
}

View File

@ -79,6 +79,8 @@ APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaV
m_params.emplace_back( new PARAM<int>( "color_picker.default_tab",
&m_ColorPicker.default_tab, 0 ) );
m_params.emplace_back( new PARAM_LIST<wxString>( "lib_tree.columns", &m_LibTree.columns, {} ) );
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "lib_tree.column_widths",
[&]() -> nlohmann::json
{

View File

@ -512,6 +512,10 @@ TOOL_ACTION ACTIONS::updateUnits( "common.Control.updateUnits",
TOOL_ACTION ACTIONS::updatePreferences( "common.Control.updatePreferences",
AS_GLOBAL );
TOOL_ACTION ACTIONS::selectColumns( "common.Control.selectColumns",
AS_GLOBAL, 0, "",
_( "Select Columns" ) );
TOOL_ACTION ACTIONS::toggleUnits( "common.Control.toggleUnits",
AS_GLOBAL,
MD_CTRL + 'U', LEGACY_HK_NAME( "Switch Units" ),

View File

@ -27,6 +27,7 @@
#include <macros.h>
#include <wxdataviewctrl_helpers.h>
#include <wx/sizer.h>
#include <dialogs/eda_reorderable_list_dialog.h>
#include <tool/tool_interactive.h>
#include <tool/tool_manager.h>
#include <tool/actions.h>
@ -47,7 +48,8 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_T
m_lib_table( aLibTable ), m_adapter( aAdapter ), m_query_ctrl( nullptr ),
m_details_ctrl( nullptr ),
m_inTimerEvent( false ),
m_recentSearchesKey( aRecentSearchesKey )
m_recentSearchesKey( aRecentSearchesKey ),
m_skipNextRightClick( false )
{
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
@ -132,7 +134,11 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_T
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_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::onItemContextMenu,
this );
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,
&LIB_TREE::onHeaderContextMenu, this );
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, &LIB_TREE::onHeaderClick, this );
Bind( SYMBOL_PRESELECTED, &LIB_TREE::onPreselect, this );
@ -171,7 +177,7 @@ LIB_TREE::~LIB_TREE()
m_debounceTimer->Stop();
// Save the column widths to the config file
m_adapter->SaveColWidths();
m_adapter->SaveSettings();
}
@ -573,8 +579,14 @@ void LIB_TREE::onPreselect( wxCommandEvent& aEvent )
}
void LIB_TREE::onContextMenu( wxDataViewEvent& aEvent )
void LIB_TREE::onItemContextMenu( wxDataViewEvent& aEvent )
{
if( m_skipNextRightClick )
{
m_skipNextRightClick = false;
return;
}
if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
{
tool->Activate();
@ -611,5 +623,34 @@ void LIB_TREE::onContextMenu( wxDataViewEvent& aEvent )
}
void LIB_TREE::onHeaderContextMenu( wxDataViewEvent& aEvent )
{
ACTION_MENU menu( true, nullptr );
menu.Add( ACTIONS::selectColumns );
if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
{
EDA_REORDERABLE_LIST_DIALOG dlg( m_parent, _( "Select Columns" ),
m_adapter->GetAvailableColumns(),
m_adapter->GetShownColumns() );
if( dlg.ShowModal() == wxID_OK )
m_adapter->SetShownColumns( dlg.EnabledList() );
}
#if !wxCHECK_VERSION( 3, 1, 0 )
// wxGTK 3.0 sends item right click events for header right clicks
m_skipNextRightClick = true;
#endif
}
void LIB_TREE::onHeaderClick( wxDataViewEvent& aEvent )
{
}
wxDEFINE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
wxDEFINE_EVENT( SYMBOL_SELECTED, wxCommandEvent );

View File

@ -0,0 +1,67 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 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
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EDA_REORDERABLE_LIST_DIALOG_H
#define EDA_REORDERABLE_LIST_DIALOG_H
#include <eda_reorderable_list_dialog_base.h>
/**
* A dialog which allows selecting a list of items from a list of available items, and reordering
* those items.
*/
class EDA_REORDERABLE_LIST_DIALOG : public EDA_REORDERABLE_LIST_DIALOG_BASE
{
public:
/**
* @param aParent Pointer to the parent window.
* @param aTitle The title shown on top.
* @param aAllItems A list of elements.
* @param aEnabledItems A list of elements that are already in the "enabled" category.
*/
EDA_REORDERABLE_LIST_DIALOG( wxWindow* aParent, const wxString& aTitle,
const std::vector<wxString>& aAllItems,
const std::vector<wxString>& aEnabledItems );
const std::vector<wxString>& EnabledList() { return m_enabledItems; }
protected:
void onAddItem( wxCommandEvent& aEvent ) override;
void onRemoveItem( wxCommandEvent& aEvent ) override;
void onMoveUp( wxCommandEvent& aEvent ) override;
void onMoveDown( wxCommandEvent& aEvent ) override;
void onAvailableListItemSelected( wxListEvent& event ) override;
void onEnabledListItemSelected( wxListEvent& event ) override;
private:
void updateItems();
bool getSelectedItem( wxListCtrl* aList, wxListItem& aInfo );
void updateButtons();
std::vector<wxString> m_availableItems;
std::vector<wxString> m_enabledItems;
long m_selectedAvailable;
long m_selectedEnabled;
};
#endif

View File

@ -138,7 +138,7 @@ public:
* Save the column widths to the config file. This requires the tree view to still be
* valid.
*/
void SaveColWidths();
void SaveSettings();
/**
* Set the symbol filter type. Must be set before adding libraries
@ -186,6 +186,16 @@ public:
doAddColumn( aHeader, false );
}
std::vector<wxString> GetAvailableColumns() const { return m_availableColumns; }
std::vector<wxString> GetShownColumns() const { return m_shownColumns; }
/**
* Sets which columns are shown in the widget. Invalid column names are discarded.
* @param aColumnNames is an ordered list of column names to show
*/
void SetShownColumns( const std::vector<wxString>& aColumnNames );
/**
* Sort the tree and assign ranks after adding libraries.
*/
@ -407,6 +417,8 @@ private:
protected:
void addColumnIfNecessary( const wxString& aHeader );
void recreateColumns();
LIB_TREE_NODE_ROOT m_tree;
std::map<unsigned, wxString> m_colIdxMap;
@ -424,6 +436,8 @@ private:
std::vector<wxDataViewColumn*> m_columns;
std::map<wxString, wxDataViewColumn*> m_colNameMap;
std::map<wxString, int> m_colWidths;
std::vector<wxString> m_availableColumns;
std::vector<wxString> m_shownColumns; // Stored in display order
};
#endif // LIB_TREE_MODEL_ADAPTER_H

View File

@ -171,6 +171,7 @@ public:
static TOOL_ACTION activatePointEditor;
static TOOL_ACTION changeEditMethod;
static TOOL_ACTION updatePreferences;
static TOOL_ACTION selectColumns;
// Suite
static TOOL_ACTION openPreferences;

View File

@ -200,7 +200,9 @@ protected:
void onDetailsLink( wxHtmlLinkEvent& aEvent );
void onPreselect( wxCommandEvent& aEvent );
void onContextMenu( wxDataViewEvent& aEvent );
void onItemContextMenu( wxDataViewEvent& aEvent );
void onHeaderClick( wxDataViewEvent& aEvent );
void onHeaderContextMenu( wxDataViewEvent& aEvent );
void onDebounceTimer( wxTimerEvent& aEvent );
@ -217,6 +219,8 @@ protected:
LIB_ID m_last_libid;
wxString m_recentSearchesKey;
bool m_skipNextRightClick;
};
///< Custom event sent when a new symbol is preselected

View File

@ -107,7 +107,7 @@ protected:
void onActivated( wxTreeListEvent& aEvent );
/**
* Method onContextMenu
* Method onItemContextMenu
* Handle right-click on a row.
*/
void onContextMenu( wxTreeListEvent& aEvent );