Remove ability to select "Other" footprint from Symbol Chooser.

We no longer run as a QuasiModal (due to 5206), so we can't put up
the Footprint Browser.

Fixes https://gitlab.com/kicad/code/kicad/issues/7174
This commit is contained in:
Jeff Young 2021-01-19 01:17:40 +00:00
parent 7461b96dea
commit eb80ac464a
4 changed files with 10 additions and 188 deletions

View File

@ -22,9 +22,6 @@
#include <wx/dc.h>
#include <wx/pen.h>
wxDEFINE_EVENT( EVT_INTERACTIVE_CHOICE, wxCommandEvent );
wxColour FOOTPRINT_CHOICE::m_grey( 0x808080 );
@ -51,15 +48,9 @@ void FOOTPRINT_CHOICE::DoSetPopupControl( wxComboPopup* aPopup )
GetVListBoxComboPopup()->Bind( wxEVT_MOTION, &FOOTPRINT_CHOICE::TryVetoMouse, this );
GetVListBoxComboPopup()->Bind( wxEVT_LEFT_DOWN, &FOOTPRINT_CHOICE::TryVetoMouse, this );
GetVListBoxComboPopup()->Bind( wxEVT_LEFT_UP, &FOOTPRINT_CHOICE::TryVetoMouse, this );
GetVListBoxComboPopup()->Bind( wxEVT_LEFT_UP, &FOOTPRINT_CHOICE::OnMouseUp, this );
GetVListBoxComboPopup()->Bind( wxEVT_LEFT_DCLICK, &FOOTPRINT_CHOICE::TryVetoMouse, this );
GetVListBoxComboPopup()->Bind(
wxEVT_LISTBOX, std::bind( &FOOTPRINT_CHOICE::TryVetoSelect, this, _1, true ) );
GetVListBoxComboPopup()->Bind( wxEVT_LISTBOX, std::bind( &FOOTPRINT_CHOICE::TryVetoSelect, this, _1, true ) );
Bind( wxEVT_COMBOBOX, std::bind( &FOOTPRINT_CHOICE::TryVetoSelect, this, _1, false ) );
GetVListBoxComboPopup()->Bind(
wxEVT_CHAR_HOOK, std::bind( &FOOTPRINT_CHOICE::TrySkipSeparator, this, _1, true ) );
GetVListBoxComboPopup()->Bind( wxEVT_CHAR_HOOK, &FOOTPRINT_CHOICE::OnKeyUp, this );
Bind( wxEVT_KEY_DOWN, std::bind( &FOOTPRINT_CHOICE::TrySkipSeparator, this, _1, false ) );
}
@ -164,33 +155,6 @@ void FOOTPRINT_CHOICE::TryVetoMouse( wxMouseEvent& aEvent )
}
void FOOTPRINT_CHOICE::OnMouseUp( wxMouseEvent& aEvent )
{
int item = GetVListBoxComboPopup()->VirtualHitTest( aEvent.GetPosition().y );
wxCommandEvent evt( EVT_INTERACTIVE_CHOICE );
evt.SetInt( item );
wxPostEvent( this, evt );
aEvent.Skip();
}
void FOOTPRINT_CHOICE::OnKeyUp( wxKeyEvent& aEvent )
{
int item = GetSelectionEither( true );
if( aEvent.GetKeyCode() == WXK_RETURN )
{
wxCommandEvent evt( EVT_INTERACTIVE_CHOICE );
evt.SetInt( item );
wxPostEvent( this, evt );
}
aEvent.Skip();
}
void FOOTPRINT_CHOICE::TryVetoSelect( wxCommandEvent& aEvent, bool aInner )
{
int sel = GetSelectionEither( aInner );
@ -212,28 +176,6 @@ void FOOTPRINT_CHOICE::TryVetoSelect( wxCommandEvent& aEvent, bool aInner )
}
void FOOTPRINT_CHOICE::TrySkipSeparator( wxKeyEvent& aEvent, bool aInner )
{
int key = aEvent.GetKeyCode();
int sel = GetSelectionEither( aInner );
int new_sel = sel;
if( key == WXK_UP && SafeGetString( sel - 1 ) == wxEmptyString )
{
new_sel = sel - 2;
}
else if( key == WXK_DOWN && SafeGetString( sel + 1 ) == wxEmptyString )
{
new_sel = sel + 2;
}
if( new_sel != sel )
SetSelectionEither( aInner, new_sel );
else
aEvent.Skip();
}
wxString FOOTPRINT_CHOICE::SafeGetString( int aItem ) const
{
if( aItem >= 0 && aItem < (int) GetCount() )

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2021 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
@ -17,7 +17,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <dialog_shim.h>
#include <eda_draw_frame.h>
#include <kiway.h>
#include <kiway_player.h>
@ -28,16 +27,6 @@
#include <wx/wupdlock.h>
#include <widgets/progress_reporter.h>
/**
* Fixed positions for standard items in the list
*/
enum
{
POS_DEFAULT,
POS_OTHER,
POS_SEPARATOR
};
wxDEFINE_EVENT( EVT_FOOTPRINT_SELECTED, wxCommandEvent );
@ -62,7 +51,6 @@ FOOTPRINT_SELECT_WIDGET::FOOTPRINT_SELECT_WIDGET( EDA_DRAW_FRAME* aFrame, wxWind
m_sizer->Fit( this );
m_fp_sel_ctrl->Bind( wxEVT_COMBOBOX, &FOOTPRINT_SELECT_WIDGET::OnComboBox, this );
m_fp_sel_ctrl->Bind( EVT_INTERACTIVE_CHOICE, &FOOTPRINT_SELECT_WIDGET::OnComboInteractive, this );
}
@ -90,89 +78,22 @@ void FOOTPRINT_SELECT_WIDGET::OnComboBox( wxCommandEvent& aEvent )
wxCommandEvent evt( EVT_FOOTPRINT_SELECTED );
int sel = m_fp_sel_ctrl->GetSelection();
switch( sel )
{
case wxNOT_FOUND: return;
if( sel == wxNOT_FOUND )
return;
case POS_SEPARATOR:
// User somehow managed to select the separator. This should not be
// possible, but just in case... deselect it
m_fp_sel_ctrl->SetSelection( m_last_item );
break;
wxStringClientData* clientdata =
static_cast<wxStringClientData*>( m_fp_sel_ctrl->GetClientObject( sel ) );
wxASSERT( clientdata );
case POS_OTHER:
// When POS_OTHER is selected, a dialog should be shown. However, we don't want to
// do this ALL the time, as some times (e.g. when moving around with the arrow keys)
// it could be very annoying. Therefore showing the picker is done from the custom
// "interactive select" event on FOOTPRINT_CHOICE, which only fires for more direct
// choice actions.
break;
default:
{
wxStringClientData* clientdata =
static_cast<wxStringClientData*>( m_fp_sel_ctrl->GetClientObject( sel ) );
wxASSERT( clientdata );
evt.SetString( clientdata->GetData() );
wxPostEvent( this, evt );
}
}
}
void FOOTPRINT_SELECT_WIDGET::OnComboInteractive( wxCommandEvent& aEvent )
{
if( aEvent.GetInt() == POS_OTHER && !m_fp_sel_ctrl->IsPopupShown() )
{
DoOther();
}
}
void FOOTPRINT_SELECT_WIDGET::DoOther()
{
wxCommandEvent evt( EVT_FOOTPRINT_SELECTED );
wxString fpname = ShowPicker();
m_other_footprint = fpname;
UpdateList();
m_fp_sel_ctrl->SetSelection( POS_OTHER );
m_last_item = POS_OTHER;
evt.SetString( m_other_footprint );
evt.SetString( clientdata->GetData() );
wxPostEvent( this, evt );
}
wxString FOOTPRINT_SELECT_WIDGET::ShowPicker()
{
wxString fpname;
wxWindow* parent = ::wxGetTopLevelParent( this );
DIALOG_SHIM* dsparent = dynamic_cast<DIALOG_SHIM*>( parent );
// Only quasimodal dialogs can launch modal kiface dialogs. Otherwise the
// event loop goes all silly.
wxASSERT( !dsparent || dsparent->IsQuasiModal() );
auto frame = m_kiway->Player( FRAME_FOOTPRINT_VIEWER_MODAL, true );
if( !frame->ShowModal( &fpname, parent ) )
{
fpname = wxEmptyString;
}
frame->Destroy();
return fpname;
}
void FOOTPRINT_SELECT_WIDGET::ClearFilters()
{
m_fp_filter.ClearFilters();
m_default_footprint.Clear();
m_other_footprint.Clear();
m_zero_filter = false;
}
@ -213,14 +134,7 @@ bool FOOTPRINT_SELECT_WIDGET::UpdateList()
m_fp_sel_ctrl->Append( m_default_footprint.IsEmpty() ?
_( "No default footprint" ) :
"[" + _( "Default" ) + "] " + m_default_footprint,
new wxStringClientData( m_default_footprint ) );
m_fp_sel_ctrl->Append( m_other_footprint.IsEmpty() ?
_( "Other..." ) :
"[" + _( "Other..." ) + "] " + m_other_footprint,
new wxStringClientData( m_other_footprint ) );
m_fp_sel_ctrl->Append( "", new wxStringClientData( "" ) );
new wxStringClientData( m_default_footprint ) );
if( !m_zero_filter )
{
@ -243,7 +157,7 @@ bool FOOTPRINT_SELECT_WIDGET::UpdateList()
void FOOTPRINT_SELECT_WIDGET::SelectDefault()
{
m_fp_sel_ctrl->SetSelection( POS_DEFAULT );
m_fp_sel_ctrl->SetSelection( 0 );
}

View File

@ -22,14 +22,6 @@
#include <wx/odcombo.h>
/**
* Event thrown when an item is selected "interactively". This includes direct clicks
* and presses of the Enter key, but not arrow key motion. Integer data will be the
* item selected.
*/
wxDECLARE_EVENT( EVT_INTERACTIVE_CHOICE, wxCommandEvent );
/**
* Customized combo box for footprint selection. This provides the following features:
*
@ -72,24 +64,6 @@ protected:
*/
void TryVetoSelect( wxCommandEvent& aEvent, bool aInner );
/**
* Mouse up on an item in the list.
*/
void OnMouseUp( wxMouseEvent& aEvent );
/**
* Key up on an item in the list.
*/
void OnKeyUp( wxKeyEvent& aEvent );
/**
* For arrow key events, skip over separators.
*
* @param aEvent - the wxKeyEvent caller
* @param aInner - true if event was called for the inner list (ie the popup)
*/
void TrySkipSeparator( wxKeyEvent& aEvent, bool aInner );
/**
* Safely get a string for an item, returning wxEmptyString if the item doesn't exist.
*/

View File

@ -131,7 +131,6 @@ private:
bool m_update;
int m_max_items;
wxString m_default_footprint;
wxString m_other_footprint;
int m_last_item;
FOOTPRINT_LIST* m_fp_list;
@ -139,13 +138,6 @@ private:
bool m_zero_filter;
void OnComboBox( wxCommandEvent& aEvent );
void OnComboInteractive( wxCommandEvent& aEvent );
/// Show the component picker and return the selected component. Used by DoOther()
wxString ShowPicker();
/// Handle activation of the "Other..." item
void DoOther();
};