Add pre-select architecture to grid helper icon-text-buttons.

Fixes: lp:1813973
* https://bugs.launchpad.net/kicad/+bug/1813973
This commit is contained in:
Jeff Young 2019-01-31 01:07:53 +00:00
parent 88d9f946a2
commit ba7b970817
7 changed files with 97 additions and 18 deletions

View File

@ -157,9 +157,11 @@ void GRID_CELL_TEXT_BUTTON::Reset()
class TEXT_BUTTON_SYMBOL_CHOOSER : public wxComboCtrl
{
public:
TEXT_BUTTON_SYMBOL_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg ) :
TEXT_BUTTON_SYMBOL_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg,
const wxString& aPreselect ) :
wxComboCtrl( aParent ),
m_dlg( aParentDlg )
m_dlg( aParentDlg ),
m_preselect( aPreselect )
{
SetButtonBitmaps( KiBitmap( small_library_xpm ) );
}
@ -174,6 +176,10 @@ protected:
{
// pick a footprint using the footprint picker.
wxString compid = GetValue();
if( compid.IsEmpty() )
compid = m_preselect;
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SCH_VIEWER_MODAL, true, m_dlg );
if( frame->ShowModal( &compid, m_dlg ) )
@ -183,13 +189,14 @@ protected:
}
DIALOG_SHIM* m_dlg;
wxString m_preselect;
};
void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg );
m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg, m_preselect );
wxGridCellEditor::Create(aParent, aId, aEventHandler);
}
@ -202,9 +209,11 @@ void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
class TEXT_BUTTON_FP_CHOOSER : public wxComboCtrl
{
public:
TEXT_BUTTON_FP_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg ) :
TEXT_BUTTON_FP_CHOOSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg,
const wxString& aPreselect ) :
wxComboCtrl( aParent ),
m_dlg( aParentDlg )
m_dlg( aParentDlg ),
m_preselect( aPreselect )
{
SetButtonBitmaps( KiBitmap( small_library_xpm ) );
}
@ -219,6 +228,10 @@ protected:
{
// pick a footprint using the footprint picker.
wxString fpid = GetValue();
if( fpid.IsEmpty() )
fpid = m_preselect;
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, m_dlg );
if( frame->ShowModal( &fpid, m_dlg ) )
@ -228,13 +241,14 @@ protected:
}
DIALOG_SHIM* m_dlg;
wxString m_preselect;
};
void GRID_CELL_FOOTPRINT_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg );
m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg, m_preselect );
wxGridCellEditor::Create(aParent, aId, aEventHandler);
}

View File

@ -347,7 +347,12 @@ private:
{
if( m_isModified )
revertChanges();
event.Skip();
// Just skipping the event doesn't work after the library browser was run
if( IsQuasiModal() )
EndQuasiModal( wxID_CANCEL );
else
event.Skip();
}
// Undo all changes, and clear the list of new lib_ids
@ -550,8 +555,8 @@ void DIALOG_EDIT_COMPONENTS_LIBID::AddRowToGrid( bool aMarkRow, const wxString&
// set new libid column browse button
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this ) );
m_grid->SetColAttr( COL_NEW_LIBID, attr );
attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this, aStrLibId ) );
m_grid->SetAttr( row, COL_NEW_LIBID, attr );
}
@ -727,6 +732,14 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow )
#else
// Use library viewer to choose a symbol
LIB_ID aPreselectedLibid;
wxString current = m_grid->GetCellValue( aRow, COL_NEW_LIBID );
if( current.IsEmpty() )
current = m_grid->GetCellValue( aRow, COL_CURR_LIBID );
if( !current.IsEmpty() )
aPreselectedLibid.Parse( current, LIB_ID::ID_SCH, true );
SCH_BASE_FRAME::COMPONENT_SELECTION sel =
m_parent->SelectComponentFromLibBrowser( this, NULL, aPreselectedLibid, 0, 0 );
#endif

View File

