From 8bf57814a42e4dc78113505f182f60a268386cf3 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Wed, 31 Oct 2012 09:41:47 -0500 Subject: [PATCH] implement move up, move down in lib table editor --- pcbnew/dialogs/dialog_fp_lib_table.cpp | 47 +++++++++++++++++++------- pcbnew/kicad_plugin.cpp | 3 +- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index b78e9ff883..b8fadde2c3 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -231,7 +231,6 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE void pageChangedHandler( wxAuiNotebookEvent& event ) { int pageNdx = m_auinotebook->GetSelection(); - m_cur_grid = pageNdx==0 ? m_global_grid : m_project_grid; D(printf("%s cur_grid is %s\n", __func__, pageNdx==0 ? "global" : "project" );) @@ -239,37 +238,33 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE void appendRowHandler( wxMouseEvent& event ) { - D(printf("%s\n", __func__);) m_cur_grid->AppendRows( 1 ); } void deleteRowHandler( wxMouseEvent& event ) { - D(printf("%s\n", __func__);) - int curRow = m_cur_grid->GetGridCursorRow(); - m_cur_grid->DeleteRows( curRow ); } void moveUpHandler( wxMouseEvent& event ) { - D(printf("%s\n", __func__);) - int curRow = m_cur_grid->GetGridCursorRow(); if( curRow >= 1 ) { + int curCol = m_cur_grid->GetGridCursorCol(); + FP_TBL_MODEL* tbl = (FP_TBL_MODEL*) m_cur_grid->GetTable(); - ROW save = tbl->rows[curRow]; + ROW move_me = tbl->rows[curRow]; - tbl->DeleteRows( curRow, 1 ); - tbl->InsertRows( --curRow, 1 ); - - tbl->rows[curRow] = save; + tbl->rows.erase( tbl->rows.begin() + curRow ); + --curRow; + tbl->rows.insert( tbl->rows.begin() + curRow, move_me ); if( tbl->GetView() ) { + // fire a msg to cause redrawing wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, @@ -277,11 +272,39 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE tbl->GetView()->ProcessTableMessage( msg ); } + + m_cur_grid->SetGridCursor( curRow, curCol ); } } void moveDownHandler( wxMouseEvent& event ) { + FP_TBL_MODEL* tbl = (FP_TBL_MODEL*) m_cur_grid->GetTable(); + + int curRow = m_cur_grid->GetGridCursorRow(); + if( unsigned( curRow + 1 ) < tbl->rows.size() ) + { + int curCol = m_cur_grid->GetGridCursorCol(); + + ROW move_me = tbl->rows[curRow]; + + tbl->rows.erase( tbl->rows.begin() + curRow ); + ++curRow; + tbl->rows.insert( tbl->rows.begin() + curRow, move_me ); + + if( tbl->GetView() ) + { + // fire a msg to cause redrawing + wxGridTableMessage msg( tbl, + wxGRIDTABLE_NOTIFY_ROWS_INSERTED, + curRow - 1, + 0 ); + + tbl->GetView()->ProcessTableMessage( msg ); + } + + m_cur_grid->SetGridCursor( curRow, curCol ); + } D(printf("%s\n", __func__);) } diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 6fcfa699ef..b52507060a 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -240,7 +240,8 @@ void FP_CACHE::Load() } // reader now owns fp, will close on exception or return - PCB_PARSER parser( new FILE_LINE_READER( fp, fpFileName ) ); + FILE_LINE_READER reader( fp, fpFileName ); + PCB_PARSER parser( &reader ); std::string name = TO_UTF8( fpFileName );