Implement add-new-on-return for some of our grids.
Fixes https://gitlab.com/kicad/code/kicad/issues/12335
This commit is contained in:
parent
98e760da93
commit
f179754118
|
@ -89,8 +89,16 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO
|
|||
m_EnvVars->SetDefaultRowSize( m_EnvVars->GetDefaultRowSize() + 4 );
|
||||
m_SearchPaths->SetDefaultRowSize( m_SearchPaths->GetDefaultRowSize() + 4 );
|
||||
|
||||
m_EnvVars->PushEventHandler( new GRID_TRICKS( m_EnvVars ) );
|
||||
m_SearchPaths->PushEventHandler( new GRID_TRICKS( m_SearchPaths ) );
|
||||
m_EnvVars->PushEventHandler( new GRID_TRICKS( m_EnvVars,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddEnvVar( aEvent );
|
||||
} ) );
|
||||
m_SearchPaths->PushEventHandler( new GRID_TRICKS( m_SearchPaths,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddSearchPath( aEvent );
|
||||
} ) );
|
||||
|
||||
m_EnvVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
||||
m_SearchPaths->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
||||
|
|
|
@ -54,7 +54,10 @@ PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES( wxWindow* aParent, PROJECT* aProject
|
|||
m_nameValidator.SetStyle( wxFILTER_EXCLUDE_CHAR_LIST );
|
||||
m_nameValidator.SetCharExcludes( wxT( "{}[]()%~<>\"='`;:.,&?/\\|$" ) );
|
||||
|
||||
m_TextVars->PushEventHandler( new GRID_TRICKS( m_TextVars ) );
|
||||
m_TextVars->PushEventHandler( new GRID_TRICKS( m_TextVars, [this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddTextVar( aEvent );
|
||||
} ) );
|
||||
m_TextVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
||||
|
||||
// wxFormBuilder doesn't include this event...
|
||||
|
|
|
@ -37,34 +37,52 @@
|
|||
#define ROW_SEP wxT( '\n' )
|
||||
|
||||
|
||||
GRID_TRICKS::GRID_TRICKS( WX_GRID* aGrid ):
|
||||
m_grid( aGrid )
|
||||
GRID_TRICKS::GRID_TRICKS( WX_GRID* aGrid ) :
|
||||
m_grid( aGrid ),
|
||||
m_addHandler( []( wxCommandEvent& ) {} )
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
GRID_TRICKS::GRID_TRICKS( WX_GRID* aGrid, std::function<void( wxCommandEvent& )> aAddHandler ) :
|
||||
m_grid( aGrid ),
|
||||
m_addHandler( aAddHandler )
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void GRID_TRICKS::init()
|
||||
{
|
||||
m_sel_row_start = 0;
|
||||
m_sel_col_start = 0;
|
||||
m_sel_row_count = 0;
|
||||
m_sel_col_count = 0;
|
||||
|
||||
aGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), nullptr, this );
|
||||
aGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), nullptr, this );
|
||||
aGrid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), nullptr, this );
|
||||
aGrid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), nullptr, this );
|
||||
aGrid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridLabelLeftClick ), nullptr, this );
|
||||
aGrid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED,
|
||||
wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), nullptr, this );
|
||||
aGrid->Connect( wxEVT_CHAR_HOOK, wxCharEventHandler( GRID_TRICKS::onCharHook ), nullptr, this );
|
||||
aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), nullptr, this );
|
||||
aGrid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ),
|
||||
nullptr, this );
|
||||
m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
|
||||
wxGridEventHandler( GRID_TRICKS::onGridLabelLeftClick ), nullptr, this );
|
||||
m_grid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED,
|
||||
wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_CHAR_HOOK,
|
||||
wxCharEventHandler( GRID_TRICKS::onCharHook ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_KEY_DOWN,
|
||||
wxKeyEventHandler( GRID_TRICKS::onKeyDown ), nullptr, this );
|
||||
m_grid->Connect( wxEVT_UPDATE_UI,
|
||||
wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ), nullptr, this );
|
||||
|
||||
// The handlers that control the tooltips must be on the actual grid window, not the grid
|
||||
aGrid->GetGridWindow()->Connect( wxEVT_MOTION,
|
||||
wxMouseEventHandler( GRID_TRICKS::onGridMotion ), nullptr, this );
|
||||
m_grid->GetGridWindow()->Connect( wxEVT_MOTION,
|
||||
wxMouseEventHandler( GRID_TRICKS::onGridMotion ), nullptr,
|
||||
this );
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,7 +418,15 @@ void GRID_TRICKS::onCharHook( wxKeyEvent& ev )
|
|||
{
|
||||
bool handled = false;
|
||||
|
||||
if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
|
||||
if( ev.GetKeyCode() == WXK_RETURN && m_grid->GetGridCursorRow() == m_grid->GetNumberRows() - 1 )
|
||||
{
|
||||
if( m_grid->CommitPendingChanges() )
|
||||
{
|
||||
wxCommandEvent dummy;
|
||||
m_addHandler( dummy );
|
||||
}
|
||||
}
|
||||
else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
|
||||
{
|
||||
if( m_grid->IsCellEditControlShown() && wxTheClipboard->Open() )
|
||||
{
|
||||
|
|
|
@ -672,7 +672,10 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent,
|
|||
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
||||
|
||||
m_grid->SetTable( m_dataModel );
|
||||
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
||||
m_grid->PushEventHandler( new GRID_TRICKS( m_grid, [this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddRow( aEvent );
|
||||
} ) );
|
||||
|
||||
// Show/hide columns according to the user's preference
|
||||
SYMBOL_EDITOR_SETTINGS* cfg = parent->GetSettings();
|
||||
|
|
|
@ -184,7 +184,11 @@ DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES( SYMBOL_EDIT_FRAME* parent, LIB_PIN
|
|||
m_alternatesGrid->SetDefaultRowSize( m_alternatesGrid->GetDefaultRowSize() + 4 );
|
||||
|
||||
m_alternatesGrid->SetTable( m_alternatesDataModel );
|
||||
m_alternatesGrid->PushEventHandler( new GRID_TRICKS( m_alternatesGrid ) );
|
||||
m_alternatesGrid->PushEventHandler( new GRID_TRICKS( m_alternatesGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddAlternate( aEvent );
|
||||
} ) );
|
||||
|
||||
if( aPin->GetParent()->HasConversion() )
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <sch_edit_frame.h>
|
||||
#include <schematic.h>
|
||||
#include <dialogs/panel_setup_buses.h>
|
||||
#include "grid_tricks.h"
|
||||
|
||||
PANEL_SETUP_BUSES::PANEL_SETUP_BUSES( wxWindow* aWindow, SCH_EDIT_FRAME* aFrame ) :
|
||||
PANEL_SETUP_BUSES_BASE( aWindow ),
|
||||
|
@ -41,6 +42,21 @@ PANEL_SETUP_BUSES::PANEL_SETUP_BUSES( wxWindow* aWindow, SCH_EDIT_FRAME* aFrame
|
|||
|
||||
m_source->SetFont( KIUI::GetInfoFont( aWindow ) );
|
||||
|
||||
m_aliasesGrid->PushEventHandler( new GRID_TRICKS( m_aliasesGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddAlias( aEvent );
|
||||
} ) );
|
||||
|
||||
m_membersGrid->PushEventHandler( new GRID_TRICKS( m_membersGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
wxIdleEvent dummy;
|
||||
reloadMembersGridOnIdle( dummy );
|
||||
|
||||
OnAddMember( aEvent );
|
||||
} ) );
|
||||
|
||||
// wxFormBuilder doesn't include this event...
|
||||
m_aliasesGrid->Connect( wxEVT_GRID_CELL_CHANGING,
|
||||
wxGridEventHandler( PANEL_SETUP_BUSES::OnAliasesGridCellChanging ),
|
||||
|
@ -53,6 +69,20 @@ PANEL_SETUP_BUSES::PANEL_SETUP_BUSES( wxWindow* aWindow, SCH_EDIT_FRAME* aFrame
|
|||
}
|
||||
|
||||
|
||||
PANEL_SETUP_BUSES::~PANEL_SETUP_BUSES()
|
||||
{
|
||||
// Delete the GRID_TRICKS.
|
||||
m_aliasesGrid->PopEventHandler( true );
|
||||
m_membersGrid->PopEventHandler( true );
|
||||
|
||||
m_aliasesGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
||||
wxGridEventHandler( PANEL_SETUP_BUSES::OnAliasesGridCellChanging ),
|
||||
nullptr, this );
|
||||
m_membersGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
||||
wxGridEventHandler( PANEL_SETUP_BUSES::OnMemberGridCellChanging ),
|
||||
nullptr, this );
|
||||
}
|
||||
|
||||
bool PANEL_SETUP_BUSES::TransferDataToWindow()
|
||||
{
|
||||
auto contains =
|
||||
|
@ -175,7 +205,7 @@ void PANEL_SETUP_BUSES::OnAddMember( wxCommandEvent& aEvent )
|
|||
if( !m_membersGrid->CommitPendingChanges() )
|
||||
return;
|
||||
|
||||
int row = m_aliasesGrid->GetNumberRows();
|
||||
int row = m_membersGrid->GetNumberRows();
|
||||
m_membersGrid->AppendRows();
|
||||
|
||||
m_membersGrid->MakeCellVisible( row, 0 );
|
||||
|
@ -274,6 +304,7 @@ void PANEL_SETUP_BUSES::OnMemberGridCellChanging( wxGridEvent& event )
|
|||
}
|
||||
}
|
||||
|
||||
m_membersGridDirty = true;
|
||||
Bind( wxEVT_IDLE, &PANEL_SETUP_BUSES::reloadMembersGridOnIdle, this );
|
||||
}
|
||||
}
|
||||
|
@ -306,12 +337,15 @@ void PANEL_SETUP_BUSES::doReloadMembersGrid()
|
|||
for( const wxString& member : alias->Members() )
|
||||
m_membersGrid->SetCellValue( ii++, 0, member );
|
||||
}
|
||||
|
||||
m_membersGridDirty = false;
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SETUP_BUSES::reloadMembersGridOnIdle( wxIdleEvent& aEvent )
|
||||
{
|
||||
doReloadMembersGrid();
|
||||
if( m_membersGridDirty )
|
||||
doReloadMembersGrid();
|
||||
|
||||
Unbind( wxEVT_IDLE, &PANEL_SETUP_BUSES::reloadMembersGridOnIdle, this );
|
||||
}
|
||||
|
@ -401,6 +435,7 @@ void PANEL_SETUP_BUSES::OnUpdateUI( wxUpdateUIEvent& event )
|
|||
const std::shared_ptr<BUS_ALIAS>& alias = m_aliases[ row ];
|
||||
alias->SetName( aliasName );
|
||||
|
||||
m_membersGridDirty = true;
|
||||
Bind( wxEVT_IDLE, &PANEL_SETUP_BUSES::reloadMembersGridOnIdle, this );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class PANEL_SETUP_BUSES : public PANEL_SETUP_BUSES_BASE
|
|||
public:
|
||||
PANEL_SETUP_BUSES( wxWindow* aWindow, SCH_EDIT_FRAME* aFrame );
|
||||
|
||||
~PANEL_SETUP_BUSES() {}
|
||||
~PANEL_SETUP_BUSES();
|
||||
|
||||
bool TransferDataFromWindow() override;
|
||||
bool TransferDataToWindow() override;
|
||||
|
@ -61,6 +61,7 @@ private:
|
|||
std::vector< std::shared_ptr<BUS_ALIAS> > m_aliases;
|
||||
int m_lastAlias;
|
||||
wxString m_lastAliasName;
|
||||
bool m_membersGridDirty;
|
||||
|
||||
wxString m_errorMsg;
|
||||
WX_GRID* m_errorGrid;
|
||||
|
|
|
@ -75,7 +75,10 @@ PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES( wxWindow* aWindow,
|
|||
|
||||
m_checkboxColWidth = m_grid->GetColSize( 1 );
|
||||
|
||||
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
||||
m_grid->PushEventHandler( new GRID_TRICKS( m_grid, [this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddButtonClick( aEvent );
|
||||
} ) );
|
||||
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,8 @@ class GRID_TRICKS : public wxEvtHandler
|
|||
public:
|
||||
explicit GRID_TRICKS( WX_GRID* aGrid );
|
||||
|
||||
GRID_TRICKS( WX_GRID* aGrid, std::function<void( wxCommandEvent& )> aAddHandler );
|
||||
|
||||
/**
|
||||
* Enable the tooltip for a column.
|
||||
*
|
||||
|
@ -85,6 +87,9 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
/// Shared initialization for various ctors.
|
||||
void init();
|
||||
|
||||
/// Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
|
||||
void getSelectedArea();
|
||||
|
||||
|
@ -110,6 +115,7 @@ protected:
|
|||
virtual void paste_text( const wxString& cb_text );
|
||||
virtual void cutcopy( bool doCopy, bool doDelete );
|
||||
|
||||
protected:
|
||||
WX_GRID* m_grid; ///< I don't own the grid, but he owns me
|
||||
|
||||
// row & col "selection" acquisition
|
||||
|
@ -119,7 +125,9 @@ protected:
|
|||
int m_sel_row_count;
|
||||
int m_sel_col_count;
|
||||
|
||||
std::bitset<GRIDTRICKS_MAX_COL> m_tooltipEnabled;
|
||||
std::function<void( wxCommandEvent& )> m_addHandler;
|
||||
|
||||
std::bitset<GRIDTRICKS_MAX_COL> m_tooltipEnabled;
|
||||
};
|
||||
|
||||
#endif // _GRID_TRICKS_H_
|
||||
|
|
|
@ -54,7 +54,10 @@ DIALOG_MANAGE_REPOSITORIES::DIALOG_MANAGE_REPOSITORIES(
|
|||
addMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &DIALOG_MANAGE_REPOSITORIES::OnAddDefault, this,
|
||||
menuItem->GetId() );
|
||||
|
||||
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
||||
m_grid->PushEventHandler( new GRID_TRICKS( m_grid, [this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAdd( aEvent );
|
||||
} ) );
|
||||
|
||||
for( int col = 0; col < m_grid->GetNumberCols(); col++ )
|
||||
{
|
||||
|
|
|
@ -161,7 +161,16 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(
|
|||
m_privateLayersGrid->SetTable( m_privateLayers );
|
||||
|
||||
m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
|
||||
m_privateLayersGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
|
||||
m_privateLayersGrid->PushEventHandler( new GRID_TRICKS( m_privateLayersGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddLayer( aEvent );
|
||||
} ) );
|
||||
m_padGroupsGrid->PushEventHandler( new GRID_TRICKS( m_padGroupsGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddPadGroup( aEvent );
|
||||
} ) );
|
||||
|
||||
m_itemsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
||||
m_privateLayersGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
||||
|
@ -224,6 +233,7 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR()
|
|||
// Delete the GRID_TRICKS.
|
||||
m_itemsGrid->PopEventHandler( true );
|
||||
m_privateLayersGrid->PopEventHandler( true );
|
||||
m_padGroupsGrid->PopEventHandler( true );
|
||||
|
||||
m_page = static_cast<NOTEBOOK_PAGES>( m_NoteBook->GetSelection() );
|
||||
|
||||
|
|
|
@ -62,7 +62,10 @@ PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL(
|
|||
{
|
||||
m_modelsGrid->SetDefaultRowSize( m_modelsGrid->GetDefaultRowSize() + 4 );
|
||||
|
||||
GRID_TRICKS* trick = new GRID_TRICKS( m_modelsGrid );
|
||||
GRID_TRICKS* trick = new GRID_TRICKS( m_modelsGrid, [this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAdd3DRow( aEvent );
|
||||
} );
|
||||
trick->SetTooltipEnable( COL_PROBLEM );
|
||||
|
||||
m_modelsGrid->PushEventHandler( trick );
|
||||
|
|
|
@ -77,9 +77,21 @@ PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS( PAGED_DIALOG* aParent,
|
|||
m_viaSizesGrid->SetDefaultRowSize( m_viaSizesGrid->GetDefaultRowSize() + 4 );
|
||||
m_diffPairsGrid->SetDefaultRowSize( m_diffPairsGrid->GetDefaultRowSize() + 4 );
|
||||
|
||||
m_trackWidthsGrid->PushEventHandler( new GRID_TRICKS( m_trackWidthsGrid ) );
|
||||
m_viaSizesGrid->PushEventHandler( new GRID_TRICKS( m_viaSizesGrid ) );
|
||||
m_diffPairsGrid->PushEventHandler( new GRID_TRICKS( m_diffPairsGrid ) );
|
||||
m_trackWidthsGrid->PushEventHandler( new GRID_TRICKS( m_trackWidthsGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddTrackWidthsClick( aEvent );
|
||||
} ) );
|
||||
m_viaSizesGrid->PushEventHandler( new GRID_TRICKS( m_viaSizesGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddViaSizesClick( aEvent );
|
||||
} ) );
|
||||
m_diffPairsGrid->PushEventHandler( new GRID_TRICKS( m_diffPairsGrid,
|
||||
[this]( wxCommandEvent& aEvent )
|
||||
{
|
||||
OnAddDiffPairsClick( aEvent );
|
||||
} ) );
|
||||
|
||||
m_trackWidthsGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
||||
m_viaSizesGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
||||
|
|
Loading…
Reference in New Issue