@ -103,7 +103,6 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::DIALOG_EDIT_COMPONENTS_LIBID_BASE( wxWindow*
// Connect Events
m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::OnSizeGrid ), NULL, this );
m_buttonUndo->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this );
m_buttonUndo->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this );
@ -116,7 +115,6 @@ DIALOG_EDIT_COMPONENTS_LIBID_BASE::~DIALOG_EDIT_COMPONENTS_LIBID_BASE()
{
// Disconnect Events
m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onCellBrowseLib ), NULL, this );
m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::OnSizeGrid ), NULL, this );
m_buttonUndo->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::onUndoChangesButton ), NULL, this );
m_buttonUndo->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_EDIT_COMPONENTS_LIBID_BASE::updateUIChangesButton ), NULL, this );

View File

@ -185,7 +185,6 @@
<event name="OnGridCellChange"></event>
<event name="OnGridCellLeftClick"></event>
<event name="OnGridCellLeftDClick">onCellBrowseLib</event>
<event name="OnGridCellRightClick">onCellBrowseLib</event>
<event name="OnGridCellRightDClick"></event>
<event name="OnGridCmdCellChange"></event>
<event name="OnGridCmdCellLeftClick"></event>

View File

@ -47,7 +47,7 @@
#include <class_library.h>
#include <view/view_controls.h>
#include <sch_painter.h>
#include <confirm.h>
// Save previous component library viewer state.
wxString LIB_VIEW_FRAME::m_libraryName;
@ -320,6 +320,46 @@ void LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton( wxUpdateUIEvent& aEvent )
}
bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
{
if( aSymbol && !aSymbol->IsEmpty() )
{
wxString msg;
LIB_TABLE* libTable = Prj().SchSymbolLibTable();
LIB_ID libid;
libid.Parse( *aSymbol, LIB_ID::ID_SCH, true );
if( libid.IsValid() )
{
wxString nickname = libid.GetLibNickname();
if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
{
msg.sprintf( _( "The current configuration does not include a library with the\n"
"nickname \"%s\". Use Manage Symbol Libraries\n"
"to edit the configuration." ), nickname );
DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg );
}
else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
{
msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
"in the current configuration. Use Manage Symbol Libraries to\n"
"edit the configuration." ), nickname );
DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
}
else
{
SetSelectedLibrary( libid.GetLibNickname() );
SetSelectedComponent( libid.GetLibItemName() );
}
}
}
return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
}
void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event )
{
GetCanvas()->StopDrawing();

View File

@ -58,6 +58,15 @@ public:
~LIB_VIEW_FRAME();
/**
* Function ShowModal
*
* Runs the Symbol Viewer as a modal dialog.
* @param aSymbol an optional FPID string to initialize the viewer with and to
* return a selected footprint through.
*/
bool ShowModal( wxString* aSymbol, wxWindow* aParent ) override;
void OnSize( wxSizeEvent& event ) override;
/**

View File

@ -60,27 +60,32 @@ protected:
class GRID_CELL_SYMBOL_ID_EDITOR : public GRID_CELL_TEXT_BUTTON
{
public:
GRID_CELL_SYMBOL_ID_EDITOR( DIALOG_SHIM* aParent ) :
m_dlg( aParent )
GRID_CELL_SYMBOL_ID_EDITOR( DIALOG_SHIM* aParent,
const wxString& aPreselect = wxEmptyString ) :
m_dlg( aParent ),
m_preselect( aPreselect )
{ }
wxGridCellEditor* Clone() const override
{
return new GRID_CELL_SYMBOL_ID_EDITOR( m_dlg );
return new GRID_CELL_SYMBOL_ID_EDITOR( m_dlg, m_preselect );
}
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
protected:
DIALOG_SHIM* m_dlg;
wxString m_preselect;
};
class GRID_CELL_FOOTPRINT_ID_EDITOR : public GRID_CELL_TEXT_BUTTON
{
public:
GRID_CELL_FOOTPRINT_ID_EDITOR( DIALOG_SHIM* aParent ) :
m_dlg( aParent )
GRID_CELL_FOOTPRINT_ID_EDITOR( DIALOG_SHIM* aParent,
const wxString& aPreselect = wxEmptyString ) :
m_dlg( aParent ),
m_preselect( aPreselect )
{ }
wxGridCellEditor* Clone() const override
@ -92,6 +97,7 @@ public:
protected:
DIALOG_SHIM* m_dlg;
wxString m_preselect;
};