CHANGED: Use FILTER_COMBOBOX for label names.
Also pushes some of the implementation down a level
so that it can be shared between this and the
SYMBOL_FILTER_COMBOBOX.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/20943
(cherry picked from commit ee2cf47f23)
This commit is contained in:
@@ -38,8 +38,8 @@ wxDEFINE_EVENT( FILTERED_ITEM_SELECTED, wxCommandEvent );
|
||||
|
||||
#if defined( __WXOSX_MAC__ )
|
||||
#define POPUP_PADDING 2
|
||||
#define LIST_ITEM_PADDING 5
|
||||
#define LIST_PADDING 5
|
||||
#define LIST_ITEM_PADDING 2
|
||||
#define LIST_PADDING 7
|
||||
#elif defined( __WXMSW__ )
|
||||
#define POPUP_PADDING 0
|
||||
#define LIST_ITEM_PADDING 2
|
||||
@@ -81,33 +81,53 @@ bool FILTER_COMBOPOPUP::Create( wxWindow* aParent )
|
||||
|
||||
m_listBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr,
|
||||
wxLB_SINGLE | wxLB_NEEDED_SB );
|
||||
mainSizer->Add( m_listBox, 0, wxEXPAND | wxTOP, 2 );
|
||||
mainSizer->Add( m_listBox, 1, wxEXPAND | wxTOP, 2 );
|
||||
|
||||
SetSizer( mainSizer );
|
||||
Layout();
|
||||
|
||||
Connect( wxEVT_IDLE, wxIdleEventHandler( FILTER_COMBOPOPUP::onIdle ), nullptr, this );
|
||||
Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( FILTER_COMBOPOPUP::onKeyDown ), nullptr, this );
|
||||
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( FILTER_COMBOPOPUP::onMouseClick ), nullptr,
|
||||
this );
|
||||
m_listBox->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( FILTER_COMBOPOPUP::onMouseClick ),
|
||||
nullptr, this );
|
||||
m_filterCtrl->Connect( wxEVT_TEXT, wxCommandEventHandler( FILTER_COMBOPOPUP::onFilterEdit ),
|
||||
nullptr, this );
|
||||
m_filterCtrl->Connect( wxEVT_TEXT_ENTER, wxCommandEventHandler( FILTER_COMBOPOPUP::onEnter ),
|
||||
nullptr, this );
|
||||
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( FILTER_COMBOPOPUP::onMouseClick ), nullptr, this );
|
||||
m_listBox->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( FILTER_COMBOPOPUP::onMouseClick ), nullptr, this );
|
||||
m_filterCtrl->Connect( wxEVT_TEXT, wxCommandEventHandler( FILTER_COMBOPOPUP::onFilterEdit ), nullptr, this );
|
||||
m_filterCtrl->Connect( wxEVT_TEXT_ENTER, wxCommandEventHandler( FILTER_COMBOPOPUP::onEnter ), nullptr, this );
|
||||
|
||||
// <enter> in a ListBox comes in as a double-click on GTK
|
||||
m_listBox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,
|
||||
wxCommandEventHandler( FILTER_COMBOPOPUP::onEnter ), nullptr, this );
|
||||
m_listBox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( FILTER_COMBOPOPUP::onEnter ),
|
||||
nullptr, this );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOPOPUP::SetStringList( const wxArrayString& aStringList )
|
||||
{
|
||||
m_stringList = aStringList;
|
||||
m_stringList.Sort();
|
||||
rebuildList();
|
||||
}
|
||||
|
||||
|
||||
wxString FILTER_COMBOPOPUP::GetStringValue() const
|
||||
{
|
||||
return m_selectedString;
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOPOPUP::SetStringValue( const wxString& aNetName )
|
||||
{
|
||||
// shouldn't be here (combo is read-only)
|
||||
if( GetWindowStyleFlag() & wxCB_READONLY )
|
||||
/* shouldn't be here (combo is read-only) */;
|
||||
else
|
||||
wxComboPopup::SetStringValue( aNetName );
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOPOPUP::SetSelectedString( const wxString& aString )
|
||||
{
|
||||
m_selectedString = aString;
|
||||
GetComboCtrl()->SetValue( m_selectedString );
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +153,24 @@ void FILTER_COMBOPOPUP::OnStartingKey( wxKeyEvent& aEvent )
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOPOPUP::Accept()
|
||||
{
|
||||
wxString selectedString = getSelectedValue().value_or( wxEmptyString );
|
||||
|
||||
Dismiss();
|
||||
|
||||
// No update on empty
|
||||
if( !selectedString.IsEmpty() && selectedString != m_selectedString )
|
||||
{
|
||||
m_selectedString = selectedString;
|
||||
GetComboCtrl()->SetValue( m_selectedString );
|
||||
|
||||
wxCommandEvent changeEvent( FILTERED_ITEM_SELECTED );
|
||||
wxPostEvent( GetComboCtrl(), changeEvent );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wxSize FILTER_COMBOPOPUP::GetAdjustedSize( int aMinWidth, int aPrefHeight, int aMaxHeight )
|
||||
{
|
||||
// Called when the popup is first shown. Stash the minWidth and maxHeight so we
|
||||
@@ -144,6 +182,19 @@ wxSize FILTER_COMBOPOPUP::GetAdjustedSize( int aMinWidth, int aPrefHeight, int a
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOPOPUP::getListContent( wxArrayString& aListContent )
|
||||
{
|
||||
const wxString filterString = getFilterValue();
|
||||
|
||||
// Simple substring, case-insensitive search
|
||||
for( const wxString& str : m_stringList )
|
||||
{
|
||||
if( filterString.IsEmpty() || str.Lower().Contains( filterString.Lower() ) )
|
||||
aListContent.push_back( str );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOPOPUP::rebuildList()
|
||||
{
|
||||
wxArrayString newList;
|
||||
@@ -174,17 +225,17 @@ wxSize FILTER_COMBOPOPUP::updateSize()
|
||||
{
|
||||
int listTop = m_listBox->GetRect().y;
|
||||
int itemHeight = KIUI::GetTextSize( wxT( "Xy" ), this ).y + LIST_ITEM_PADDING;
|
||||
int listHeight = m_listBox->GetCount() * itemHeight + LIST_PADDING;
|
||||
int listHeight = ( (int) m_listBox->GetCount() * itemHeight ) + ( LIST_PADDING * 3 );
|
||||
|
||||
if( listTop + listHeight >= m_maxPopupHeight )
|
||||
listHeight = m_maxPopupHeight - listTop - 1;
|
||||
|
||||
int listWidth = m_minPopupWidth;
|
||||
int listWidth = m_minPopupWidth;
|
||||
|
||||
for( size_t i = 0; i < m_listBox->GetCount(); ++i )
|
||||
{
|
||||
int itemWidth = KIUI::GetTextSize( m_listBox->GetString( i ), m_listBox ).x;
|
||||
listWidth = std::max( listWidth, itemWidth + LIST_PADDING * 3 );
|
||||
listWidth = std::max( listWidth, itemWidth + LIST_PADDING * 2 );
|
||||
}
|
||||
|
||||
wxSize listSize( listWidth, listHeight );
|
||||
@@ -388,7 +439,7 @@ void FILTER_COMBOPOPUP::doSetFocus( wxWindow* aWindow )
|
||||
|
||||
FILTER_COMBOBOX::FILTER_COMBOBOX( wxWindow *parent, wxWindowID id, const wxPoint &pos,
|
||||
const wxSize &size, long style ) :
|
||||
wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxCB_READONLY|wxTE_PROCESS_ENTER ),
|
||||
wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxTE_PROCESS_ENTER ),
|
||||
m_filterPopup( nullptr )
|
||||
{
|
||||
UseAltPopupWindow();
|
||||
@@ -398,12 +449,37 @@ FILTER_COMBOBOX::FILTER_COMBOBOX( wxWindow *parent, wxWindowID id, const wxPoint
|
||||
}
|
||||
|
||||
|
||||
FILTER_COMBOBOX::FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxString& value,
|
||||
const wxPoint& pos, const wxSize& size,
|
||||
int count, wxString strings[], long style ) :
|
||||
FILTER_COMBOBOX( parent, id, pos, size, style )
|
||||
{
|
||||
// These arguments are just to match wxFormBuilder's expected API; they are not supported
|
||||
wxASSERT( value.IsEmpty() && count == 0 && strings == nullptr );
|
||||
|
||||
m_filterPopup = new FILTER_COMBOPOPUP();
|
||||
setFilterPopup( m_filterPopup );
|
||||
}
|
||||
|
||||
|
||||
FILTER_COMBOBOX::~FILTER_COMBOBOX()
|
||||
{
|
||||
Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( FILTER_COMBOBOX::onKeyDown ), nullptr, this );
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOBOX::SetStringList( const wxArrayString& aList )
|
||||
{
|
||||
m_filterPopup->SetStringList( aList );
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOBOX::SetSelectedString( const wxString& aString )
|
||||
{
|
||||
m_filterPopup->SetSelectedString( aString );
|
||||
}
|
||||
|
||||
|
||||
void FILTER_COMBOBOX::setFilterPopup( FILTER_COMBOPOPUP* aPopup )
|
||||
{
|
||||
m_filterPopup = aPopup;
|
||||
@@ -432,8 +508,8 @@ void FILTER_COMBOBOX::onKeyDown( wxKeyEvent& aEvt )
|
||||
{
|
||||
Popup();
|
||||
}
|
||||
// Non-control characters go to filterbox in popup
|
||||
else if( key > WXK_SPACE && key < WXK_START )
|
||||
// Non-control characters go to filterbox in popup for read-only controls
|
||||
else if( key > WXK_SPACE && key < WXK_START && ( GetWindowStyleFlag() & wxCB_READONLY ) )
|
||||
{
|
||||
Popup();
|
||||
m_filterPopup->OnStartingKey( aEvt );
|
||||
|
||||
@@ -38,7 +38,6 @@ class NET_SELECTOR_COMBOPOPUP : public FILTER_COMBOPOPUP
|
||||
public:
|
||||
NET_SELECTOR_COMBOPOPUP() :
|
||||
m_netinfoList( nullptr ),
|
||||
m_board( nullptr ),
|
||||
m_selectedNetcode( 0 )
|
||||
{ }
|
||||
|
||||
@@ -67,11 +66,6 @@ public:
|
||||
rebuildList();
|
||||
}
|
||||
|
||||
void SetBoard( BOARD* aBoard )
|
||||
{
|
||||
m_board = aBoard;
|
||||
}
|
||||
|
||||
void SetIndeterminate() { m_selectedNetcode = -1; }
|
||||
bool IsIndeterminate() { return m_selectedNetcode == -1; }
|
||||
|
||||
@@ -117,35 +111,30 @@ public:
|
||||
m_selectedNetcode = 0;
|
||||
GetComboCtrl()->SetValue( NO_NET );
|
||||
}
|
||||
else if( escapedNetName.StartsWith( CREATE_NET, &remainingName ) &&
|
||||
!remainingName.IsEmpty() )
|
||||
else if( escapedNetName.StartsWith( CREATE_NET, &remainingName ) && !remainingName.IsEmpty() )
|
||||
{
|
||||
// Remove the first character ':' and all whitespace
|
||||
remainingName = remainingName.Mid( 1 ).Trim().Trim( false );
|
||||
|
||||
BOARD* board = m_netinfoList->GetParent();
|
||||
NETINFO_ITEM *newnet = new NETINFO_ITEM( m_board, remainingName, 0 );
|
||||
if( BOARD* board = m_netinfoList->GetParent() )
|
||||
{
|
||||
NETINFO_ITEM *newnet = new NETINFO_ITEM( board, remainingName, 0 );
|
||||
|
||||
wxASSERT( board );
|
||||
|
||||
if( board )
|
||||
board->Add( newnet );
|
||||
rebuildList();
|
||||
|
||||
rebuildList();
|
||||
|
||||
if( newnet->GetNetCode() > 0 )
|
||||
{
|
||||
m_selectedNetcode = newnet->GetNetCode();
|
||||
GetComboCtrl()->SetValue( UnescapeString( remainingName ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// This indicates that the NETINFO_ITEM was not successfully appended to the
|
||||
// list for unknown reasons
|
||||
if( board )
|
||||
if( newnet->GetNetCode() > 0 )
|
||||
{
|
||||
m_selectedNetcode = newnet->GetNetCode();
|
||||
GetComboCtrl()->SetValue( UnescapeString( remainingName ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// This indicates that the NETINFO_ITEM was not successfully appended to the
|
||||
// list for unknown reasons
|
||||
board->Remove( newnet );
|
||||
|
||||
delete newnet;
|
||||
delete newnet;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -213,10 +202,9 @@ protected:
|
||||
aNetnames.push_back( m_indeterminateLabel );
|
||||
}
|
||||
|
||||
protected:
|
||||
const NETINFO_LIST* m_netinfoList;
|
||||
wxString m_indeterminateLabel;
|
||||
BOARD* m_board;
|
||||
|
||||
int m_selectedNetcode;
|
||||
|
||||
std::map<wxString, wxString> m_unescapedNetNameMap;
|
||||
@@ -225,7 +213,7 @@ protected:
|
||||
|
||||
NET_SELECTOR::NET_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
|
||||
long style ) :
|
||||
FILTER_COMBOBOX( parent, id, pos, size, style )
|
||||
FILTER_COMBOBOX( parent, id, pos, size, style|wxCB_READONLY )
|
||||
{
|
||||
m_netSelectorPopup = new NET_SELECTOR_COMBOPOPUP();
|
||||
setFilterPopup( m_netSelectorPopup );
|
||||
@@ -245,12 +233,6 @@ void NET_SELECTOR::SetIndeterminateString( const wxString& aString )
|
||||
}
|
||||
|
||||
|
||||
void NET_SELECTOR::SetBoard( BOARD* aBoard )
|
||||
{
|
||||
m_netSelectorPopup->SetBoard( aBoard );
|
||||
}
|
||||
|
||||
|
||||
void NET_SELECTOR::SetSelectedNetcode( int aNetcode )
|
||||
{
|
||||
m_netSelectorPopup->SetSelectedNetcode( aNetcode );
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <widgets/font_choice.h>
|
||||
#include <widgets/std_bitmap_button.h>
|
||||
#include <widgets/color_swatch.h>
|
||||
#include <widgets/filter_combobox.h>
|
||||
#include <settings/color_settings.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <tool/tool_manager.h>
|
||||
@@ -260,10 +261,6 @@ DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent,
|
||||
if( cfg->m_Appearance.edit_label_width > 0 && cfg->m_Appearance.edit_label_height > 0 )
|
||||
SetSize( cfg->m_Appearance.edit_label_width, cfg->m_Appearance.edit_label_height );
|
||||
}
|
||||
|
||||
// Bind the event to handle filtering
|
||||
m_valueCombo->Bind( wxEVT_TEXT, &DIALOG_LABEL_PROPERTIES::OnLabelFilter, this );
|
||||
m_valueCombo->Bind( wxEVT_COMBOBOX, &DIALOG_LABEL_PROPERTIES::OnLabelItemSelected, this );
|
||||
}
|
||||
|
||||
|
||||
@@ -285,9 +282,6 @@ DIALOG_LABEL_PROPERTIES::~DIALOG_LABEL_PROPERTIES()
|
||||
|
||||
if( m_helpWindow )
|
||||
m_helpWindow->Destroy();
|
||||
|
||||
m_valueCombo->Unbind( wxEVT_TEXT, &DIALOG_LABEL_PROPERTIES::OnLabelFilter, this );
|
||||
m_valueCombo->Unbind( wxEVT_COMBOBOX, &DIALOG_LABEL_PROPERTIES::OnLabelItemSelected, this );
|
||||
}
|
||||
|
||||
|
||||
@@ -296,15 +290,15 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataToWindow()
|
||||
if( !wxDialog::TransferDataToWindow() )
|
||||
return false;
|
||||
|
||||
wxString text;
|
||||
|
||||
if( m_activeTextEntry )
|
||||
{
|
||||
// show control characters in a human-readable format
|
||||
wxString text = UnescapeString( m_currentLabel->GetText() );
|
||||
text = UnescapeString( m_currentLabel->GetText() );
|
||||
|
||||
// show text variable cross-references in a human-readable format
|
||||
text = m_currentLabel->Schematic()->ConvertKIIDsToRefs( text );
|
||||
|
||||
m_activeTextEntry->SetValue( text );
|
||||
}
|
||||
|
||||
if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
|
||||
@@ -348,7 +342,12 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataToWindow()
|
||||
for( const wxString& label : existingLabels )
|
||||
m_existingLabelArray.push_back( label );
|
||||
|
||||
m_valueCombo->Append( m_existingLabelArray );
|
||||
m_valueCombo->SetStringList( m_existingLabelArray );
|
||||
m_valueCombo->SetSelectedString( text );
|
||||
}
|
||||
else if( m_activeTextEntry )
|
||||
{
|
||||
m_activeTextEntry->SetValue( text );
|
||||
}
|
||||
|
||||
// Push a copy of each field into m_updateFields
|
||||
@@ -916,98 +915,6 @@ void DIALOG_LABEL_PROPERTIES::OnSizeGrid( wxSizeEvent& event )
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles the filtering of items in the wxComboBox based on user input.
|
||||
*
|
||||
* This function is triggered by the wxEVT_TEXT event whenever the user types
|
||||
* or modifies the text in the combo box. It filters the dropdown list
|
||||
* to show only those items that match the user's input.
|
||||
*
|
||||
* Key Steps:
|
||||
* - Prevents re-entry using a static flag `isFiltering` to avoid recursion
|
||||
* caused by wxComboBox events triggered during item updates.
|
||||
* - Compares the current input with the previously entered text to avoid
|
||||
* unnecessary filtering if the text hasn't changed.
|
||||
* - Filters the items from `m_existingLabelArray` to match the user's input.
|
||||
* - Updates the combo box with the filtered items while preserving the user's
|
||||
* input and cursor position.
|
||||
*
|
||||
* @param event The wxCommandEvent associated with the wxEVT_TEXT event.
|
||||
*/
|
||||
void DIALOG_LABEL_PROPERTIES::OnLabelFilter( wxCommandEvent& event )
|
||||
{
|
||||
static bool isFiltering = false;
|
||||
|
||||
if( isFiltering )
|
||||
return;
|
||||
|
||||
isFiltering = true;
|
||||
|
||||
wxString currentLabelText = m_valueCombo->GetValue();
|
||||
|
||||
// Check if the text has changed compared to the previous value
|
||||
if( currentLabelText.length() > m_previousLabelText.length() )
|
||||
{
|
||||
long insertionPoint = m_valueCombo->GetInsertionPoint();
|
||||
|
||||
wxArrayString filteredLabels;
|
||||
|
||||
if( currentLabelText.IsEmpty() )
|
||||
{
|
||||
filteredLabels = m_existingLabelArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString filterText = currentLabelText.Lower();
|
||||
|
||||
std::copy_if( m_existingLabelArray.begin(), m_existingLabelArray.end(),
|
||||
std::back_inserter( filteredLabels ),
|
||||
[&filterText]( const wxString& label )
|
||||
{
|
||||
return label.Lower().Contains( filterText );
|
||||
} );
|
||||
}
|
||||
|
||||
m_valueCombo->Freeze();
|
||||
m_valueCombo->Clear();
|
||||
m_valueCombo->Append( filteredLabels );
|
||||
m_valueCombo->Thaw();
|
||||
|
||||
m_valueCombo->ChangeValue( currentLabelText );
|
||||
m_valueCombo->SetInsertionPoint( insertionPoint );
|
||||
|
||||
if( filteredLabels.size() > 0 && !currentLabelText.empty() )
|
||||
{
|
||||
wxString filterText = currentLabelText.Lower();
|
||||
|
||||
auto it = std::find_if( filteredLabels.begin(), filteredLabels.end(),
|
||||
[&filterText]( const wxString& label )
|
||||
{
|
||||
return label.Lower().StartsWith( filterText );
|
||||
} );
|
||||
|
||||
if( it != filteredLabels.end() )
|
||||
{
|
||||
wxString suggestion = *it;
|
||||
m_valueCombo->ChangeValue( suggestion );
|
||||
m_valueCombo->SetInsertionPoint( filterText.length() );
|
||||
m_valueCombo->SetSelection( filterText.length(), suggestion.length() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_previousLabelText = currentLabelText;
|
||||
isFiltering = false;
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_LABEL_PROPERTIES::OnLabelItemSelected( wxCommandEvent& event )
|
||||
{
|
||||
wxString selectedValue = m_valueCombo->GetValue();
|
||||
m_previousLabelText = selectedValue;
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_LABEL_PROPERTIES::onMultiLabelCheck( wxCommandEvent& event )
|
||||
{
|
||||
if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T )
|
||||
|
||||
@@ -66,28 +66,6 @@ private:
|
||||
void OnSizeGrid( wxSizeEvent& event ) override;
|
||||
void OnUpdateUI( wxUpdateUIEvent& event ) override;
|
||||
|
||||
/**
|
||||
* Handles the filtering of items in the wxComboBox based on user input.
|
||||
*
|
||||
* This function is triggered by the wxEVT_TEXT event when the user modifies
|
||||
* the text in the combo box. It filters the dropdown list to display only
|
||||
* the items that match the input text.
|
||||
*
|
||||
* @param event The wxCommandEvent associated with the wxEVT_TEXT event.
|
||||
*/
|
||||
void OnLabelFilter( wxCommandEvent& event );
|
||||
|
||||
/**
|
||||
* Handles the selection of an item from the wxComboBox dropdown.
|
||||
*
|
||||
* This function is triggered by the wxEVT_COMBOBOX event when the user selects
|
||||
* an item. It ensures that the selected value is correctly processed and
|
||||
* prevents unnecessary re-filtering based on the selection.
|
||||
*
|
||||
* @param event The wxCommandEvent associated with the wxEVT_COMBOBOX event.
|
||||
*/
|
||||
void OnLabelItemSelected( wxCommandEvent& event );
|
||||
|
||||
void AdjustGridColumns( int aWidth );
|
||||
|
||||
bool TransferDataToWindow() override;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty)
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "widgets/bitmap_button.h"
|
||||
#include "widgets/color_swatch.h"
|
||||
#include "widgets/filter_combobox.h"
|
||||
#include "widgets/font_choice.h"
|
||||
#include "widgets/std_bitmap_button.h"
|
||||
#include "widgets/wx_grid.h"
|
||||
@@ -41,7 +42,7 @@ DIALOG_LABEL_PROPERTIES_BASE::DIALOG_LABEL_PROPERTIES_BASE( wxWindow* parent, wx
|
||||
m_labelCombo->Wrap( -1 );
|
||||
m_textEntrySizer->Add( m_labelCombo, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
|
||||
|
||||
m_valueCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER );
|
||||
m_valueCombo = new FILTER_COMBOBOX( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
|
||||
m_textEntrySizer->Add( m_valueCombo, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
|
||||
|
||||
m_labelMultiLine = new wxStaticText( this, wxID_ANY, _("Label:"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
|
||||
@@ -324,8 +324,8 @@
|
||||
<property name="selection">-1</property>
|
||||
<property name="show">1</property>
|
||||
<property name="size"></property>
|
||||
<property name="style">wxTE_PROCESS_ENTER</property>
|
||||
<property name="subclass">; forward_declare</property>
|
||||
<property name="style"></property>
|
||||
<property name="subclass">FILTER_COMBOBOX; widgets/filter_combobox.h; forward_declare</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="validator_data_type"></property>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty)
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <wx/intl.h>
|
||||
class BITMAP_BUTTON;
|
||||
class COLOR_SWATCH;
|
||||
class FILTER_COMBOBOX;
|
||||
class FONT_CHOICE;
|
||||
class STD_BITMAP_BUTTON;
|
||||
class WX_GRID;
|
||||
@@ -60,7 +61,7 @@ class DIALOG_LABEL_PROPERTIES_BASE : public DIALOG_SHIM
|
||||
wxStaticText* m_labelSingleLine;
|
||||
wxTextCtrl* m_valueSingleLine;
|
||||
wxStaticText* m_labelCombo;
|
||||
wxComboBox* m_valueCombo;
|
||||
FILTER_COMBOBOX* m_valueCombo;
|
||||
wxStaticText* m_labelMultiLine;
|
||||
wxTextCtrl* m_valueMultiLine;
|
||||
wxCheckBox* m_cbMultiLine;
|
||||
|
||||
@@ -53,12 +53,10 @@ DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent,
|
||||
for( const wxString& name : aSymbolNames )
|
||||
escapedNames.Add( UnescapeString( name ) );
|
||||
|
||||
m_comboInheritanceSelect->SetSymbolList( escapedNames );
|
||||
m_comboInheritanceSelect->SetStringList( escapedNames );
|
||||
|
||||
if( !aInheritFromSymbolName.IsEmpty() )
|
||||
{
|
||||
m_comboInheritanceSelect->SetSelectedSymbol( aInheritFromSymbolName );
|
||||
}
|
||||
m_comboInheritanceSelect->SetSelectedString( aInheritFromSymbolName );
|
||||
}
|
||||
|
||||
// Trigger the event handler to show/hide the info bar message.
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
#include "widgets/symbol_filter_combobox.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
static const wxString kNoParentSymbol( "<do not derive>" );
|
||||
|
||||
class SYMBOL_FILTER_COMBOPOPUP : public FILTER_COMBOPOPUP
|
||||
@@ -33,81 +33,29 @@ class SYMBOL_FILTER_COMBOPOPUP : public FILTER_COMBOPOPUP
|
||||
public:
|
||||
SYMBOL_FILTER_COMBOPOPUP() {}
|
||||
|
||||
wxString GetStringValue() const override { return m_selectedSymbol; }
|
||||
|
||||
void SetSelectedSymbol( const wxString& aSymbolName )
|
||||
{
|
||||
m_selectedSymbol = aSymbolName;
|
||||
GetComboCtrl()->SetValue( m_selectedSymbol );
|
||||
}
|
||||
|
||||
void Accept() override
|
||||
{
|
||||
wxString selectedSymbol = getSelectedValue().value_or( wxEmptyString );
|
||||
|
||||
Dismiss();
|
||||
|
||||
// No update on empty
|
||||
if( !selectedSymbol.IsEmpty() && selectedSymbol != m_selectedSymbol )
|
||||
{
|
||||
m_selectedSymbol = selectedSymbol;
|
||||
GetComboCtrl()->SetValue( m_selectedSymbol );
|
||||
|
||||
wxCommandEvent changeEvent( FILTERED_ITEM_SELECTED );
|
||||
wxPostEvent( GetComboCtrl(), changeEvent );
|
||||
}
|
||||
}
|
||||
|
||||
void SetSymbolList( const wxArrayString& aSymbolList )
|
||||
{
|
||||
m_symbolList = aSymbolList;
|
||||
m_symbolList.Sort();
|
||||
rebuildList();
|
||||
}
|
||||
|
||||
private:
|
||||
void getListContent( wxArrayString& aListContent ) override
|
||||
{
|
||||
FILTER_COMBOPOPUP::getListContent( aListContent );
|
||||
|
||||
const wxString filterString = getFilterValue();
|
||||
|
||||
// Special handling for <no net>
|
||||
// Special handling for <do not derive>
|
||||
if( filterString.IsEmpty() || kNoParentSymbol.Lower().Matches( filterString ) )
|
||||
aListContent.insert( aListContent.begin(), kNoParentSymbol );
|
||||
|
||||
// Simple substring, case-insensitive search
|
||||
for( const wxString& symbol : m_symbolList )
|
||||
{
|
||||
if( filterString.IsEmpty() || symbol.Lower().Contains( filterString.Lower() ) )
|
||||
aListContent.push_back( symbol );
|
||||
}
|
||||
}
|
||||
|
||||
wxString m_selectedSymbol;
|
||||
wxArrayString m_symbolList;
|
||||
};
|
||||
|
||||
|
||||
SYMBOL_FILTER_COMBOBOX::SYMBOL_FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxPoint& pos,
|
||||
const wxSize& size, long style ) :
|
||||
FILTER_COMBOBOX( parent, id, pos, size, style )
|
||||
FILTER_COMBOBOX( parent, id, pos, size, style|wxCB_READONLY )
|
||||
{
|
||||
m_selectorPopup = new SYMBOL_FILTER_COMBOPOPUP();
|
||||
setFilterPopup( m_selectorPopup );
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_FILTER_COMBOBOX::SetSymbolList( const wxArrayString& aSymbolList )
|
||||
{
|
||||
m_selectorPopup->SetSymbolList( aSymbolList );
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_FILTER_COMBOBOX::SetSelectedSymbol( const wxString& aSymbolName )
|
||||
{
|
||||
m_selectorPopup->SetSelectedSymbol( aSymbolName );
|
||||
}
|
||||
|
||||
|
||||
wxString SYMBOL_FILTER_COMBOBOX::GetValue() const
|
||||
{
|
||||
wxString value = m_selectorPopup->GetStringValue();
|
||||
|
||||
@@ -37,13 +37,8 @@ public:
|
||||
SYMBOL_FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0 );
|
||||
|
||||
void SetSymbolList( const wxArrayString& aSymbolList );
|
||||
|
||||
void SetSelectedSymbol( const wxString& aSymbolName );
|
||||
|
||||
wxString GetValue() const override;
|
||||
|
||||
protected:
|
||||
SYMBOL_FILTER_COMBOPOPUP* m_selectorPopup;
|
||||
// wxString m_indeterminateString;
|
||||
};
|
||||
|
||||
@@ -46,15 +46,20 @@ public:
|
||||
|
||||
wxWindow* GetControl() override { return this; }
|
||||
|
||||
void SetStringList( const wxArrayString& aStringList );
|
||||
|
||||
wxString GetStringValue() const override;
|
||||
void SetStringValue( const wxString& aNetName ) override;
|
||||
|
||||
void SetSelectedString( const wxString& aString );
|
||||
|
||||
void OnPopup() override;
|
||||
|
||||
void OnStartingKey( wxKeyEvent& aEvent );
|
||||
|
||||
wxSize GetAdjustedSize( int aMinWidth, int aPrefHeight, int aMaxHeight ) override;
|
||||
|
||||
virtual void Accept() = 0;
|
||||
virtual void Accept();
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -67,17 +72,17 @@ protected:
|
||||
*/
|
||||
wxString getFilterValue() const;
|
||||
|
||||
/**
|
||||
* Fill the combobox list
|
||||
*/
|
||||
virtual void getListContent( wxArrayString& aStringList );
|
||||
|
||||
/**
|
||||
* Call this to rebuild the list from the getListContent() method.
|
||||
*/
|
||||
void rebuildList();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Implement this to fill in the given list.
|
||||
*/
|
||||
virtual void getListContent( wxArrayString& aListToFill ) = 0;
|
||||
|
||||
wxSize updateSize();
|
||||
|
||||
void onIdle( wxIdleEvent& aEvent );
|
||||
@@ -98,7 +103,10 @@ protected:
|
||||
int m_minPopupWidth;
|
||||
int m_maxPopupHeight;
|
||||
|
||||
wxEvtHandler* m_focusHandler;
|
||||
wxEvtHandler* m_focusHandler;
|
||||
|
||||
wxString m_selectedString;
|
||||
wxArrayString m_stringList;
|
||||
};
|
||||
|
||||
|
||||
@@ -113,11 +121,21 @@ wxDECLARE_EVENT( FILTERED_ITEM_SELECTED, wxCommandEvent );
|
||||
class FILTER_COMBOBOX : public wxComboCtrl
|
||||
{
|
||||
public:
|
||||
// C'tor matching wxFormBuilder's Custom Control
|
||||
FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0 );
|
||||
|
||||
// C'tor matching wxFormBuilder's ComboxBox.
|
||||
FILTER_COMBOBOX( wxWindow* parent, wxWindowID id, const wxString& value,
|
||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
||||
int count = 0, wxString strings[] = nullptr, long style = 0 );
|
||||
|
||||
~FILTER_COMBOBOX();
|
||||
|
||||
virtual void SetStringList( const wxArrayString& aStringList );
|
||||
|
||||
virtual void SetSelectedString( const wxString& aString );
|
||||
|
||||
protected:
|
||||
void setFilterPopup( FILTER_COMBOPOPUP* aPopup );
|
||||
|
||||
|
||||
@@ -36,17 +36,14 @@ class NET_SELECTOR : public FILTER_COMBOBOX
|
||||
public:
|
||||
// Note: this list of arguments is here because it keeps us from having to customize
|
||||
// the constructor calls in wxFormBuilder.
|
||||
NET_SELECTOR( wxWindow *parent, wxWindowID id,
|
||||
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
|
||||
long style = 0 );
|
||||
NET_SELECTOR( wxWindow *parent, wxWindowID id, const wxPoint &pos = wxDefaultPosition,
|
||||
const wxSize &size = wxDefaultSize, long style = 0 );
|
||||
|
||||
void SetNetInfo( const NETINFO_LIST* aNetInfoList );
|
||||
|
||||
// Set to wxEmptyString to disallow indeterminate settings
|
||||
void SetIndeterminateString( const wxString& aString );
|
||||
|
||||
void SetBoard( BOARD* aBoard );
|
||||
|
||||
void SetSelectedNetcode( int aNetcode );
|
||||
void SetSelectedNet( const wxString& aNetname );
|
||||
void SetIndeterminate();
|
||||
@@ -55,8 +52,12 @@ public:
|
||||
int GetSelectedNetcode();
|
||||
wxString GetSelectedNetname();
|
||||
|
||||
protected:
|
||||
void SetSelectedString( const wxString& aString ) override
|
||||
{
|
||||
wxFAIL_MSG( "Unsupported; use SetSelectedNet() or SetSelectedNetcode()" );
|
||||
}
|
||||
|
||||
protected:
|
||||
NET_SELECTOR_COMBOPOPUP* m_netSelectorPopup;
|
||||
wxString m_indeterminateString;
|
||||
};
|
||||
|
||||
@@ -101,7 +101,6 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS::~DIALOG_CLEANUP_TRACKS_AND_VIAS()
|
||||
void DIALOG_CLEANUP_TRACKS_AND_VIAS::buildFilterLists()
|
||||
{
|
||||
// Populate the net filter list with net names
|
||||
m_netFilter->SetBoard( m_brd );
|
||||
m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
|
||||
|
||||
if( !m_brd->GetHighLightNetCodes().empty() )
|
||||
|
||||
@@ -212,7 +212,6 @@ DIALOG_GLOBAL_EDIT_TEARDROPS::~DIALOG_GLOBAL_EDIT_TEARDROPS()
|
||||
void DIALOG_GLOBAL_EDIT_TEARDROPS::buildFilterLists()
|
||||
{
|
||||
// Populate the net filter list with net names
|
||||
m_netFilter->SetBoard( m_brd );
|
||||
m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
|
||||
|
||||
if( !m_brd->GetHighLightNetCodes().empty() )
|
||||
|
||||
@@ -156,7 +156,6 @@ void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::onUnitsChanged( wxCommandEvent& aEvent
|
||||
void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists()
|
||||
{
|
||||
// Populate the net filter list with net names
|
||||
m_netFilter->SetBoard( m_brd );
|
||||
m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
|
||||
|
||||
if( !m_brd->GetHighLightNetCodes().empty() )
|
||||
|
||||
@@ -162,7 +162,6 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad
|
||||
m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD );
|
||||
m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD );
|
||||
|
||||
m_padNetSelector->SetBoard( m_board );
|
||||
m_padNetSelector->SetNetInfo( &m_board->GetNetInfo() );
|
||||
|
||||
m_cbShowPadOutline->SetValue( m_sketchPreview );
|
||||
|
||||
@@ -1010,7 +1010,6 @@ DIALOG_SHAPE_PROPERTIES::DIALOG_SHAPE_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent,
|
||||
m_LayerSelectionCtrl->SetBoardFrame( m_parent );
|
||||
m_LayerSelectionCtrl->Resync();
|
||||
|
||||
m_netSelector->SetBoard( aParent->GetBoard() );
|
||||
m_netSelector->SetNetInfo( &aParent->GetBoard()->GetNetInfo() );
|
||||
|
||||
if( m_parent->GetFrameType() == FRAME_FOOTPRINT_EDITOR )
|
||||
|
||||
@@ -365,7 +365,6 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_EDIT_FRAME* a
|
||||
m_ViaEndLayer->SetLayerSelection( selection_last_layer );
|
||||
}
|
||||
|
||||
m_netSelector->SetBoard( aParent->GetBoard() );
|
||||
m_netSelector->SetNetInfo( &aParent->GetBoard()->GetNetInfo() );
|
||||
|
||||
if ( net >= 0 )
|
||||
|
||||
Reference in New Issue
Block a user