diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index 6ffc29aac7..f14c933154 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2012-18 KiCad Developers, see change_log.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 @@ -26,29 +26,15 @@ #include #include #include -#include #include -#include - - // It works for table data on clipboard for an Excell spreadsheet, +// It works for table data on clipboard for an Excell spreadsheet, // why not us too for now. #define COL_SEP wxT( '\t' ) #define ROW_SEP wxT( '\n' ) -enum -{ - MYID_FIRST = -1, - MYID_CUT, - MYID_COPY, - MYID_PASTE, - MYID_SELECT, - MYID_LAST, -}; - - GRID_TRICKS::GRID_TRICKS( wxGrid* aGrid ): m_grid( aGrid ) { @@ -58,11 +44,11 @@ GRID_TRICKS::GRID_TRICKS( wxGrid* aGrid ): m_sel_col_count = 0; aGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), NULL, this ); - aGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), NULL, this ); + aGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), NULL, this ); aGrid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), NULL, this ); - aGrid->Connect( MYID_FIRST, MYID_LAST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), NULL, this ); + aGrid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), NULL, this ); + aGrid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), NULL, this ); aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), NULL, this ); - aGrid->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( GRID_TRICKS::onRightDown ), NULL, this ); } @@ -112,16 +98,23 @@ void GRID_TRICKS::onGridCellLeftClick( wxGridEvent& aEvent ) // Don't make users click twice to toggle a checkbox if( !aEvent.GetModifiers() && toggleCell( row, col ) ) - { - m_grid->ClearSelection(); - m_grid->SetGridCursor( row, col ); - - // eat event - } + /* eat event */ ; else - { aEvent.Skip(); - } +} + + +void GRID_TRICKS::onGridCellLeftDClick( wxGridEvent& aEvent ) +{ + if( !handleDoubleClick( aEvent ) ) + onGridCellLeftClick( aEvent ); +} + + +bool GRID_TRICKS::handleDoubleClick( wxGridEvent& aEvent ) +{ + // Double-click processing must be handled by specific sub-classes + return false; } @@ -133,8 +126,6 @@ void GRID_TRICKS::getSelectedArea() wxArrayInt cols = m_grid->GetSelectedCols(); wxArrayInt rows = m_grid->GetSelectedRows(); - DBG(printf("topLeft.Count():%d botRight:Count():%d\n", int( topLeft.Count() ), int( botRight.Count() ) );) - if( topLeft.Count() && botRight.Count() ) { m_sel_row_start = topLeft[0].GetRow(); @@ -159,54 +150,74 @@ void GRID_TRICKS::getSelectedArea() } else { - m_sel_row_start = -1; - m_sel_col_start = -1; - m_sel_row_count = 0; - m_sel_col_count = 0; + m_sel_row_start = m_grid->GetGridCursorRow(); + m_sel_col_start = m_grid->GetGridCursorCol(); + m_sel_row_count = m_sel_row_start >= 0 ? 1 : 0; + m_sel_col_count = m_sel_col_start >= 0 ? 1 : 0; } - - //DBG(printf("m_sel_row_start:%d m_sel_col_start:%d m_sel_row_count:%d m_sel_col_count:%d\n", m_sel_row_start, m_sel_col_start, m_sel_row_count, m_sel_col_count );) } -void GRID_TRICKS::showPopupMenu() +void GRID_TRICKS::onGridCellRightClick( wxGridEvent& ) { - wxMenu menu; + wxMenu menu; - menu.Append( MYID_CUT, _( "Cut\tCTRL+X" ), _( "Clear selected cells pasting original contents to clipboard" ) ); - menu.Append( MYID_COPY, _( "Copy\tCTRL+C" ), _( "Copy selected cells to clipboard" ) ); - menu.Append( MYID_PASTE, _( "Paste\tCTRL+V" ), _( "Paste clipboard cells to matrix at current cell" ) ); - menu.Append( MYID_SELECT, _( "Select All\tCTRL+A" ), _( "Select all cells" ) ); + showPopupMenu( menu ); +} + + +void GRID_TRICKS::onGridLabelRightClick( wxGridEvent& ) +{ + wxMenu menu; + + for( int i = 0; i < m_grid->GetNumberCols(); ++i ) + { + int id = GRIDTRICKS_FIRST_SHOWHIDE + i; + menu.AppendCheckItem( id, m_grid->GetColLabelValue( i ) ); + menu.Check( id, m_grid->IsColShown( i ) ); + } + + m_grid->PopupMenu( &menu ); +} + + +void GRID_TRICKS::showPopupMenu( wxMenu& menu ) +{ + menu.Append( GRIDTRICKS_ID_CUT, _( "Cut\tCTRL+X" ), _( "Clear selected cells placing original contents on clipboard" ) ); + menu.Append( GRIDTRICKS_ID_COPY, _( "Copy\tCTRL+C" ), _( "Copy selected cells to clipboard" ) ); + menu.Append( GRIDTRICKS_ID_PASTE, _( "Paste\tCTRL+V" ), _( "Paste clipboard cells to matrix at current cell" ) ); + menu.Append( GRIDTRICKS_ID_SELECT, _( "Select All\tCTRL+A" ), _( "Select all cells" ) ); getSelectedArea(); // if nothing is selected, disable cut and copy. if( !m_sel_row_count && !m_sel_col_count ) { - menu.Enable( MYID_CUT, false ); - menu.Enable( MYID_COPY, false ); + menu.Enable( GRIDTRICKS_ID_CUT, false ); + menu.Enable( GRIDTRICKS_ID_COPY, false ); } - bool have_cb_text = false; + menu.Enable( GRIDTRICKS_ID_PASTE, false ); + if( wxTheClipboard->Open() ) { if( wxTheClipboard->IsSupported( wxDF_TEXT ) ) - have_cb_text = true; + menu.Enable( GRIDTRICKS_ID_PASTE, true ); wxTheClipboard->Close(); } - if( !have_cb_text ) - { - // if nothing on clipboard, disable paste. - menu.Enable( MYID_PASTE, false ); - } - m_grid->PopupMenu( &menu ); } void GRID_TRICKS::onPopupSelection( wxCommandEvent& event ) +{ + doPopupSelection( event ); +} + + +void GRID_TRICKS::doPopupSelection( wxCommandEvent& event ) { int menu_id = event.GetId(); @@ -215,21 +226,29 @@ void GRID_TRICKS::onPopupSelection( wxCommandEvent& event ) switch( menu_id ) { - case MYID_CUT: - case MYID_COPY: - cutcopy( menu_id == MYID_CUT ); + case GRIDTRICKS_ID_CUT: + case GRIDTRICKS_ID_COPY: + cutcopy( menu_id == GRIDTRICKS_ID_CUT ); break; - case MYID_PASTE: + case GRIDTRICKS_ID_PASTE: paste_clipboard(); break; - case MYID_SELECT: + case GRIDTRICKS_ID_SELECT: m_grid->SelectAll(); break; default: - ; + if( menu_id >= GRIDTRICKS_FIRST_SHOWHIDE ) + { + int col = menu_id - GRIDTRICKS_FIRST_SHOWHIDE; + + if( m_grid->IsColShown( col ) ) + m_grid->HideCol( col ); + else + m_grid->ShowCol( col ); + } } } @@ -259,15 +278,24 @@ void GRID_TRICKS::onKeyDown( wxKeyEvent& ev ) cutcopy( true ); return; } - else if( ev.GetKeyCode() == ' ' ) + + // space-bar toggling of checkboxes + if( ev.GetKeyCode() == ' ' ) { - int row = getCursorRow(); - int col = getCursorCol(); + int row = m_grid->GetGridCursorRow(); + int col = m_grid->GetGridCursorCol(); if( m_grid->IsVisible( row, col ) && toggleCell( row, col ) ) return; } + // shift-return for OK + if( ev.GetKeyCode() == WXK_RETURN && ev.ShiftDown() ) + { + wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); + return; + } + ev.Skip( true ); } @@ -282,9 +310,7 @@ void GRID_TRICKS::paste_clipboard() wxTheClipboard->GetData( data ); - wxString cb_text = data.GetText(); - - paste_text( cb_text ); + paste_text( data.GetText() ); } wxTheClipboard->Close(); @@ -297,8 +323,14 @@ void GRID_TRICKS::paste_text( const wxString& cb_text ) { wxGridTableBase* tbl = m_grid->GetTable(); - const int cur_row = std::max( getCursorRow(), 0 ); // no -1 - const int cur_col = std::max( getCursorCol(), 0 ); + const int cur_row = m_grid->GetGridCursorRow(); + const int cur_col = m_grid->GetGridCursorCol(); + + if( cur_row < 0 || cur_col < 0 ) + { + wxBell(); + return; + } wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY ); @@ -322,7 +354,6 @@ void GRID_TRICKS::paste_text( const wxString& cb_text ) tbl->SetValue( row, col, cellTxt ); } } - m_grid->AutoSizeColumns( false ); } @@ -353,10 +384,72 @@ void GRID_TRICKS::cutcopy( bool doCut ) wxTheClipboard->Close(); if( doCut ) - { - m_grid->AutoSizeColumns( false ); m_grid->ForceRefresh(); - } } } + +// --------------- Static Helper Methods ---------------------------------------------- + + +void GRID_TRICKS::ShowHideGridColumns( wxGrid* aGrid, const wxString& shownColumns ) +{ + for( int i = 0; i < aGrid->GetNumberCols(); ++i ) + aGrid->HideCol( i ); + + wxStringTokenizer shownTokens( shownColumns ); + + while( shownTokens.HasMoreTokens() ) + { + long colNumber; + shownTokens.GetNextToken().ToLong( &colNumber ); + + if( colNumber >= 0 && colNumber < aGrid->GetNumberCols() ) + aGrid->ShowCol( colNumber ); + } +} + + +wxString GRID_TRICKS::GetShownColumns( wxGrid* aGrid ) +{ + wxString shownColumns; + + for( int i = 0; i < aGrid->GetNumberCols(); ++i ) + { + if( aGrid->IsColShown( i ) ) + { + if( shownColumns.Length() ) + shownColumns << wxT( " " ); + shownColumns << i; + } + } + + return shownColumns; +} + + +void GRID_TRICKS::SetGridTable( wxGrid* aGrid, wxGridTableBase* aTable ) +{ + // SetTable() messes up the column widths from wxFormBuilder so we have to save and + // restore them. + int formBuilderColWidths[ aGrid->GetNumberCols() ]; + + for( int i = 0; i < aGrid->GetNumberCols(); ++i ) + formBuilderColWidths[ i ] = aGrid->GetColSize( i ); + + aGrid->SetTable( aTable ); + + for( int i = 0; i < aGrid->GetNumberCols(); ++i ) + aGrid->SetColSize( i, formBuilderColWidths[ i ] ); +} + + +void GRID_TRICKS::DestroyGridTable( wxGrid* aGrid, wxGridTableBase* aTable ) +{ + // wxGrid's destructor will crash trying to look up the cell attr if the edit control + // is left open. Normally it's closed in Validate(), but not if the user hit Cancel. + aGrid->DisableCellEditControl(); + + aGrid->SetTable( nullptr ); + delete aTable; +} diff --git a/eeschema/dialogs/dialog_fields_editor_global.cpp b/eeschema/dialogs/dialog_fields_editor_global.cpp index 836bb7fd79..67b83848bc 100644 --- a/eeschema/dialogs/dialog_fields_editor_global.cpp +++ b/eeschema/dialogs/dialog_fields_editor_global.cpp @@ -42,6 +42,31 @@ #include "dialog_fields_editor_global.h" +class FIELDS_EDITOR_GRID_TRICKS : public GRID_TRICKS +{ +public: + FIELDS_EDITOR_GRID_TRICKS( wxGrid* aGrid, wxDataViewListCtrl* aFieldsCtrl ) : + GRID_TRICKS( aGrid ), + m_fieldsCtrl( aFieldsCtrl ) + {} + +protected: + void doPopupSelection( wxCommandEvent& event ) override + { + GRID_TRICKS::doPopupSelection( event ); + + if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE && event.GetId() < GRIDTRICKS_LAST_ID ) + { + // Refresh Show checkboxes from grid columns + for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i ) + m_fieldsCtrl->SetToggleValue( m_grid->IsColShown( i ), i, 1 ); + } + } + + wxDataViewListCtrl* m_fieldsCtrl; +}; + + enum GROUP_TYPE { GROUP_SINGLETON, @@ -590,7 +615,7 @@ DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent } // add Cut, Copy, and Paste to wxGrid - m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) ); + m_grid->PushEventHandler( new FIELDS_EDITOR_GRID_TRICKS( m_grid, m_fieldsCtrl ) ); // give a bit more room for editing m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 2 ); diff --git a/eeschema/dialogs/dialog_sym_lib_table.cpp b/eeschema/dialogs/dialog_sym_lib_table.cpp index 5c1105eb64..9e8335e22c 100644 --- a/eeschema/dialogs/dialog_sym_lib_table.cpp +++ b/eeschema/dialogs/dialog_sym_lib_table.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -114,19 +115,12 @@ protected: if( parsed ) { - const int cur_row = std::max( getCursorRow(), 0 ); - - // if clipboard rows would extend past end of current table size... - if( tmp_tbl.GetCount() > tbl->GetNumberRows() - cur_row ) - { - int newRowsNeeded = tmp_tbl.GetCount() - ( tbl->GetNumberRows() - cur_row ); - tbl->AppendRows( newRowsNeeded ); - } + // make sure the table is big enough... + if( tmp_tbl.GetCount() > tbl->GetNumberRows() ) + tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() ); for( int i = 0; i < tmp_tbl.GetCount(); ++i ) - { - tbl->rows.replace( cur_row+i, tmp_tbl.At( i ) ); - } + tbl->rows.replace( i, tmp_tbl.At( i ) ); } m_grid->AutoSizeColumns( false ); @@ -135,6 +129,8 @@ protected: { // paste spreadsheet formatted text. GRID_TRICKS::paste_text( cb_text ); + + m_grid->AutoSizeColumns( false ); } } }; @@ -156,6 +152,10 @@ DIALOG_SYMBOL_LIB_TABLE::DIALOG_SYMBOL_LIB_TABLE( wxTopLevelWindow* aParent, m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aGlobal ), true ); m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *aProject ), true ); + // Give a bit more room for combobox editors + m_global_grid->SetDefaultRowSize( m_global_grid->GetDefaultRowSize() + 4 ); + m_project_grid->SetDefaultRowSize( m_project_grid->GetDefaultRowSize() + 4 ); + // add Cut, Copy, and Paste to wxGrids m_global_grid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_global_grid ) ); m_project_grid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_project_grid ) ); @@ -205,24 +205,22 @@ DIALOG_SYMBOL_LIB_TABLE::DIALOG_SYMBOL_LIB_TABLE( wxTopLevelWindow* aParent, m_global_grid->SelectRow( 0 ); m_project_grid->SelectRow( 0 ); - // for ALT+A handling, we want the initial focus to be on the first selected grid. - if( m_pageNdx == 0 ) - { - m_global_grid->SetFocus(); - m_cur_grid = m_global_grid; - } - else - { - m_project_grid->SetFocus(); - m_cur_grid = m_project_grid; - } + // Configure button logos + m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) ); + m_delete_button->SetBitmap( KiBitmap( trash_xpm ) ); + m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) ); + m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) ); + m_browse_button->SetBitmap( KiBitmap( folder_xpm ) ); + + m_sdbSizerOK->SetDefault(); SetSizeInDU( 450, 400 ); Center(); - // On some window managers (Unity, XFCE), this dialog is - // not always raised, depending on this dialog is run. - // Force it to be raised + FinishDialogSettings(); + + // On some window managers (Unity, XFCE), this dialog is not always raised, depending on + // how this dialog is run. Raise(); } @@ -236,15 +234,25 @@ DIALOG_SYMBOL_LIB_TABLE::~DIALOG_SYMBOL_LIB_TABLE() } -int DIALOG_SYMBOL_LIB_TABLE::getCursorCol() const +bool DIALOG_SYMBOL_LIB_TABLE::Show( bool aShow ) { - return m_cur_grid->GetGridCursorCol(); -} + if( aShow ) + { + m_cur_grid = ( m_pageNdx == 0 ) ? m_global_grid : m_project_grid; + // for ALT+A handling, we want the initial focus to be on the first selected grid. + SetInitialFocus( m_cur_grid ); + } + else + { + // Save page index for next invocation + // We must do this on Show( false ) because when the first grid is hidden it + // gives focus to the next one (which is then hidden), but the result is that + // we save the wrong grid if we do it after this. + m_pageNdx = m_auinotebook->GetSelection(); + } -int DIALOG_SYMBOL_LIB_TABLE::getCursorRow() const -{ - return m_cur_grid->GetGridCursorRow(); + return DIALOG_SHIM::Show( aShow ); } @@ -271,19 +279,15 @@ bool DIALOG_SYMBOL_LIB_TABLE::verifyTables() else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_SCH ) ) ) { wxString msg = wxString::Format( - _( "Illegal character \"%c\" found in Nickname: \"%s\" in row %d" ), - illegalCh, GetChars( nick ), r + 1 ); + _( "Illegal character \"%c\" in Nickname: \"%s\"" ), + illegalCh, GetChars( nick ) ); // show the tabbed panel holding the grid we have flunked: if( &model != cur_model() ) - { m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 ); - } - // go to the problematic row - m_cur_grid->SetGridCursor( r, 0 ); - m_cur_grid->SelectBlock( r, 0, r, 0 ); m_cur_grid->MakeCellVisible( r, 0 ); + m_cur_grid->SetGridCursor( r, 1 ); wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) ); errdlg.ShowModal(); @@ -321,17 +325,15 @@ bool DIALOG_SYMBOL_LIB_TABLE::verifyTables() // show the tabbed panel holding the grid we have flunked: if( &model != cur_model() ) - { m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 ); - } // go to the lower of the two rows, it is technically the duplicate: - m_cur_grid->SetGridCursor( r2, 0 ); - m_cur_grid->SelectBlock( r2, 0, r2, 0 ); m_cur_grid->MakeCellVisible( r2, 0 ); + m_cur_grid->SetGridCursor( r2, 1 ); wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) ); errdlg.ShowModal(); + return false; } } @@ -344,8 +346,7 @@ bool DIALOG_SYMBOL_LIB_TABLE::verifyTables() void DIALOG_SYMBOL_LIB_TABLE::pageChangedHandler( wxAuiNotebookEvent& event ) { - m_pageNdx = m_auinotebook->GetSelection(); - m_cur_grid = ( m_pageNdx == 0 ) ? m_global_grid : m_project_grid; + m_cur_grid = ( m_auinotebook->GetSelection() == 0 ) ? m_global_grid : m_project_grid; } @@ -425,7 +426,10 @@ void DIALOG_SYMBOL_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) } if( !files.IsEmpty() ) - scrollToRow( m_cur_grid->GetNumberRows() - 1 ); // scroll to the new libraries + { + m_cur_grid->MakeCellVisible( m_cur_grid->GetNumberRows() - 1, 0 ); + m_cur_grid->SetGridCursor( m_cur_grid->GetNumberRows() - 1, 1 ); + } } @@ -436,14 +440,21 @@ void DIALOG_SYMBOL_LIB_TABLE::appendRowHandler( wxCommandEvent& event ) int row = m_cur_grid->GetNumberRows() - 1; // Gives a default type (currently, only one type exists): m_cur_grid->SetCellValue( row, COL_TYPE, SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) ); - scrollToRow( row ); + + // wx documentation is wrong, SetGridCursor does not make visible. + m_cur_grid->MakeCellVisible( row, 0 ); + m_cur_grid->SetGridCursor( row, 1 ); + + m_cur_grid->EnableCellEditControl( true ); + m_cur_grid->ShowCellEditControl(); } } void DIALOG_SYMBOL_LIB_TABLE::deleteRowHandler( wxCommandEvent& event ) { - int currRow = getCursorRow(); + int curRow = m_cur_grid->GetGridCursorRow(); + int curCol = m_cur_grid->GetGridCursorCol(); // In a wxGrid, collect rows that have a selected cell, or are selected // is not so easy: it depend on the way the selection was made. @@ -467,8 +478,8 @@ void DIALOG_SYMBOL_LIB_TABLE::deleteRowHandler( wxCommandEvent& event ) } // Use the row having the grid cursor only if we have no candidate: - if( selectedRows.size() == 0 && getCursorRow() >= 0 ) - selectedRows.Add( getCursorRow() ); + if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 ) + selectedRows.Add( m_cur_grid->GetGridCursorRow() ); std::sort( selectedRows.begin(), selectedRows.end() ); @@ -486,29 +497,18 @@ void DIALOG_SYMBOL_LIB_TABLE::deleteRowHandler( wxCommandEvent& event ) } } - if( currRow >= m_cur_grid->GetNumberRows() ) - m_cur_grid->SetGridCursor(m_cur_grid->GetNumberRows()-1, getCursorCol() ); - - m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() ); + m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol ); } void DIALOG_SYMBOL_LIB_TABLE::moveUpHandler( wxCommandEvent& event ) { - wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows(); - - if( rowsSelected.GetCount() == 0 ) - return; + SYMBOL_LIB_TABLE_GRID* tbl = cur_model(); + int curRow = m_cur_grid->GetGridCursorRow(); // @todo: add multiple selection moves. - int curRow = rowsSelected[0]; - if( curRow >= 1 ) { - int curCol = getCursorCol(); - - SYMBOL_LIB_TABLE_GRID* tbl = cur_model(); - boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = tbl->rows.release( tbl->rows.begin() + curRow ); @@ -517,38 +517,25 @@ void DIALOG_SYMBOL_LIB_TABLE::moveUpHandler( wxCommandEvent& event ) if( tbl->GetView() ) { - // fire a msg to cause redrawing - wxGridTableMessage msg( tbl, - wxGRIDTABLE_NOTIFY_ROWS_INSERTED, - curRow, - 0 ); - + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 ); tbl->GetView()->ProcessTableMessage( msg ); } - m_cur_grid->MakeCellVisible( curRow, curCol ); - m_cur_grid->SetGridCursor( curRow, curCol ); - m_cur_grid->SelectRow( getCursorRow() ); + m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); + m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); } } void DIALOG_SYMBOL_LIB_TABLE::moveDownHandler( wxCommandEvent& event ) { - wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows(); - - if( rowsSelected.GetCount() == 0 ) - return; - SYMBOL_LIB_TABLE_GRID* tbl = cur_model(); + int curRow = m_cur_grid->GetGridCursorRow(); // @todo: add multiple selection moves. - int curRow = rowsSelected[0]; - if( unsigned( curRow + 1 ) < tbl->rows.size() ) { - int curCol = getCursorCol(); - boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = tbl->rows.release( tbl->rows.begin() + curRow ); @@ -557,18 +544,13 @@ void DIALOG_SYMBOL_LIB_TABLE::moveDownHandler( wxCommandEvent& event ) if( tbl->GetView() ) { - // fire a msg to cause redrawing - wxGridTableMessage msg( tbl, - wxGRIDTABLE_NOTIFY_ROWS_INSERTED, - curRow - 1, - 0 ); - + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 ); tbl->GetView()->ProcessTableMessage( msg ); } - m_cur_grid->MakeCellVisible( curRow, curCol ); - m_cur_grid->SetGridCursor( curRow, curCol ); - m_cur_grid->SelectRow( getCursorRow() ); + m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); + m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); } } @@ -642,31 +624,41 @@ void DIALOG_SYMBOL_LIB_TABLE::populateEnvironReadOnlyTable() unique.insert( PROJECT_VAR_NAME ); unique.insert( SYMBOL_LIB_TABLE::GlobalPathEnvVariableName() ); - m_path_subs_grid->AppendRows( unique.size() ); - - int row = 0; - - for( auto it = unique.begin(); it != unique.end(); ++it, ++row ) + for( wxString evName : unique ) { - wxString evName = *it; - wxString evValue; + int row = m_path_subs_grid->GetNumberRows(); + m_path_subs_grid->AppendRows( 1 ); - m_path_subs_grid->SetCellValue( row, 0, evName ); + m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) ); - if( wxGetEnv( evName, &evValue ) ) - m_path_subs_grid->SetCellValue( row, 1, evValue ); + wxString evValue; + wxGetEnv( evName, &evValue ); + m_path_subs_grid->SetCellValue( row, 1, evValue ); } - m_path_subs_grid->AutoSizeColumns(); + // No combobox editors here, but it looks better if its consistent with the other + // grids in the dialog. + m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 4 ); + + adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() ); } -void DIALOG_SYMBOL_LIB_TABLE::scrollToRow( int aRowNumber ) +void DIALOG_SYMBOL_LIB_TABLE::adjustPathSubsGridColumns( int aWidth ) { - // wx documentation is wrong, SetGridCursor does not make visible. - m_cur_grid->MakeCellVisible( aRowNumber, 0 ); - m_cur_grid->SetGridCursor( aRowNumber, 0 ); - m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() ); + // Account for scroll bars + aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x ); + + m_path_subs_grid->AutoSizeColumn( 0 ); + m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) ); +} + + +void DIALOG_SYMBOL_LIB_TABLE::onSizeGrid( wxSizeEvent& event ) +{ + adjustPathSubsGridColumns( event.GetSize().GetX() ); + + event.Skip(); } @@ -688,4 +680,4 @@ SYMBOL_LIB_TABLE_GRID* DIALOG_SYMBOL_LIB_TABLE::cur_model() const } -int DIALOG_SYMBOL_LIB_TABLE::m_pageNdx = 0; +size_t DIALOG_SYMBOL_LIB_TABLE::m_pageNdx = 0; diff --git a/eeschema/dialogs/dialog_sym_lib_table.h b/eeschema/dialogs/dialog_sym_lib_table.h index 59f2a7f934..6a71332b8a 100644 --- a/eeschema/dialogs/dialog_sym_lib_table.h +++ b/eeschema/dialogs/dialog_sym_lib_table.h @@ -38,16 +38,9 @@ public: SYMBOL_LIB_TABLE* aProject ); virtual ~DIALOG_SYMBOL_LIB_TABLE(); + bool Show( bool aShow ) override; private: - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based column index. - int getCursorCol() const; - - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based row index. - int getCursorRow() const; - /** * Trim important fields, removes blank row entries, and checks for duplicates. * @@ -56,16 +49,13 @@ private: bool verifyTables(); void pageChangedHandler( wxAuiNotebookEvent& event ) override; - void browseLibrariesHandler( wxCommandEvent& event ) override; - void appendRowHandler( wxCommandEvent& event ) override; - void deleteRowHandler( wxCommandEvent& event ) override; - void moveUpHandler( wxCommandEvent& event ) override; - void moveDownHandler( wxCommandEvent& event ) override; + void onSizeGrid( wxSizeEvent& event ) override; + void adjustPathSubsGridColumns( int aWidth ); bool TransferDataFromWindow() override; @@ -73,9 +63,6 @@ private: /// by examining all the full_uri columns. void populateEnvironReadOnlyTable(); - /// Makes a specific row visible - void scrollToRow( int aRowNumber ); - // Caller's tables are modified only on OK button and successful verification. SYMBOL_LIB_TABLE* m_global; SYMBOL_LIB_TABLE* m_project; @@ -87,7 +74,7 @@ private: SYMBOL_LIB_TABLE_GRID* cur_model() const; wxGrid* m_cur_grid; ///< changed based on tab choice - static int m_pageNdx; ///< Remember the last notebook page selected during a session + static size_t m_pageNdx; ///< Remember the last notebook page selected during a session wxString m_lastBrowseDir; ///< last browsed directory }; diff --git a/eeschema/dialogs/dialog_sym_lib_table_base.cpp b/eeschema/dialogs/dialog_sym_lib_table_base.cpp index 8747e6fa94..a467a09d80 100644 --- a/eeschema/dialogs/dialog_sym_lib_table_base.cpp +++ b/eeschema/dialogs/dialog_sym_lib_table_base.cpp @@ -20,6 +20,8 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx m_top_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Libraries by Scope") ), wxVERTICAL ); m_auinotebook = new wxAuiNotebook( m_top_sizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_auinotebook->SetMinSize( wxSize( 720,460 ) ); + m_global_panel = new wxPanel( m_auinotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxBoxSizer* m_global_sizer; m_global_sizer = new wxBoxSizer( wxVERTICAL ); @@ -53,13 +55,13 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx m_global_grid->AutoSizeColumns(); m_global_grid->EnableDragColMove( false ); m_global_grid->EnableDragColSize( true ); - m_global_grid->SetColLabelSize( 30 ); + m_global_grid->SetColLabelSize( 22 ); m_global_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_global_grid->AutoSizeRows(); m_global_grid->EnableDragRowSize( false ); - m_global_grid->SetRowLabelSize( 40 ); + m_global_grid->SetRowLabelSize( 0 ); m_global_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Label Appearance @@ -106,12 +108,12 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx m_project_grid->AutoSizeColumns(); m_project_grid->EnableDragColMove( false ); m_project_grid->EnableDragColSize( true ); - m_project_grid->SetColLabelSize( 30 ); + m_project_grid->SetColLabelSize( 22 ); m_project_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_project_grid->EnableDragRowSize( false ); - m_project_grid->SetRowLabelSize( 40 ); + m_project_grid->SetRowLabelSize( 0 ); m_project_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Label Appearance @@ -131,31 +133,23 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx wxBoxSizer* bSizer51; bSizer51 = new wxBoxSizer( wxHORIZONTAL ); - m_browse_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Browse Libraries..."), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer51->Add( m_browse_button, 0, wxALL, 5 ); + m_append_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bSizer51->Add( m_append_button, 0, wxLEFT, 5 ); - m_append_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Append Library"), wxDefaultPosition, wxDefaultSize, 0 ); - m_append_button->SetToolTip( _("Add a symbol library row to this table") ); + m_browse_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bSizer51->Add( m_browse_button, 0, wxRIGHT, 5 ); - bSizer51->Add( m_append_button, 0, wxALL, 5 ); + m_delete_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bSizer51->Add( m_delete_button, 0, wxRIGHT|wxLEFT, 5 ); - m_delete_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Remove Library"), wxDefaultPosition, wxDefaultSize, 0 ); - m_delete_button->SetToolTip( _("Remove a symbol library from this library table") ); + m_move_up_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bSizer51->Add( m_move_up_button, 0, wxLEFT, 5 ); - bSizer51->Add( m_delete_button, 0, wxALL, 5 ); - - m_move_up_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Move Up"), wxDefaultPosition, wxDefaultSize, 0 ); - m_move_up_button->SetToolTip( _("Move the currently selected row up one position") ); - - bSizer51->Add( m_move_up_button, 0, wxALL, 5 ); - - m_move_down_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Move Down"), wxDefaultPosition, wxDefaultSize, 0 ); - m_move_down_button->SetToolTip( _("Move the currently selected row down one position") ); - - bSizer51->Add( m_move_down_button, 0, wxALL, 5 ); + m_move_down_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bSizer51->Add( m_move_down_button, 0, wxRIGHT, 5 ); - m_top_sizer->Add( bSizer51, 0, wxALIGN_CENTER|wxBOTTOM, 8 ); + m_top_sizer->Add( bSizer51, 0, 0, 8 ); bSizer1->Add( m_top_sizer, 1, wxALL|wxEXPAND, 5 ); @@ -178,14 +172,12 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx m_path_subs_grid->AutoSizeColumns(); m_path_subs_grid->EnableDragColMove( false ); m_path_subs_grid->EnableDragColSize( true ); - m_path_subs_grid->SetColLabelSize( 30 ); - m_path_subs_grid->SetColLabelValue( 0, _("Environment Variable") ); - m_path_subs_grid->SetColLabelValue( 1, _("Path Segment") ); + m_path_subs_grid->SetColLabelSize( 0 ); m_path_subs_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_path_subs_grid->EnableDragRowSize( true ); - m_path_subs_grid->SetRowLabelSize( 40 ); + m_path_subs_grid->SetRowLabelSize( 0 ); m_path_subs_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Label Appearance @@ -194,7 +186,7 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx m_path_subs_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); m_path_subs_grid->SetToolTip( _("This is a read-only table which shows pertinent environment variables.") ); - sbSizer1->Add( m_path_subs_grid, 1, wxALL|wxEXPAND, 5 ); + sbSizer1->Add( m_path_subs_grid, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); bSizer1->Add( sbSizer1, 0, wxALL|wxEXPAND, 5 ); @@ -209,7 +201,7 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - m_bottom_sizer->Add( m_sdbSizer, 0, wxALL|wxEXPAND, 5 ); + m_bottom_sizer->Add( m_sdbSizer, 0, wxEXPAND, 5 ); bSizer1->Add( m_bottom_sizer, 0, wxEXPAND, 5 ); @@ -217,26 +209,29 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx this->SetSizer( bSizer1 ); this->Layout(); + bSizer1->Fit( this ); this->Centre( wxBOTH ); // Connect Events m_auinotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::pageChangedHandler ), NULL, this ); - m_browse_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::appendRowHandler ), NULL, this ); + m_browse_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::deleteRowHandler ), NULL, this ); m_move_up_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::moveUpHandler ), NULL, this ); m_move_down_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::moveDownHandler ), NULL, this ); + m_path_subs_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::onSizeGrid ), NULL, this ); } DIALOG_SYMBOL_LIB_TABLE_BASE::~DIALOG_SYMBOL_LIB_TABLE_BASE() { // Disconnect Events m_auinotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::pageChangedHandler ), NULL, this ); - m_browse_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::appendRowHandler ), NULL, this ); + m_browse_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::deleteRowHandler ), NULL, this ); m_move_up_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::moveUpHandler ), NULL, this ); m_move_down_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::moveDownHandler ), NULL, this ); + m_path_subs_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::onSizeGrid ), NULL, this ); } diff --git a/eeschema/dialogs/dialog_sym_lib_table_base.fbp b/eeschema/dialogs/dialog_sym_lib_table_base.fbp index 754d42ac4c..115a37d275 100644 --- a/eeschema/dialogs/dialog_sym_lib_table_base.fbp +++ b/eeschema/dialogs/dialog_sym_lib_table_base.fbp @@ -45,7 +45,7 @@ -1,-1 DIALOG_SYMBOL_LIB_TABLE_BASE - 800,600 + -1,-1 wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU DIALOG_SHIM; dialog_shim.h Symbol Libraries @@ -144,7 +144,7 @@ 0 - + 720,460 1 m_auinotebook 1 @@ -491,7 +491,7 @@ 0 1 wxALIGN_CENTRE - 30 + 22 wxALIGN_CENTRE 5 @@ -537,7 +537,7 @@ Fixed wxALIGN_CENTRE - 40 + 0 wxALIGN_CENTRE @@ -904,7 +904,7 @@ 0 1 wxALIGN_CENTRE - 30 + 22 wxALIGN_CENTRE 5 @@ -950,7 +950,7 @@ Fixed wxALIGN_CENTRE - 40 + 0 wxALIGN_CENTRE @@ -1027,7 +1027,7 @@ 8 - wxALIGN_CENTER|wxBOTTOM + 0 @@ -1036,9 +1036,9 @@ none 5 - wxALL + wxLEFT 0 - + 1 1 1 @@ -1049,6 +1049,7 @@ + 1 0 @@ -1057,17 +1058,113 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY - Browse Libraries... + Add Library + + 0 + + + 0 + + 1 + m_append_button + 1 + + + protected + 1 + + Resizable + + 1 + 30,30 + wxBU_AUTODRAW + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + appendRowHandler + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + + wxID_ANY + Add Library 0 @@ -1083,10 +1180,11 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 @@ -1122,99 +1220,11 @@ - + 5 - wxALL + wxRIGHT|wxLEFT 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Append Library - - 0 - - - 0 - - 1 - m_append_button - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - Add a symbol library row to this table - - wxFILTER_NONE - wxDefaultValidator - - - - - appendRowHandler - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL - 0 - + 1 1 1 @@ -1225,6 +1235,7 @@ + 1 0 @@ -1233,15 +1244,18 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY Remove Library @@ -1259,12 +1273,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Remove a symbol library from this library table + wxFILTER_NONE wxDefaultValidator @@ -1298,11 +1313,11 @@ - + 5 - wxALL + wxLEFT 0 - + 1 1 1 @@ -1313,6 +1328,7 @@ + 1 0 @@ -1321,15 +1337,18 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY Move Up @@ -1347,12 +1366,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Move the currently selected row up one position + wxFILTER_NONE wxDefaultValidator @@ -1386,11 +1406,11 @@ - + 5 - wxALL + wxRIGHT 0 - + 1 1 1 @@ -1401,6 +1421,7 @@ + 1 0 @@ -1409,15 +1430,18 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY Move Down @@ -1435,12 +1459,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Move the currently selected row down one position + wxFILTER_NONE wxDefaultValidator @@ -1493,7 +1518,7 @@ 5 - wxALL|wxEXPAND + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 1 1 @@ -1518,8 +1543,8 @@ 0 1 wxALIGN_CENTRE - 30 - "Environment Variable" "Path Segment" + 0 + wxALIGN_CENTRE 2 150,500 @@ -1564,7 +1589,7 @@ Resizable wxALIGN_CENTRE - 40 + 0 wxALIGN_CENTRE @@ -1630,7 +1655,7 @@ - + onSizeGrid @@ -1647,7 +1672,7 @@ none 5 - wxALL|wxEXPAND + wxEXPAND 0 0 diff --git a/eeschema/dialogs/dialog_sym_lib_table_base.h b/eeschema/dialogs/dialog_sym_lib_table_base.h index b848909591..ed1c752072 100644 --- a/eeschema/dialogs/dialog_sym_lib_table_base.h +++ b/eeschema/dialogs/dialog_sym_lib_table_base.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -49,11 +50,11 @@ class DIALOG_SYMBOL_LIB_TABLE_BASE : public DIALOG_SHIM wxStaticText* m_staticText4; wxStaticText* m_PrjTableFilename; wxGrid* m_project_grid; - wxButton* m_browse_button; - wxButton* m_append_button; - wxButton* m_delete_button; - wxButton* m_move_up_button; - wxButton* m_move_down_button; + wxBitmapButton* m_append_button; + wxBitmapButton* m_browse_button; + wxBitmapButton* m_delete_button; + wxBitmapButton* m_move_up_button; + wxBitmapButton* m_move_down_button; wxGrid* m_path_subs_grid; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; @@ -61,16 +62,17 @@ class DIALOG_SYMBOL_LIB_TABLE_BASE : public DIALOG_SHIM // Virtual event handlers, overide them in your derived class virtual void pageChangedHandler( wxAuiNotebookEvent& event ) = 0; - virtual void browseLibrariesHandler( wxCommandEvent& event ) = 0; virtual void appendRowHandler( wxCommandEvent& event ) = 0; + virtual void browseLibrariesHandler( wxCommandEvent& event ) = 0; virtual void deleteRowHandler( wxCommandEvent& event ) = 0; virtual void moveUpHandler( wxCommandEvent& event ) = 0; virtual void moveDownHandler( wxCommandEvent& event ) = 0; + virtual void onSizeGrid( wxSizeEvent& event ) = 0; public: - DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Symbol Libraries"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 800,600 ), long style = wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU ); + DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Symbol Libraries"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU ); ~DIALOG_SYMBOL_LIB_TABLE_BASE(); }; diff --git a/include/bitmaps.h b/include/bitmaps.h index 42b7858fa1..a875e83771 100644 --- a/include/bitmaps.h +++ b/include/bitmaps.h @@ -499,7 +499,9 @@ EXTERN_BITMAP( showtrack_xpm ) EXTERN_BITMAP( show_zone_xpm ) EXTERN_BITMAP( show_zone_disable_xpm ) EXTERN_BITMAP( show_zone_outline_only_xpm ) +EXTERN_BITMAP( small_down_xpm ) EXTERN_BITMAP( small_plus_xpm ) +EXTERN_BITMAP( small_up_xpm ) EXTERN_BITMAP( spreadsheet_xpm ) EXTERN_BITMAP( svg_file_xpm ) EXTERN_BITMAP( swap_layer_xpm ) diff --git a/include/grid_tricks.h b/include/grid_tricks.h index 4a2b1855a1..120595f1be 100644 --- a/include/grid_tricks.h +++ b/include/grid_tricks.h @@ -22,11 +22,28 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#ifndef _GRID_TRICKS_H_ +#define _GRID_TRICKS_H_ + #include #include +enum +{ + GRIDTRICKS_FIRST_ID = 901, + GRIDTRICKS_ID_CUT, + GRIDTRICKS_ID_COPY, + GRIDTRICKS_ID_PASTE, + GRIDTRICKS_ID_SELECT, + + GRIDTRICKS_FIRST_SHOWHIDE = 979, // reserve 20 IDs for show/hide-column-n + + GRIDTRICKS_LAST_ID = 999 +}; + + /** * Class GRID_TRICKS * is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance. @@ -35,8 +52,19 @@ class GRID_TRICKS : public wxEvtHandler { public: - GRID_TRICKS( wxGrid* aGrid ); + explicit GRID_TRICKS( wxGrid* aGrid ); + /// Helper routines for column visibility preferences + static void ShowHideGridColumns( wxGrid* aGrid, const wxString& shownColumns ); + static wxString GetShownColumns( wxGrid* aGrid ); + + /// Workaround for wxGrid::SetTable(), which messes up the column widths that were set + /// in wxFormBuilder.) + static void SetGridTable( wxGrid* aGrid, wxGridTableBase* aTable ); + + /// Workaround for crash bug in wxGrid where it tries to call the table in the d'tor + /// in order to hide the cell editor + static void DestroyGridTable( wxGrid* aGrid, wxGridTableBase* aTable ); protected: wxGrid* m_grid; ///< I don't own the grid, but he owns me @@ -48,20 +76,6 @@ protected: int m_sel_row_count; int m_sel_col_count; - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based column index. - int getCursorCol() const - { - return m_grid->GetGridCursorCol(); - } - - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based row index. - int getCursorRow() const - { - return m_grid->GetGridCursorRow(); - } - /// Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above. void getSelectedArea(); @@ -71,30 +85,21 @@ protected: } void onGridCellLeftClick( wxGridEvent& event ); - - void onGridCellRightClick( wxGridEvent& event ) - { - showPopupMenu(); - } - - void onRightDown( wxMouseEvent& event ) - { - showPopupMenu(); - } - - virtual void showPopupMenu(); - - // the user clicked on a popup menu choice: + void onGridCellLeftDClick( wxGridEvent& event ); + void onGridCellRightClick( wxGridEvent& event ); + void onGridLabelRightClick( wxGridEvent& event ); void onPopupSelection( wxCommandEvent& event ); - void onKeyDown( wxKeyEvent& ev ); + virtual bool handleDoubleClick( wxGridEvent& aEvent ); + virtual void showPopupMenu( wxMenu& menu ); + virtual void doPopupSelection( wxCommandEvent& event ); + bool toggleCell( int aRow, int aCol ); virtual void paste_clipboard(); - virtual void paste_text( const wxString& cb_text ); - virtual void cutcopy( bool doCut ); }; +#endif // _GRID_TRICKS_H_ diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index 11909fe617..206bcd9709 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -33,15 +33,17 @@ #include #include +#include #include #include #include <3d_viewer.h> // for KISYS3DMOD -#include +#include #include #include #include #include +#include #include #include #include @@ -139,23 +141,73 @@ public: }; +#define MYID_OPTIONS_EDITOR 15151 + + class FP_GRID_TRICKS : public GRID_TRICKS { public: - FP_GRID_TRICKS( wxGrid* aGrid ) : - GRID_TRICKS( aGrid ) + FP_GRID_TRICKS( wxGrid* aGrid ) : GRID_TRICKS( aGrid ) { } protected: + void optionsEditor( int aRow ) + { + FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable(); + if( tbl->GetNumberRows() > aRow ) + { + LIB_TABLE_ROW* row = tbl->at( (size_t) aRow ); + const wxString& options = row->GetOptions(); + wxString result = options; + + InvokePluginOptionsEditor( wxGetTopLevelParent( m_grid ), row->GetNickName(), + row->GetType(), options, &result ); + + if( options != result ) + { + row->SetOptions( result ); + m_grid->Refresh(); + } + } + } + + bool handleDoubleClick( wxGridEvent& aEvent ) override + { + if( aEvent.GetCol() == COL_OPTIONS ) + { + optionsEditor( aEvent.GetRow() ); + return true; + } + + return false; + } + + void showPopupMenu( wxMenu& menu ) override + { + if( m_grid->GetGridCursorCol() == COL_OPTIONS ) + { + menu.Append( MYID_OPTIONS_EDITOR, _( "Options Editor..." ), _( "Edit options" ) ); + menu.AppendSeparator(); + } + + GRID_TRICKS::showPopupMenu( menu ); + } + + void doPopupSelection( wxCommandEvent& event ) override + { + if( event.GetId() == MYID_OPTIONS_EDITOR ) + optionsEditor( m_grid->GetGridCursorRow() ); + else + GRID_TRICKS::doPopupSelection( event ); + } /// handle specialized clipboard text, with leading "(fp_lib_table", OR /// spreadsheet formatted text. - virtual void paste_text( const wxString& cb_text ) override + void paste_text( const wxString& cb_text ) override { - FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable(); - - size_t ndx = cb_text.find( "(fp_lib_table" ); + FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable(); + size_t ndx = cb_text.find( "(fp_lib_table" ); if( ndx != std::string::npos ) { @@ -179,19 +231,12 @@ protected: if( parsed ) { - const int cur_row = std::max( getCursorRow(), 0 ); - - // if clipboard rows would extend past end of current table size... - if( tmp_tbl.GetCount() > tbl->GetNumberRows() - cur_row ) - { - int newRowsNeeded = tmp_tbl.GetCount() - ( tbl->GetNumberRows() - cur_row ); - tbl->AppendRows( newRowsNeeded ); - } + // make sure the table is big enough... + if( tmp_tbl.GetCount() > tbl->GetNumberRows() ) + tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() ); for( int i = 0; i < tmp_tbl.GetCount(); ++i ) - { - tbl->rows.replace( cur_row+i, tmp_tbl.At( i ) ); - } + tbl->rows.replace( i, tmp_tbl.At( i ) ); } m_grid->AutoSizeColumns( false ); @@ -200,638 +245,546 @@ protected: { // paste spreadsheet formatted text. GRID_TRICKS::paste_text( cb_text ); + + m_grid->AutoSizeColumns( false ); } } }; -/** - * Class DIALOG_FP_LIB_TABLE - * shows and edits the PCB library tables. Two tables are expected, one global - * and one project specific. - */ -class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE +DIALOG_FP_LIB_TABLE::DIALOG_FP_LIB_TABLE( wxWindow* aParent, FP_LIB_TABLE* aGlobal, + FP_LIB_TABLE* aProject ) : + DIALOG_FP_LIB_TABLE_BASE( aParent ), + m_global( aGlobal ), + m_project( aProject ) { + // For user info, shows the table filenames: + m_PrjTableFilename->SetLabel( Prj().FootprintLibTblName() ); + m_GblTableFilename->SetLabel( FP_LIB_TABLE::GetGlobalTableFileName() ); -public: - DIALOG_FP_LIB_TABLE( wxTopLevelWindow* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject ) : - DIALOG_FP_LIB_TABLE_BASE( aParent ), - m_global( aGlobal ), - m_project( aProject ) + // wxGrid only supports user owned tables if they exist past end of ~wxGrid(), + // so make it a grid owned table. + m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobal ), true ); + m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProject ), true ); + + // Give a bit more room for combobox editors + m_global_grid->SetDefaultRowSize( m_global_grid->GetDefaultRowSize() + 4 ); + m_project_grid->SetDefaultRowSize( m_project_grid->GetDefaultRowSize() + 4 ); + + // add Cut, Copy, and Paste to wxGrids + m_global_grid->PushEventHandler( new FP_GRID_TRICKS( m_global_grid ) ); + m_project_grid->PushEventHandler( new FP_GRID_TRICKS( m_project_grid ) ); + + m_global_grid->AutoSizeColumns( false ); + m_project_grid->AutoSizeColumns( false ); + + wxArrayString choices; + + choices.Add( IO_MGR::ShowType( IO_MGR::KICAD_SEXP ) ); + choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) ); + choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) ); + choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) ); + choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) ); + + /* PCAD_PLUGIN does not support Footprint*() functions + choices.Add( IO_MGR::ShowType( IO_MGR::PCAD ) ); + */ + + populateEnvironReadOnlyTable(); + + for( int i=0; i<2; ++i ) { - // For user info, shows the table filenames: - m_PrjTableFilename->SetLabel( Prj().FootprintLibTblName() ); - m_GblTableFilename->SetLabel( FP_LIB_TABLE::GetGlobalTableFileName() ); + wxGrid* g = i==0 ? m_global_grid : m_project_grid; - // wxGrid only supports user owned tables if they exist past end of ~wxGrid(), - // so make it a grid owned table. - m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobal ), true ); - m_project_grid->SetTable( new FP_LIB_TABLE_GRID( *aProject ), true ); + wxGridCellAttr* attr; - // add Cut, Copy, and Paste to wxGrids - m_global_grid->PushEventHandler( new FP_GRID_TRICKS( m_global_grid ) ); - m_project_grid->PushEventHandler( new FP_GRID_TRICKS( m_project_grid ) ); + attr = new wxGridCellAttr; + attr->SetEditor( new wxGridCellChoiceEditor( choices ) ); + g->SetColAttr( COL_TYPE, attr ); - m_global_grid->AutoSizeColumns( false ); - m_project_grid->AutoSizeColumns( false ); + attr = new wxGridCellAttr; + attr->SetRenderer( new wxGridCellBoolRenderer() ); + attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS + g->SetColAttr( COL_ENABLED, attr ); - wxArrayString choices; + // all but COL_OPTIONS, which is edited with Option Editor anyways. + g->AutoSizeColumn( COL_NICKNAME, false ); + g->AutoSizeColumn( COL_TYPE, false ); + g->AutoSizeColumn( COL_URI, false ); + g->AutoSizeColumn( COL_DESCR, false ); - choices.Add( IO_MGR::ShowType( IO_MGR::KICAD_SEXP ) ); - choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) ); - choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) ); - choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) ); - choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) ); + // would set this to width of title, if it was easily known. + g->SetColSize( COL_OPTIONS, 80 ); + } - /* PCAD_PLUGIN does not support Footprint*() functions - choices.Add( IO_MGR::ShowType( IO_MGR::GITHUB ) ); - */ + // select the last selected page + m_auinotebook->SetSelection( m_pageNdx ); - populateEnvironReadOnlyTable(); + // Configure button logos + m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) ); + m_browse_button->SetBitmap( KiBitmap( folder_xpm ) ); + m_delete_button->SetBitmap( KiBitmap( trash_xpm ) ); + m_move_up_button->SetBitmap( KiBitmap( small_up_xpm ) ); + m_move_down_button->SetBitmap( KiBitmap( small_down_xpm ) ); - for( int i=0; i<2; ++i ) - { - wxGrid* g = i==0 ? m_global_grid : m_project_grid; + // Gives a selection for each grid, mainly for delete lib button. + // Without that, we do not see what lib will be deleted + m_global_grid->SetGridCursor( 0, 1 ); + m_project_grid->SetGridCursor( 0, 1 ); - wxGridCellAttr* attr; - - attr = new wxGridCellAttr; - attr->SetEditor( new wxGridCellChoiceEditor( choices ) ); - g->SetColAttr( COL_TYPE, attr ); - - attr = new wxGridCellAttr; - attr->SetRenderer( new wxGridCellBoolRenderer() ); - attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS - g->SetColAttr( COL_ENABLED, attr ); - - // all but COL_OPTIONS, which is edited with Option Editor anyways. - g->AutoSizeColumn( COL_NICKNAME, false ); - g->AutoSizeColumn( COL_TYPE, false ); - g->AutoSizeColumn( COL_URI, false ); - g->AutoSizeColumn( COL_DESCR, false ); - - // would set this to width of title, if it was easily known. - g->SetColSize( COL_OPTIONS, 80 ); - } - - // This scrunches the dialog hideously, probably due to wxAUI container. - // Fit(); - // We derive from DIALOG_SHIM so prior size will be used anyways. - - // select the last selected page - m_auinotebook->SetSelection( m_pageNdx ); - - // fire pageChangedHandler() so m_cur_grid gets set - // m_auinotebook->SetSelection will generate a pageChangedHandler() - // event call later, but too late. - wxAuiNotebookEvent uneventful; - pageChangedHandler( uneventful ); - - // Gives a selection for each grid, mainly for delete lib button. - // Without that, we do not see what lib will be deleted - m_global_grid->SelectRow( 0 ); - m_project_grid->SelectRow( 0 ); - - // for ALT+A handling, we want the initial focus to be on the first selected grid. - m_cur_grid->SetFocus(); + m_sdbSizerOK->SetDefault(); SetSizeInDU( 450, 380 ); Center(); - // On some windows manager (Unity, XFCE), this dialog is - // not always raised, depending on this dialog is run. - // Force it to be raised - Raise(); + FinishDialogSettings(); + + // On some windows manager (Unity, XFCE), this dialog is not always raised, depending + // on how the dialog is run. + Raise(); +} + + +DIALOG_FP_LIB_TABLE::~DIALOG_FP_LIB_TABLE() +{ + // Delete the GRID_TRICKS. + // Any additional event handlers should be popped before the window is deleted. + m_global_grid->PopEventHandler( true ); + m_project_grid->PopEventHandler( true ); +} + + +bool DIALOG_FP_LIB_TABLE::Show( bool aShow ) +{ + if( aShow ) + { + m_cur_grid = ( m_pageNdx == 0 ) ? m_global_grid : m_project_grid; + + // for ALT+A handling, we want the initial focus to be on the first selected grid. + SetInitialFocus( m_cur_grid ); + } + else + { + // Save page index for next invocation + // We must do this on Show( false ) because when the first grid is hidden it + // gives focus to the next one (which is then hidden), but the result is that + // we save the wrong grid if we do it after this. + m_pageNdx = m_auinotebook->GetSelection(); } - ~DIALOG_FP_LIB_TABLE() - { - // Delete the GRID_TRICKS. - // Any additional event handlers should be popped before the window is deleted. - m_global_grid->PopEventHandler( true ); - m_project_grid->PopEventHandler( true ); - } + return DIALOG_SHIM::Show( aShow ); +} -private: - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based column index. - int getCursorCol() const +bool DIALOG_FP_LIB_TABLE::verifyTables() +{ + for( int t=0; t<2; ++t ) { - return m_cur_grid->GetGridCursorCol(); - } + FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model(); - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based row index. - int getCursorRow() const - { - return m_cur_grid->GetGridCursorRow(); - } - - /** - * Function verifyTables - * trims important fields, removes blank row entries, and checks for duplicates. - * @return bool - true if tables are OK, else false. - */ - bool verifyTables() - { - for( int t=0; t<2; ++t ) + for( int r = 0; r < model.GetNumberRows(); ) { - FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model(); + wxString nick = model.GetValue( r, COL_NICKNAME ).Trim( false ).Trim(); + wxString uri = model.GetValue( r, COL_URI ).Trim( false ).Trim(); + unsigned illegalCh = 0; - for( int r = 0; r < model.GetNumberRows(); ) + if( !nick || !uri ) { - wxString nick = model.GetValue( r, COL_NICKNAME ).Trim( false ).Trim(); - wxString uri = model.GetValue( r, COL_URI ).Trim( false ).Trim(); - unsigned illegalCh = 0; + // Delete the "empty" row, where empty means missing nick or uri. + // This also updates the UI which could be slow, but there should only be a few + // rows to delete, unless the user fell asleep on the Add Row + // button. + model.DeleteRows( r, 1 ); + } + else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) ) + { + wxString msg = wxString::Format( + _( "Illegal character \"%c\" in Nickname: \"%s\"" ), + illegalCh, GetChars( nick ) ); - if( !nick || !uri ) - { - // Delete the "empty" row, where empty means missing nick or uri. - // This also updates the UI which could be slow, but there should only be a few - // rows to delete, unless the user fell asleep on the Add Row - // button. - model.DeleteRows( r, 1 ); - } - else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) ) + // show the tabbed panel holding the grid we have flunked: + if( &model != cur_model() ) + m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 ); + + m_cur_grid->MakeCellVisible( r, 0 ); + m_cur_grid->SetGridCursor( r, 1 ); + + wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) ); + errdlg.ShowModal(); + return false; + } + else + { + // set the trimmed values back into the table so they get saved to disk. + model.SetValue( r, COL_NICKNAME, nick ); + model.SetValue( r, COL_URI, uri ); + ++r; // this row was OK. + } + } + } + + // check for duplicate nickNames, separately in each table. + for( int t=0; t<2; ++t ) + { + FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model(); + + for( int r1 = 0; r1 < model.GetNumberRows() - 1; ++r1 ) + { + wxString nick1 = model.GetValue( r1, COL_NICKNAME ); + + for( int r2=r1+1; r2 < model.GetNumberRows(); ++r2 ) + { + wxString nick2 = model.GetValue( r2, COL_NICKNAME ); + + if( nick1 == nick2 ) { wxString msg = wxString::Format( - _( "Illegal character \"%c\" found in Nickname: \"%s\" in row %d" ), - illegalCh, GetChars( nick ), r ); + _( "Duplicate Nickname: \"%s\" in rows %d and %d" ), + GetChars( nick1 ), r1+1, r2+1 + ); // show the tabbed panel holding the grid we have flunked: if( &model != cur_model() ) - { m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 ); - } - // go to the problematic row - m_cur_grid->SetGridCursor( r, 0 ); - m_cur_grid->SelectBlock( r, 0, r, 0 ); - m_cur_grid->MakeCellVisible( r, 0 ); + // go to the lower of the two rows, it is technically the duplicate: + m_cur_grid->MakeCellVisible( r2, 0 ); + m_cur_grid->SetGridCursor( r2, 1 ); - wxMessageDialog errdlg( this, msg, _( "No Colon in Nicknames" ) ); + wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) ); errdlg.ShowModal(); return false; } - else - { - // set the trimmed values back into the table so they get saved to disk. - model.SetValue( r, COL_NICKNAME, nick ); - model.SetValue( r, COL_URI, uri ); - ++r; // this row was OK. - } } } + } - // check for duplicate nickNames, separately in each table. - for( int t=0; t<2; ++t ) + return true; +} + + +//--------------------------------------- + +void DIALOG_FP_LIB_TABLE::pageChangedHandler( wxAuiNotebookEvent& event ) +{ + m_cur_grid = ( m_auinotebook->GetSelection() == 0 ) ? m_global_grid : m_project_grid; +} + + +void DIALOG_FP_LIB_TABLE::appendRowHandler( wxCommandEvent& event ) +{ + if( m_cur_grid->AppendRows( 1 ) ) + { + int last_row = m_cur_grid->GetNumberRows() - 1; + + // wx documentation is wrong, SetGridCursor does not make visible. + m_cur_grid->MakeCellVisible( last_row, 0 ); + m_cur_grid->SetGridCursor( last_row, 1 ); + m_cur_grid->EnableCellEditControl( true ); + m_cur_grid->ShowCellEditControl(); + } +} + + +void DIALOG_FP_LIB_TABLE::deleteRowHandler( wxCommandEvent& event ) +{ + int curRow = m_cur_grid->GetGridCursorRow(); + int curCol = m_cur_grid->GetGridCursorCol(); + + // In a wxGrid, collect rows that have a selected cell, or are selected + // is not so easy: it depend on the way the selection was made. + // Here, we collect row selected by clicking on a row label, and + // row that contain a cell previously selected. + // If no candidate, just delete the row with the grid cursor. + wxArrayInt selectedRows = m_cur_grid->GetSelectedRows(); + wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells(); + wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft(); + wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight(); + + // Add all row having cell selected to list: + for( unsigned ii = 0; ii < cells.GetCount(); ii++ ) + selectedRows.Add( cells[ii].GetRow() ); + + // Handle block selection + if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() ) + { + for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i ) + selectedRows.Add( i ); + } + + // Use the row having the grid cursor only if we have no candidate: + if( selectedRows.size() == 0 && m_cur_grid->GetGridCursorRow() >= 0 ) + selectedRows.Add( m_cur_grid->GetGridCursorRow() ); + + std::sort( selectedRows.begin(), selectedRows.end() ); + + // Remove selected rows (note: a row can be stored more than once in list) + int last_row = -1; + for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- ) + { + int row = selectedRows[ii]; + + if( row != last_row ) { - FP_LIB_TABLE_GRID& model = t==0 ? *global_model() : *project_model(); + last_row = row; + m_cur_grid->DeleteRows( row, 1 ); + } + } - for( int r1 = 0; r1 < model.GetNumberRows() - 1; ++r1 ) + m_cur_grid->SetGridCursor( std::min( curRow, m_cur_grid->GetNumberRows() - 1 ), curCol ); +} + + +void DIALOG_FP_LIB_TABLE::moveUpHandler( wxCommandEvent& event ) +{ + FP_LIB_TABLE_GRID* tbl = cur_model(); + int curRow = m_cur_grid->GetGridCursorRow(); + + // @todo: add multiple selection moves. + if( curRow >= 1 ) + { + boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = + tbl->rows.release( tbl->rows.begin() + curRow ); + + --curRow; + tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() ); + + if( tbl->GetView() ) + { + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 ); + tbl->GetView()->ProcessTableMessage( msg ); + } + + m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); + m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); + } +} + + +void DIALOG_FP_LIB_TABLE::moveDownHandler( wxCommandEvent& event ) +{ + FP_LIB_TABLE_GRID* tbl = cur_model(); + int curRow = m_cur_grid->GetGridCursorRow(); + + // @todo: add multiple selection moves. + if( unsigned( curRow + 1 ) < tbl->rows.size() ) + { + boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = + tbl->rows.release( tbl->rows.begin() + curRow ); + + ++curRow; + tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() ); + + if( tbl->GetView() ) + { + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 ); + tbl->GetView()->ProcessTableMessage( msg ); + } + + m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); + m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); + } +} + + +void DIALOG_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) +{ + if( m_lastBrowseDir.IsEmpty() ) + m_lastBrowseDir = Prj().GetProjectPath(); + + DIALOG_FILE_DIR_PICKER dlg( this, _( "Select Library" ), m_lastBrowseDir, + getFilterString(), FD_MULTIPLE ); + + auto result = dlg.ShowModal(); + + if( result == wxID_CANCEL ) + return; + + m_lastBrowseDir = dlg.GetDirectory(); + + // Drop the last directory if the path is a .pretty folder + if( m_lastBrowseDir.EndsWith( KiCadFootprintLibPathExtension ) ) + m_lastBrowseDir = m_lastBrowseDir.BeforeLast( wxFileName::GetPathSeparator() ); + + bool skipRemainingDuplicates = false; + wxArrayString files; + dlg.GetFilenames( files ); + + for( const auto& filePath : files ) + { + wxFileName fn( filePath ); + wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB ); + + if( cur_model()->ContainsNickname( nickname ) ) + { + if( skipRemainingDuplicates ) + continue; + + int ret = YesNoCancelDialog( this, + _( "Warning: Duplicate Nickname" ), + wxString::Format( _( "A library nicknamed \"%s\" already exists." ), nickname ), + _( "Skip" ), + _( "Skip All Remaining Duplicates" ), + _( "Add Anyway" ) ); + + if( ret == wxID_YES ) + continue; + else if ( ret == wxID_NO ) { - wxString nick1 = model.GetValue( r1, COL_NICKNAME ); - - for( int r2=r1+1; r2 < model.GetNumberRows(); ++r2 ) - { - wxString nick2 = model.GetValue( r2, COL_NICKNAME ); - - if( nick1 == nick2 ) - { - wxString msg = wxString::Format( - _( "Duplicate Nickname: \"%s\" in rows %d and %d" ), - GetChars( nick1 ), r1+1, r2+1 - ); - - // show the tabbed panel holding the grid we have flunked: - if( &model != cur_model() ) - { - m_auinotebook->SetSelection( &model == global_model() ? 0 : 1 ); - } - - // go to the lower of the two rows, it is technically the duplicate: - m_cur_grid->SetGridCursor( r2, 0 ); - m_cur_grid->SelectBlock( r2, 0, r2, 0 ); - m_cur_grid->MakeCellVisible( r2, 0 ); - - wxMessageDialog errdlg( this, msg, _( "Please Delete or Modify One" ) ); - errdlg.ShowModal(); - return false; - } - } + skipRemainingDuplicates = true; + continue; } } - return true; - } - - //--------------------------------------- - - void onKeyDown( wxKeyEvent& ev ) override - { -#if 0 - // send the key to the current grid - ((wxEvtHandler*)m_cur_grid)->ProcessEvent( ev ); -#else - // or no: - // m_cur_grid has the focus most of the time anyways, so above not needed. - ev.Skip(); -#endif - } - - void pageChangedHandler( wxAuiNotebookEvent& event ) override - { - m_pageNdx = m_auinotebook->GetSelection(); - m_cur_grid = ( m_pageNdx == 0 ) ? m_global_grid : m_project_grid; - } - - void appendRowHandler( wxCommandEvent& event ) override - { if( m_cur_grid->AppendRows( 1 ) ) { int last_row = m_cur_grid->GetNumberRows() - 1; - // wx documentation is wrong, SetGridCursor does not make visible. - m_cur_grid->MakeCellVisible( last_row, 0 ); - m_cur_grid->SetGridCursor( last_row, 0 ); - m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() ); + m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname ); + + auto type = IO_MGR::GuessPluginTypeFromLibPath( filePath ); + m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( type ) ); + + // try to use path normalized to an environmental variable or project path + wxString normalizedPath = NormalizePath( filePath, &Pgm().GetLocalEnvVariables(), &Prj() ); + m_cur_grid->SetCellValue( last_row, COL_URI, + normalizedPath.IsEmpty() ? fn.GetFullPath() : normalizedPath ); } } - void deleteRowHandler( wxCommandEvent& event ) override + if( !files.IsEmpty() ) { - int currRow = getCursorRow(); - - // In a wxGrid, collect rows that have a selected cell, or are selected - // is not so easy: it depend on the way the selection was made. - // Here, we collect row selected by clicking on a row label, and - // row that contain a cell previously selected. - // If no candidate, just delete the row with the grid cursor. - wxArrayInt selectedRows = m_cur_grid->GetSelectedRows(); - wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells(); - wxGridCellCoordsArray blockTopLeft = m_cur_grid->GetSelectionBlockTopLeft(); - wxGridCellCoordsArray blockBotRight = m_cur_grid->GetSelectionBlockBottomRight(); - - // Add all row having cell selected to list: - for( unsigned ii = 0; ii < cells.GetCount(); ii++ ) - selectedRows.Add( cells[ii].GetRow() ); - - // Handle block selection - if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() ) - { - for( int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i ) - selectedRows.Add( i ); - } - - // Use the row having the grid cursor only if we have no candidate: - if( selectedRows.size() == 0 && getCursorRow() >= 0 ) - selectedRows.Add( getCursorRow() ); - - std::sort( selectedRows.begin(), selectedRows.end() ); - - // Remove selected rows (note: a row can be stored more than once in list) - int last_row = -1; - for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- ) - { - int row = selectedRows[ii]; - - if( row != last_row ) - { - last_row = row; - m_cur_grid->DeleteRows( row, 1 ); - } - } - - if( currRow >= m_cur_grid->GetNumberRows() ) - m_cur_grid->SetGridCursor(m_cur_grid->GetNumberRows()-1, getCursorCol() ); - - m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() ); + int new_row = m_cur_grid->GetNumberRows() - 1; + m_cur_grid->MakeCellVisible( new_row, m_cur_grid->GetGridCursorCol() ); + m_cur_grid->SetGridCursor( new_row, m_cur_grid->GetGridCursorCol() ); } +} - void moveUpHandler( wxCommandEvent& event ) override +void DIALOG_FP_LIB_TABLE::adjustPathSubsGridColumns( int aWidth ) +{ + // Account for scroll bars + aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x ); + + m_path_subs_grid->AutoSizeColumn( 0 ); + m_path_subs_grid->SetColSize( 1, aWidth - m_path_subs_grid->GetColSize( 0 ) ); +} + + +void DIALOG_FP_LIB_TABLE::onSizeGrid( wxSizeEvent& event ) +{ + adjustPathSubsGridColumns( event.GetSize().GetX() ); + + event.Skip(); +} + + +void DIALOG_FP_LIB_TABLE::onOKButtonClick( wxCommandEvent& event ) +{ + int dialogRet = 0; + + // stuff any pending cell editor text into the table. + m_cur_grid->DisableCellEditControl(); + + if( verifyTables() ) { - wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows(); - - if( rowsSelected.GetCount() == 0 ) - return; - - // @todo: add multiple selection moves. - int curRow = rowsSelected[0]; - - if( curRow >= 1 ) + if( *global_model() != *m_global ) { - int curCol = getCursorCol(); + dialogRet |= 1; - FP_LIB_TABLE_GRID* tbl = cur_model(); - - boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = - tbl->rows.release( tbl->rows.begin() + curRow ); - - --curRow; - tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() ); - - if( tbl->GetView() ) - { - // fire a msg to cause redrawing - wxGridTableMessage msg( tbl, - wxGRIDTABLE_NOTIFY_ROWS_INSERTED, - curRow, - 0 ); - - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_cur_grid->MakeCellVisible( curRow, curCol ); - m_cur_grid->SetGridCursor( curRow, curCol ); - m_cur_grid->SelectRow( getCursorRow() ); + m_global->Clear(); + m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(), + global_model()->rows.end(), global_model()->rows ); + m_global->reindex(); } - } - void moveDownHandler( wxCommandEvent& event ) override - { - wxArrayInt rowsSelected = m_cur_grid->GetSelectedRows(); - - if( rowsSelected.GetCount() == 0 ) - return; - - FP_LIB_TABLE_GRID* tbl = cur_model(); - - // @todo: add multiple selection moves. - int curRow = rowsSelected[0]; - - if( unsigned( curRow + 1 ) < tbl->rows.size() ) + if( *project_model() != *m_project ) { - int curCol = getCursorCol(); + dialogRet |= 2; - boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = - tbl->rows.release( tbl->rows.begin() + curRow ); - - ++curRow; - tbl->rows.insert( tbl->rows.begin() + curRow, move_me.release() ); - - 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->MakeCellVisible( curRow, curCol ); - m_cur_grid->SetGridCursor( curRow, curCol ); - m_cur_grid->SelectRow( getCursorRow() ); + m_project->Clear(); + m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(), + project_model()->rows.end(), project_model()->rows ); + m_project->reindex(); } + + EndModal( dialogRet ); } +} - void optionsEditor( wxCommandEvent& event ) override + +/// Populate the readonly environment variable table with names and values +/// by examining all the full_uri columns. +void DIALOG_FP_LIB_TABLE::populateEnvironReadOnlyTable() +{ + wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED ); + wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required. + + std::set< wxString > unique; + + // clear the table + m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() ); + + for( int i = 0; i < 2; ++i ) { - FP_LIB_TABLE_GRID* tbl = cur_model(); + FP_LIB_TABLE_GRID* tbl = i == 0 ? global_model() : project_model(); - if( tbl->GetNumberRows() ) + for( int row = 0; row < tbl->GetNumberRows(); ++row ) { - int curRow = getCursorRow(); - LIB_TABLE_ROW* row = &tbl->rows[curRow]; + wxString uri = tbl->GetValue( row, COL_URI ); - wxString result; - const wxString& options = row->GetOptions(); - - InvokePluginOptionsEditor( this, row->GetNickName(), row->GetType(), options, &result ); - - if( options != result ) + while( re.Matches( uri ) ) { - row->SetOptions( result ); + wxString envvar = re.GetMatch( uri, 2 ); - // all but options: - m_cur_grid->AutoSizeColumn( COL_NICKNAME, false ); - m_cur_grid->AutoSizeColumn( COL_URI, false ); - m_cur_grid->AutoSizeColumn( COL_TYPE, false ); + // if not ${...} form then must be $(...) + if( envvar.IsEmpty() ) + envvar = re.GetMatch( uri, 4 ); - // On Windows, the grid is not refresh, - // so force resfresh after a change -#ifdef __WINDOWS__ - Refresh(); -#endif + // ignore duplicates + unique.insert( envvar ); + + // delete the last match and search again + uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); } } } - void browseLibrariesHandler( wxCommandEvent& event ) override + // Make sure this special environment variable shows up even if it was + // not used yet. It is automatically set by KiCad to the directory holding + // the current project. + unique.insert( PROJECT_VAR_NAME ); + unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() ); + // This special environment variable is used to locate 3d shapes + unique.insert( KISYS3DMOD ); + + for( wxString evName : unique ) { - if( m_lastBrowseDir.IsEmpty() ) - m_lastBrowseDir = Prj().GetProjectPath(); + int row = m_path_subs_grid->GetNumberRows(); + m_path_subs_grid->AppendRows( 1 ); - DIALOG_FILE_DIR_PICKER dlg( this, _( "Select Library" ), m_lastBrowseDir, - getFilterString(), FD_MULTIPLE ); + m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) ); - auto result = dlg.ShowModal(); - - if( result == wxID_CANCEL ) - return; - - m_lastBrowseDir = dlg.GetDirectory(); - - // Drop the last directory if the path is a .pretty folder - if( m_lastBrowseDir.EndsWith( KiCadFootprintLibPathExtension ) ) - m_lastBrowseDir = m_lastBrowseDir.BeforeLast( wxFileName::GetPathSeparator() ); - - bool skipRemainingDuplicates = false; - wxArrayString files; - dlg.GetFilenames( files ); - - for( const auto& filePath : files ) - { - wxFileName fn( filePath ); - wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB ); - - if( cur_model()->ContainsNickname( nickname ) ) - { - if( skipRemainingDuplicates ) - continue; - - int ret = YesNoCancelDialog( this, - _( "Warning: Duplicate Nickname" ), - wxString::Format( _( "A library nicknamed \"%s\" already exists." ), nickname ), - _( "Skip" ), - _( "Skip All Remaining Duplicates" ), - _( "Add Anyway" ) ); - - if( ret == wxID_YES ) - continue; - else if ( ret == wxID_NO ) - { - skipRemainingDuplicates = true; - continue; - } - } - - if( m_cur_grid->AppendRows( 1 ) ) - { - int last_row = m_cur_grid->GetNumberRows() - 1; - - m_cur_grid->SetCellValue( last_row, COL_NICKNAME, nickname ); - - auto type = IO_MGR::GuessPluginTypeFromLibPath( filePath ); - m_cur_grid->SetCellValue( last_row, COL_TYPE, IO_MGR::ShowType( type ) ); - - // try to use path normalized to an environmental variable or project path - wxString normalizedPath = NormalizePath( filePath, &Pgm().GetLocalEnvVariables(), &Prj() ); - m_cur_grid->SetCellValue( last_row, COL_URI, - normalizedPath.IsEmpty() ? fn.GetFullPath() : normalizedPath ); - } - } - - if( !files.IsEmpty() ) - scrollToRow( m_cur_grid->GetNumberRows() - 1 ); // scroll to the new libraries + wxString evValue; + wxGetEnv( evName, &evValue ); + m_path_subs_grid->SetCellValue( row, 1, evValue ); } - void onCancelButtonClick( wxCommandEvent& event ) override - { - EndModal( 0 ); - } + // No combobox editors here, but it looks better if its consistent with the other + // grids in the dialog. + m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 4 ); - void onCancelCaptionButtonClick( wxCloseEvent& event ) override - { - EndModal( 0 ); - } + adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() ); +} - void onOKButtonClick( wxCommandEvent& event ) override - { - int dialogRet = 0; - - // stuff any pending cell editor text into the table. - m_cur_grid->DisableCellEditControl(); - - if( verifyTables() ) - { - if( *global_model() != *m_global ) - { - dialogRet |= 1; - - m_global->Clear(); - m_global->rows.transfer( m_global->rows.end(), global_model()->rows.begin(), - global_model()->rows.end(), global_model()->rows ); - m_global->reindex(); - } - - if( *project_model() != *m_project ) - { - dialogRet |= 2; - - m_project->Clear(); - m_project->rows.transfer( m_project->rows.end(), project_model()->rows.begin(), - project_model()->rows.end(), project_model()->rows ); - m_project->reindex(); - } - - EndModal( dialogRet ); - } - } - - /// Populate the readonly environment variable table with names and values - /// by examining all the full_uri columns. - void populateEnvironReadOnlyTable() - { - wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED ); - wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required. - - std::set< wxString > unique; - - // clear the table - m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() ); - - for( int i = 0; i < 2; ++i ) - { - FP_LIB_TABLE_GRID* tbl = i == 0 ? global_model() : project_model(); - - for( int row = 0; row < tbl->GetNumberRows(); ++row ) - { - wxString uri = tbl->GetValue( row, COL_URI ); - - while( re.Matches( uri ) ) - { - wxString envvar = re.GetMatch( uri, 2 ); - - // if not ${...} form then must be $(...) - if( envvar.IsEmpty() ) - envvar = re.GetMatch( uri, 4 ); - - // ignore duplicates - unique.insert( envvar ); - - // delete the last match and search again - uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); - } - } - } - - // Make sure this special environment variable shows up even if it was - // not used yet. It is automatically set by KiCad to the directory holding - // the current project. - unique.insert( PROJECT_VAR_NAME ); - unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() ); - // This special environment variable is used to locate 3d shapes - unique.insert( KISYS3DMOD ); - - m_path_subs_grid->AppendRows( unique.size() ); - - int row = 0; - - for( auto it = unique.begin(); it != unique.end(); ++it, ++row ) - { - wxString evName = *it; - wxString evValue; - - m_path_subs_grid->SetCellValue( row, 0, evName ); - - if( wxGetEnv( evName, &evValue ) ) - m_path_subs_grid->SetCellValue( row, 1, evValue ); - } - - m_path_subs_grid->AutoSizeColumns(); - } - - /// Makes a specific row visible - void scrollToRow( int aRowNumber ) - { - // wx documentation is wrong, SetGridCursor does not make visible. - m_cur_grid->MakeCellVisible( aRowNumber, 0 ); - m_cur_grid->SetGridCursor( aRowNumber, 0 ); - m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() ); - } - - //-------------------------------------- - - // caller's tables are modified only on OK button and successful verification. - FP_LIB_TABLE* m_global; - FP_LIB_TABLE* m_project; - - FP_LIB_TABLE_GRID* global_model() const - { - return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable(); - } - - FP_LIB_TABLE_GRID* project_model() const - { - return (FP_LIB_TABLE_GRID*) m_project_grid->GetTable(); - } - - FP_LIB_TABLE_GRID* cur_model() const - { - return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable(); - } - - wxGrid* m_cur_grid; ///< changed based on tab choice - static int m_pageNdx; ///< Remember the last notebook page selected during a session - - wxString m_lastBrowseDir; ///< last browsed directory -}; +//-------------------------------------- -int DIALOG_FP_LIB_TABLE::m_pageNdx = 0; + +size_t DIALOG_FP_LIB_TABLE::m_pageNdx = 0; + +wxString DIALOG_FP_LIB_TABLE::m_lastBrowseDir; int InvokePcbLibTableEditor( wxTopLevelWindow* aCaller, FP_LIB_TABLE* aGlobal, diff --git a/pcbnew/dialogs/dialog_fp_lib_table.h b/pcbnew/dialogs/dialog_fp_lib_table.h new file mode 100644 index 0000000000..89f560b3e7 --- /dev/null +++ b/pcbnew/dialogs/dialog_fp_lib_table.h @@ -0,0 +1,88 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 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 + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef DIALOG_FP_LIB_TABLE_H +#define DIALOG_FP_LIB_TABLE_H + +#include "dialog_fp_lib_table_base.h" + +class FP_LIB_TABLE; +class FP_LIB_TABLE_GRID; + + +/** + * Dialog to show and edit symbol library tables. + */ +class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE +{ + +public: + DIALOG_FP_LIB_TABLE( wxWindow* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject ); + ~DIALOG_FP_LIB_TABLE() override; + + bool Show( bool aShow ) override; + +private: + /** + * Trim important fields, removes blank row entries, and checks for duplicates. + * + * @return bool - true if tables are OK, else false. + */ + bool verifyTables(); + + void pageChangedHandler( wxAuiNotebookEvent& event ) override; + void appendRowHandler( wxCommandEvent& event ) override; + void browseLibrariesHandler( wxCommandEvent& event ) override; + void deleteRowHandler( wxCommandEvent& event ) override; + void moveUpHandler( wxCommandEvent& event ) override; + void moveDownHandler( wxCommandEvent& event ) override; + void onOKButtonClick( wxCommandEvent& event ) override; + void onSizeGrid( wxSizeEvent& event ) override; + + void adjustPathSubsGridColumns( int aWidth ); + + /// Populate the readonly environment variable table with names and values + /// by examining all the full_uri columns. + void populateEnvironReadOnlyTable(); + + // caller's tables are modified only on OK button and successful verification. + FP_LIB_TABLE* m_global; + FP_LIB_TABLE* m_project; + + FP_LIB_TABLE_GRID* global_model() const + { + return (FP_LIB_TABLE_GRID*) m_global_grid->GetTable(); + } + + FP_LIB_TABLE_GRID* project_model() const + { + return (FP_LIB_TABLE_GRID*) m_project_grid->GetTable(); + } + + FP_LIB_TABLE_GRID* cur_model() const + { + return (FP_LIB_TABLE_GRID*) m_cur_grid->GetTable(); + } + + wxGrid* m_cur_grid; // changed based on tab choice + static size_t m_pageNdx; // Remember last notebook page selected during a session + static wxString m_lastBrowseDir; // Remember last directory browsed during a session +}; + +#endif // DIALOG_FP_LIB_TABLE_H diff --git a/pcbnew/dialogs/dialog_fp_lib_table_base.cpp b/pcbnew/dialogs/dialog_fp_lib_table_base.cpp index 06807fa600..7ad3222f8d 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table_base.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table_base.cpp @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 17 2016) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // -// PLEASE DO "NOT" EDIT THIS FILE! +// PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #include "dialog_fp_lib_table_base.h" @@ -13,13 +13,15 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - wxBoxSizer* bSizer1; - bSizer1 = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* bMainSizer; + bMainSizer = new wxBoxSizer( wxVERTICAL ); wxStaticBoxSizer* m_top_sizer; m_top_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Libraries by Scope") ), wxVERTICAL ); m_auinotebook = new wxAuiNotebook( m_top_sizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_auinotebook->SetMinSize( wxSize( 720,460 ) ); + m_global_panel = new wxPanel( m_auinotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxBoxSizer* m_global_sizer; m_global_sizer = new wxBoxSizer( wxVERTICAL ); @@ -53,12 +55,12 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID m_global_grid->AutoSizeColumns(); m_global_grid->EnableDragColMove( false ); m_global_grid->EnableDragColSize( true ); - m_global_grid->SetColLabelSize( 30 ); + m_global_grid->SetColLabelSize( 22 ); m_global_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_global_grid->EnableDragRowSize( false ); - m_global_grid->SetRowLabelSize( 40 ); + m_global_grid->SetRowLabelSize( 0 ); m_global_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Label Appearance @@ -105,12 +107,12 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID m_project_grid->AutoSizeColumns(); m_project_grid->EnableDragColMove( false ); m_project_grid->EnableDragColSize( true ); - m_project_grid->SetColLabelSize( 30 ); + m_project_grid->SetColLabelSize( 22 ); m_project_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_project_grid->EnableDragRowSize( false ); - m_project_grid->SetRowLabelSize( 40 ); + m_project_grid->SetRowLabelSize( 0 ); m_project_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Label Appearance @@ -125,44 +127,31 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID m_project_sizer->Fit( m_project_panel ); m_auinotebook->AddPage( m_project_panel, _("Project Specific Libraries"), true, wxNullBitmap ); - m_top_sizer->Add( m_auinotebook, 6, wxEXPAND | wxALL, 5 ); + m_top_sizer->Add( m_auinotebook, 6, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - wxBoxSizer* bSizer51; - bSizer51 = new wxBoxSizer( wxHORIZONTAL ); + wxBoxSizer* bButtonsSizer; + bButtonsSizer = new wxBoxSizer( wxHORIZONTAL ); - m_browseButton = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Browse Libraries..."), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer51->Add( m_browseButton, 0, wxALL, 5 ); + m_append_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bButtonsSizer->Add( m_append_button, 0, wxLEFT, 5 ); - m_append_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Append Library"), wxDefaultPosition, wxDefaultSize, 0 ); - m_append_button->SetToolTip( _("Add a PCB library row to this table") ); + m_browse_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bButtonsSizer->Add( m_browse_button, 0, wxRIGHT, 5 ); - bSizer51->Add( m_append_button, 0, wxALL, 5 ); + m_delete_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bButtonsSizer->Add( m_delete_button, 0, wxRIGHT|wxLEFT, 5 ); - m_delete_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Remove Library"), wxDefaultPosition, wxDefaultSize, 0 ); - m_delete_button->SetToolTip( _("Remove a PCB library from this library table") ); + m_move_up_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bButtonsSizer->Add( m_move_up_button, 0, wxLEFT, 5 ); - bSizer51->Add( m_delete_button, 0, wxALL, 5 ); - - m_move_up_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Move Up"), wxDefaultPosition, wxDefaultSize, 0 ); - m_move_up_button->SetToolTip( _("Move the currently selected row up one position") ); - - bSizer51->Add( m_move_up_button, 0, wxALL, 5 ); - - m_move_down_button = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Move Down"), wxDefaultPosition, wxDefaultSize, 0 ); - m_move_down_button->SetToolTip( _("Move the currently selected row down one position") ); - - bSizer51->Add( m_move_down_button, 0, wxALL, 5 ); - - m_edit_options = new wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Options Editor"), wxDefaultPosition, wxDefaultSize, 0 ); - m_edit_options->SetToolTip( _("Zoom into the options table for current row") ); - - bSizer51->Add( m_edit_options, 0, wxALL, 5 ); + m_move_down_button = new wxBitmapButton( m_top_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bButtonsSizer->Add( m_move_down_button, 0, wxRIGHT, 5 ); - m_top_sizer->Add( bSizer51, 0, wxALIGN_CENTER|wxBOTTOM, 8 ); + m_top_sizer->Add( bButtonsSizer, 0, wxEXPAND, 5 ); - bSizer1->Add( m_top_sizer, 1, wxALL|wxEXPAND, 5 ); + bMainSizer->Add( m_top_sizer, 1, wxALL|wxEXPAND, 5 ); wxStaticBoxSizer* sbSizer1; sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Path Substitutions:") ), wxVERTICAL ); @@ -182,14 +171,12 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID m_path_subs_grid->AutoSizeColumns(); m_path_subs_grid->EnableDragColMove( false ); m_path_subs_grid->EnableDragColSize( true ); - m_path_subs_grid->SetColLabelSize( 30 ); - m_path_subs_grid->SetColLabelValue( 0, _("Environment Variable") ); - m_path_subs_grid->SetColLabelValue( 1, _("Path Segment") ); + m_path_subs_grid->SetColLabelSize( 0 ); m_path_subs_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_path_subs_grid->EnableDragRowSize( true ); - m_path_subs_grid->SetRowLabelSize( 40 ); + m_path_subs_grid->SetRowLabelSize( 0 ); m_path_subs_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Label Appearance @@ -198,10 +185,10 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID m_path_subs_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); m_path_subs_grid->SetToolTip( _("This is a read-only table which shows pertinent environment variables.") ); - sbSizer1->Add( m_path_subs_grid, 1, wxALL|wxEXPAND, 5 ); + sbSizer1->Add( m_path_subs_grid, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - bSizer1->Add( sbSizer1, 0, wxALL|wxEXPAND, 5 ); + bMainSizer->Add( sbSizer1, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); wxBoxSizer* m_bottom_sizer; m_bottom_sizer = new wxBoxSizer( wxVERTICAL ); @@ -213,44 +200,38 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - m_bottom_sizer->Add( m_sdbSizer, 0, wxALL|wxEXPAND, 5 ); + m_bottom_sizer->Add( m_sdbSizer, 0, wxEXPAND, 5 ); - bSizer1->Add( m_bottom_sizer, 0, wxEXPAND, 5 ); + bMainSizer->Add( m_bottom_sizer, 0, wxEXPAND, 5 ); - this->SetSizer( bSizer1 ); + this->SetSizer( bMainSizer ); this->Layout(); this->Centre( wxBOTH ); // Connect Events - this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FP_LIB_TABLE_BASE::onCancelCaptionButtonClick ) ); - this->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_FP_LIB_TABLE_BASE::onKeyDown ) ); m_auinotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_FP_LIB_TABLE_BASE::pageChangedHandler ), NULL, this ); - m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::appendRowHandler ), NULL, this ); + m_browse_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::deleteRowHandler ), NULL, this ); m_move_up_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveUpHandler ), NULL, this ); m_move_down_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveDownHandler ), NULL, this ); - m_edit_options->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::optionsEditor ), NULL, this ); - m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::onCancelButtonClick ), NULL, this ); + m_path_subs_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_LIB_TABLE_BASE::onSizeGrid ), NULL, this ); m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::onOKButtonClick ), NULL, this ); } DIALOG_FP_LIB_TABLE_BASE::~DIALOG_FP_LIB_TABLE_BASE() { // Disconnect Events - this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FP_LIB_TABLE_BASE::onCancelCaptionButtonClick ) ); - this->Disconnect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_FP_LIB_TABLE_BASE::onKeyDown ) ); m_auinotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_FP_LIB_TABLE_BASE::pageChangedHandler ), NULL, this ); - m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::appendRowHandler ), NULL, this ); + m_browse_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this ); m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::deleteRowHandler ), NULL, this ); m_move_up_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveUpHandler ), NULL, this ); m_move_down_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveDownHandler ), NULL, this ); - m_edit_options->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::optionsEditor ), NULL, this ); - m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::onCancelButtonClick ), NULL, this ); + m_path_subs_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_LIB_TABLE_BASE::onSizeGrid ), NULL, this ); m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::onOKButtonClick ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_fp_lib_table_base.fbp b/pcbnew/dialogs/dialog_fp_lib_table_base.fbp index 21994aa9bc..b8eee3df72 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table_base.fbp +++ b/pcbnew/dialogs/dialog_fp_lib_table_base.fbp @@ -61,14 +61,14 @@ - onCancelCaptionButtonClick + - onKeyDown + @@ -90,7 +90,7 @@ - bSizer1 + bMainSizer wxVERTICAL none @@ -108,7 +108,7 @@ 5 - wxEXPAND | wxALL + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 6 1 @@ -143,7 +143,7 @@ 0 - + 720,460 1 m_auinotebook 1 @@ -279,11 +279,11 @@ m_global_sizer wxVERTICAL none - + 5 wxEXPAND 0 - + 2 wxBOTH @@ -295,11 +295,11 @@ none 1 0 - + 4 wxTOP|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -378,11 +378,11 @@ - + 4 wxTOP|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -490,7 +490,7 @@ 0 1 wxALIGN_CENTRE - 30 + 22 wxALIGN_CENTRE 5 @@ -536,7 +536,7 @@ Fixed wxALIGN_CENTRE - 40 + 0 wxALIGN_CENTRE @@ -692,11 +692,11 @@ m_project_sizer wxVERTICAL none - + 5 wxEXPAND 0 - + 2 wxBOTH @@ -712,7 +712,7 @@ 4 wxLEFT|wxRIGHT|wxTOP 0 - + 1 1 1 @@ -795,7 +795,7 @@ 4 wxLEFT|wxRIGHT|wxTOP 0 - + 1 1 1 @@ -903,7 +903,7 @@ 0 1 wxALIGN_CENTRE - 30 + 22 wxALIGN_CENTRE 5 @@ -949,7 +949,7 @@ Fixed wxALIGN_CENTRE - 40 + 0 wxALIGN_CENTRE @@ -1025,19 +1025,19 @@ - 8 - wxALIGN_CENTER|wxBOTTOM + 5 + wxEXPAND 0 - bSizer51 + bButtonsSizer wxHORIZONTAL none 5 - wxALL + wxLEFT 0 - + 1 1 1 @@ -1048,6 +1048,7 @@ + 1 0 @@ -1056,17 +1057,20 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY - Browse Libraries... + Add Library 0 @@ -1074,7 +1078,7 @@ 0 1 - m_browseButton + m_append_button 1 @@ -1082,10 +1086,104 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + appendRowHandler + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + + wxID_ANY + Browse for Library + + 0 + + + 0 + + 1 + m_browse_button + 1 + + + protected + 1 + + Resizable + + 1 + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 @@ -1121,99 +1219,11 @@ - + 5 - wxALL + wxRIGHT|wxLEFT 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Append Library - - 0 - - - 0 - - 1 - m_append_button - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - Add a PCB library row to this table - - wxFILTER_NONE - wxDefaultValidator - - - - - appendRowHandler - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL - 0 - + 1 1 1 @@ -1224,6 +1234,7 @@ + 1 0 @@ -1232,15 +1243,18 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY Remove Library @@ -1258,12 +1272,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Remove a PCB library from this library table + wxFILTER_NONE wxDefaultValidator @@ -1297,11 +1312,11 @@ - + 5 - wxALL + wxLEFT 0 - + 1 1 1 @@ -1312,6 +1327,7 @@ + 1 0 @@ -1320,15 +1336,18 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY Move Up @@ -1346,12 +1365,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Move the currently selected row up one position + wxFILTER_NONE wxDefaultValidator @@ -1385,11 +1405,11 @@ - + 5 - wxALL + wxRIGHT 0 - + 1 1 1 @@ -1400,6 +1420,7 @@ + 1 0 @@ -1408,15 +1429,18 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY Move Down @@ -1434,12 +1458,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Move the currently selected row down one position + wxFILTER_NONE wxDefaultValidator @@ -1473,101 +1498,13 @@ - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Options Editor - - 0 - - - 0 - - 1 - m_edit_options - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - Zoom into the options table for current row - - wxFILTER_NONE - wxDefaultValidator - - - - - optionsEditor - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL|wxEXPAND + wxEXPAND|wxRIGHT|wxLEFT 0 wxID_ANY @@ -1580,7 +1517,7 @@ 5 - wxALL|wxEXPAND + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 1 1 @@ -1605,8 +1542,8 @@ 0 1 wxALIGN_CENTRE - 30 - "Environment Variable" "Path Segment" + 0 + wxALIGN_CENTRE 2 150,500 @@ -1651,7 +1588,7 @@ Resizable wxALIGN_CENTRE - 40 + 0 wxALIGN_CENTRE @@ -1717,7 +1654,7 @@ - + onSizeGrid @@ -1734,7 +1671,7 @@ none 5 - wxALL|wxEXPAND + wxEXPAND 0 0 @@ -1749,7 +1686,7 @@ m_sdbSizer protected - onCancelButtonClick + diff --git a/pcbnew/dialogs/dialog_fp_lib_table_base.h b/pcbnew/dialogs/dialog_fp_lib_table_base.h index a229d68993..115cf48c25 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table_base.h +++ b/pcbnew/dialogs/dialog_fp_lib_table_base.h @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jul 17 2016) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // -// PLEASE DO "NOT" EDIT THIS FILE! +// PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #ifndef __DIALOG_FP_LIB_TABLE_BASE_H__ @@ -11,8 +11,6 @@ #include #include #include -class DIALOG_SHIM; - #include "dialog_shim.h" #include #include @@ -27,6 +25,7 @@ class DIALOG_SHIM; #include #include #include +#include #include #include #include @@ -51,28 +50,24 @@ class DIALOG_FP_LIB_TABLE_BASE : public DIALOG_SHIM wxStaticText* m_staticText4; wxStaticText* m_PrjTableFilename; wxGrid* m_project_grid; - wxButton* m_browseButton; - wxButton* m_append_button; - wxButton* m_delete_button; - wxButton* m_move_up_button; - wxButton* m_move_down_button; - wxButton* m_edit_options; + wxBitmapButton* m_append_button; + wxBitmapButton* m_browse_button; + wxBitmapButton* m_delete_button; + wxBitmapButton* m_move_up_button; + wxBitmapButton* m_move_down_button; wxGrid* m_path_subs_grid; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; // Virtual event handlers, overide them in your derived class - virtual void onCancelCaptionButtonClick( wxCloseEvent& event ) = 0; - virtual void onKeyDown( wxKeyEvent& event ) = 0; virtual void pageChangedHandler( wxAuiNotebookEvent& event ) = 0; - virtual void browseLibrariesHandler( wxCommandEvent& event ) = 0; virtual void appendRowHandler( wxCommandEvent& event ) = 0; + virtual void browseLibrariesHandler( wxCommandEvent& event ) = 0; virtual void deleteRowHandler( wxCommandEvent& event ) = 0; virtual void moveUpHandler( wxCommandEvent& event ) = 0; virtual void moveDownHandler( wxCommandEvent& event ) = 0; - virtual void optionsEditor( wxCommandEvent& event ) = 0; - virtual void onCancelButtonClick( wxCommandEvent& event ) = 0; + virtual void onSizeGrid( wxSizeEvent& event ) = 0; virtual void onOKButtonClick( wxCommandEvent& event ) = 0; diff --git a/pcbnew/dialogs/dialog_fp_plugin_options.cpp b/pcbnew/dialogs/dialog_fp_plugin_options.cpp index 7d479c460c..72d0b27c26 100644 --- a/pcbnew/dialogs/dialog_fp_plugin_options.cpp +++ b/pcbnew/dialogs/dialog_fp_plugin_options.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #define INITIAL_HELP \ @@ -37,10 +38,6 @@ using std::string; -// re-enter the dialog with the column sizes preserved from last time. -static int col_width_option; -static int col_width_value; - /** * Class DIALOG_FP_PLUGIN_OPTIONS @@ -52,26 +49,62 @@ class DIALOG_FP_PLUGIN_OPTIONS : public DIALOG_FP_PLUGIN_OPTIONS_BASE { public: - DIALOG_FP_PLUGIN_OPTIONS( wxTopLevelWindow* aParent, - const wxString& aNickname, const wxString& aPluginType, - const wxString& aOptions, wxString* aResult ) : + DIALOG_FP_PLUGIN_OPTIONS( wxWindow* aParent, const wxString& aNickname, + const wxString& aPluginType, const wxString& aOptions, + wxString* aResult ) : DIALOG_FP_PLUGIN_OPTIONS_BASE( aParent ), m_callers_options( aOptions ), m_result( aResult ), m_initial_help( INITIAL_HELP ) { - wxString title = wxString::Format( - _( "Options for Library \"%s\"" ), GetChars( aNickname ) ); - - SetTitle( title ); + SetTitle( wxString::Format( _( "Options for Library \"%s\"" ), aNickname ) ); // add Cut, Copy, and Paste to wxGrid m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) ); - m_grid->SetColMinimalWidth( 1, 250 ); + // Option Choices Panel: + + IO_MGR::PCB_FILE_T pi_type = IO_MGR::EnumFromStr( aPluginType ); + PLUGIN::RELEASER pi( IO_MGR::PluginFind( pi_type ) ); + + pi->FootprintLibOptions( &m_choices ); + + if( m_choices.size() ) + { + unsigned int row = 0; + for( PROPERTIES::const_iterator it = m_choices.begin(); it != m_choices.end(); ++it, ++row ) + { + wxString item = FROM_UTF8( it->first.c_str() ); + + m_listbox->InsertItems( 1, &item, row ); + } + } + + m_html->SetPage( m_initial_help ); + + // Configure button logos + m_append_button->SetBitmap( KiBitmap( small_plus_xpm ) ); + m_delete_button->SetBitmap( KiBitmap( trash_xpm ) ); + + // initial focus on the grid please. + SetInitialFocus( m_grid ); + + m_sdbSizer1OK->SetDefault(); + } + + ~DIALOG_FP_PLUGIN_OPTIONS() override + { + // destroy GRID_TRICKS before m_grid. + m_grid->PopEventHandler( true ); + } + + bool TransferDataToWindow() override + { + if( !DIALOG_SHIM::TransferDataToWindow() ) + return false; // Fill the grid with existing aOptions - string options = TO_UTF8( aOptions ); + string options = TO_UTF8( m_callers_options ); PROPERTIES* props = LIB_TABLE::ParseOptions( options ); @@ -90,94 +123,19 @@ public: delete props; } - // Option Choices Panel: + adjustGridColumns( m_grid->GetRect().GetWidth() ); - IO_MGR::PCB_FILE_T pi_type = IO_MGR::EnumFromStr( aPluginType ); - PLUGIN::RELEASER pi( IO_MGR::PluginFind( pi_type ) ); - - pi->FootprintLibOptions( &m_choices ); - - if( m_choices.size() ) - { - int row = 0; - for( PROPERTIES::const_iterator it = m_choices.begin(); it != m_choices.end(); ++it, ++row ) - { - wxString item = FROM_UTF8( it->first.c_str() ); - - m_listbox->InsertItems( 1, &item, row ); - } - } - - m_html->SetPage( m_initial_help ); - - if( !col_width_option ) - { - m_grid->AutoSizeColumns( false ); - } - else - { - m_grid->SetColSize( 0, col_width_option ); - m_grid->SetColSize( 1, col_width_value ); - } - - Fit(); - - // initial focus on the grid please. - m_grid->SetFocus(); + return true; } - ~DIALOG_FP_PLUGIN_OPTIONS() + bool TransferDataFromWindow() override { - // destroy GRID_TRICKS before m_grid. - m_grid->PopEventHandler( true ); - } + // Write any active editors into the grid + m_grid->DisableCellEditControl(); + if( !DIALOG_SHIM::TransferDataFromWindow() ) + return false; -private: - const wxString& m_callers_options; - wxString* m_result; - PROPERTIES m_choices; - wxString m_initial_help; - - - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based column index. - int getCursorCol() const - { - return m_grid->GetGridCursorCol(); - } - - /// If the cursor is not on a valid cell, because there are no rows at all, return -1, - /// else return a 0 based row index. - int getCursorRow() const - { - return m_grid->GetGridCursorRow(); - } - - wxArrayString getRow( int aRow ) - { - wxArrayString row; - - const int col_count = m_grid->GetNumberCols(); - for( int col = 0; col < col_count; ++col ) - { - row.Add( m_grid->GetCellValue( aRow, col ) ); - } - - return row; - } - - void setRow( int aRow, const wxArrayString& aPair ) - { - const int col_count = m_grid->GetNumberCols(); - for( int col = 0; col < col_count; ++col ) - { - m_grid->SetCellValue( aRow, col, aPair[col] ); - } - } - - wxString makeResult() - { PROPERTIES props; const int rowCount = m_grid->GetNumberRows(); @@ -192,37 +150,27 @@ private: } } - return LIB_TABLE::FormatOptions( &props ); + *m_result = LIB_TABLE::FormatOptions( &props ); + return true; } - void saveColSizes() - { - col_width_option = m_grid->GetColSize( 0 ); - col_width_value = m_grid->GetColSize( 1 ); - } - - void abort() - { - saveColSizes(); - - *m_result = m_callers_options; // tell caller "no change" - EndModal( 0 ); - } +private: + const wxString& m_callers_options; + wxString* m_result; + PROPERTIES m_choices; + wxString m_initial_help; int appendRow() { - if( m_grid->AppendRows( 1 ) ) - { - int last_row = m_grid->GetNumberRows() - 1; + int row = m_grid->GetNumberRows(); - // wx documentation is wrong, SetGridCursor does not make visible. - m_grid->MakeCellVisible( last_row, 0 ); - m_grid->SetGridCursor( last_row, 0 ); + m_grid->AppendRows( 1 ); - return last_row; - } + // wx documentation is wrong, SetGridCursor does not make visible. + m_grid->MakeCellVisible( row, 0 ); + m_grid->SetGridCursor( row, 0 ); - return -1; + return row; } void appendOption() @@ -247,7 +195,6 @@ private: row = appendRow(); m_grid->SetCellValue( row, 0, option ); - m_grid->AutoSizeColumns( false ); } } @@ -262,15 +209,9 @@ private: UTF8 help_text; if( m_choices.Value( option.c_str(), &help_text ) ) - { - wxString page = help_text; - - m_html->SetPage( page ); - } + m_html->SetPage( help_text ); else - { m_html->SetPage( m_initial_help ); - } } } @@ -279,19 +220,25 @@ private: appendOption(); } - void onAppendOption( wxCommandEvent& event ) override + void onAppendOption( wxCommandEvent& ) override { appendOption(); } - void onAppendRow( wxMouseEvent& event ) override + void onAppendRow( wxCommandEvent& ) override { appendRow(); } - void onDeleteRow( wxMouseEvent& event ) override + void onDeleteRow( wxCommandEvent& ) override { - int curRow = getCursorRow(); + if( !m_grid->HasFocus() ) + { + m_grid->SetFocus(); + return; + } + + int curRow = m_grid->GetGridCursorRow(); m_grid->DeleteRows( curRow ); @@ -300,97 +247,40 @@ private: m_grid->SetGridCursor( curRow, m_grid->GetGridCursorCol() ); } - void onMoveUp( wxMouseEvent& event ) override + void onUpdateUI( wxUpdateUIEvent& ) override { - int curRow = getCursorRow(); - if( curRow >= 1 ) - { - int curCol = getCursorCol(); - - wxArrayString move_me = getRow( curRow ); - - m_grid->DeleteRows( curRow ); - --curRow; - m_grid->InsertRows( curRow ); - - setRow( curRow, move_me ); - - wxGridTableBase* tbl = m_grid->GetTable(); - - if( tbl->GetView() ) - { - // fire a msg to cause redrawing - wxGridTableMessage msg( tbl, - wxGRIDTABLE_NOTIFY_ROWS_INSERTED, - curRow, - 0 ); - - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_grid->MakeCellVisible( curRow, curCol ); - m_grid->SetGridCursor( curRow, curCol ); - } + if( !m_grid->IsCellEditControlShown() ) + adjustGridColumns( m_grid->GetRect().GetWidth() ); } - void onMoveDown( wxMouseEvent& event ) override + void onSize( wxSizeEvent& aEvent ) override { - int curRow = getCursorRow(); - if( curRow + 1 < m_grid->GetNumberRows() ) - { - int curCol = getCursorCol(); + adjustGridColumns( aEvent.GetSize().GetX() ); - wxArrayString move_me = getRow( curRow ); - - m_grid->DeleteRows( curRow ); - ++curRow; - m_grid->InsertRows( curRow ); - setRow( curRow, move_me ); - - wxGridTableBase* tbl = m_grid->GetTable(); - - if( tbl->GetView() ) - { - // fire a msg to cause redrawing - wxGridTableMessage msg( tbl, - wxGRIDTABLE_NOTIFY_ROWS_INSERTED, - curRow - 1, - 0 ); - - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_grid->MakeCellVisible( curRow, curCol ); - m_grid->SetGridCursor( curRow, curCol ); - } + aEvent.Skip(); } - void onCancelButtonClick( wxCommandEvent& event ) override - { - abort(); - } - - void onCancelCaptionButtonClick( wxCloseEvent& event ) override - { - abort(); - } - - void onOKButtonClick( wxCommandEvent& event ) override - { - saveColSizes(); - - *m_result = makeResult(); // change from edits - EndModal( 1 ); - } //---------------------------------------------------------- + + void adjustGridColumns( int aWidth ) + { + m_grid->Freeze(); + + m_grid->AutoSizeColumn( 0 ); + m_grid->SetColSize( 0, std::max( 120, m_grid->GetColSize( 0 ) ) ); + + m_grid->SetColSize( 1, aWidth - m_grid->GetColSize( 0 ) ); + + m_grid->Thaw(); + } }; -void InvokePluginOptionsEditor( wxTopLevelWindow* aCaller, - const wxString& aNickname, const wxString& aPluginType, - const wxString& aOptions, wxString* aResult ) +void InvokePluginOptionsEditor( wxWindow* aCaller, const wxString& aNickname, + const wxString& aPluginType, const wxString& aOptions, + wxString* aResult ) { - DIALOG_FP_PLUGIN_OPTIONS dlg( aCaller, aNickname, aPluginType, aOptions, aResult ); + DIALOG_FP_PLUGIN_OPTIONS dlg( aCaller, aNickname, aPluginType, aOptions, aResult ); dlg.ShowModal(); } diff --git a/pcbnew/dialogs/dialog_fp_plugin_options_base.cpp b/pcbnew/dialogs/dialog_fp_plugin_options_base.cpp index 832ac9b22d..fe800cce49 100644 --- a/pcbnew/dialogs/dialog_fp_plugin_options_base.cpp +++ b/pcbnew/dialogs/dialog_fp_plugin_options_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Nov 22 2017) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -13,16 +13,16 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent, { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - wxBoxSizer* bSizer4; - bSizer4 = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* bMainSizer; + bMainSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer* m_horizontal_sizer; m_horizontal_sizer = new wxBoxSizer( wxHORIZONTAL ); wxStaticBoxSizer* m_grid_sizer; - m_grid_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Plugin Options:") ), wxVERTICAL ); + m_grid_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Plugin Options") ), wxVERTICAL ); - m_grid_sizer->SetMinSize( wxSize( -1,300 ) ); + m_grid_sizer->SetMinSize( wxSize( 400,300 ) ); m_grid = new wxGrid( m_grid_sizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL ); // Grid @@ -33,85 +33,65 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent, m_grid->SetMargins( 0, 0 ); // Columns + m_grid->SetColSize( 0, 120 ); + m_grid->SetColSize( 1, 240 ); m_grid->EnableDragColMove( false ); m_grid->EnableDragColSize( true ); - m_grid->SetColLabelSize( 30 ); + m_grid->SetColLabelSize( 22 ); m_grid->SetColLabelValue( 0, _("Option") ); m_grid->SetColLabelValue( 1, _("Value") ); m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_grid->EnableDragRowSize( false ); - m_grid->SetRowLabelSize( 40 ); + m_grid->SetRowLabelSize( 0 ); m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Label Appearance // Cell Defaults m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); - m_grid_sizer->Add( m_grid, 1, wxEXPAND|wxTOP, 5 ); + m_grid_sizer->Add( m_grid, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); - wxBoxSizer* m_button_sizer; - m_button_sizer = new wxBoxSizer( wxHORIZONTAL ); + wxBoxSizer* bButtonsSizer; + bButtonsSizer = new wxBoxSizer( wxHORIZONTAL ); - m_add_row = new wxButton( m_grid_sizer->GetStaticBox(), wxID_ANY, _("Append"), wxDefaultPosition, wxDefaultSize, 0 ); - m_add_row->SetToolTip( _("Append a blank row") ); + m_append_button = new wxBitmapButton( m_grid_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bButtonsSizer->Add( m_append_button, 0, wxLEFT, 5 ); - m_button_sizer->Add( m_add_row, 0, wxALL, 5 ); - - m_delete_row = new wxButton( m_grid_sizer->GetStaticBox(), wxID_ANY, _("Delete"), wxDefaultPosition, wxDefaultSize, 0 ); - m_delete_row->SetToolTip( _("Delete the selected row") ); - - m_button_sizer->Add( m_delete_row, 0, wxALL, 5 ); - - m_move_up = new wxButton( m_grid_sizer->GetStaticBox(), wxID_ANY, _("Move Up"), wxDefaultPosition, wxDefaultSize, 0 ); - m_move_up->SetToolTip( _("Move the selected row up one position") ); - - m_button_sizer->Add( m_move_up, 0, wxALL, 5 ); - - m_move_down = new wxButton( m_grid_sizer->GetStaticBox(), wxID_ANY, _("Move Down"), wxDefaultPosition, wxDefaultSize, 0 ); - m_move_down->SetToolTip( _("Move the selected row down one position") ); - - m_button_sizer->Add( m_move_down, 0, wxALL, 5 ); + m_delete_button = new wxBitmapButton( m_grid_sizer->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 30,30 ), wxBU_AUTODRAW ); + bButtonsSizer->Add( m_delete_button, 0, wxRIGHT, 5 ); - m_grid_sizer->Add( m_button_sizer, 0, wxALIGN_CENTER, 5 ); + m_grid_sizer->Add( bButtonsSizer, 0, wxEXPAND|wxTOP, 5 ); - m_horizontal_sizer->Add( m_grid_sizer, 3, wxEXPAND, 5 ); - - wxGridSizer* m_choose_size; - m_choose_size = new wxGridSizer( 1, 1, 0, 0 ); - - - m_horizontal_sizer->Add( m_choose_size, 0, wxEXPAND, 5 ); + m_horizontal_sizer->Add( m_grid_sizer, 3, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); wxStaticBoxSizer* m_options_sizer; - m_options_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Option Choices:") ), wxVERTICAL ); + m_options_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Option Choices") ), wxVERTICAL ); - m_options_sizer->SetMinSize( wxSize( 200,-1 ) ); m_listbox = new wxListBox( m_options_sizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_ALWAYS_SB|wxLB_SINGLE ); m_listbox->SetToolTip( _("Options supported by current plugin") ); - m_options_sizer->Add( m_listbox, 2, wxALL|wxEXPAND, 5 ); + m_options_sizer->Add( m_listbox, 3, wxALL|wxEXPAND, 5 ); m_append_choice_button = new wxButton( m_options_sizer->GetStaticBox(), wxID_ANY, _("<< Append Selected Option"), wxDefaultPosition, wxDefaultSize, 0 ); m_options_sizer->Add( m_append_choice_button, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); - m_staticText1 = new wxStaticText( m_options_sizer->GetStaticBox(), wxID_ANY, _("Option Specific Help:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText1->Wrap( -1 ); - m_options_sizer->Add( m_staticText1, 0, wxLEFT|wxRIGHT|wxTOP, 5 ); + + m_options_sizer->Add( 0, 0, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 ); m_html = new wxHtmlWindow( m_options_sizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO|wxVSCROLL ); - m_html->SetMinSize( wxSize( 300,300 ) ); + m_html->SetMinSize( wxSize( 280,100 ) ); - m_options_sizer->Add( m_html, 3, wxALL|wxEXPAND, 5 ); + m_options_sizer->Add( m_html, 2, wxALL|wxEXPAND, 5 ); - m_horizontal_sizer->Add( m_options_sizer, 2, wxEXPAND, 5 ); + m_horizontal_sizer->Add( m_options_sizer, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); - bSizer4->Add( m_horizontal_sizer, 1, wxALL|wxEXPAND, 5 ); + bMainSizer->Add( m_horizontal_sizer, 1, wxALL|wxEXPAND, 5 ); m_sdbSizer1 = new wxStdDialogButtonSizer(); m_sdbSizer1OK = new wxButton( this, wxID_OK ); @@ -120,40 +100,34 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent, m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); m_sdbSizer1->Realize(); - bSizer4->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 ); + bMainSizer->Add( m_sdbSizer1, 0, wxEXPAND, 5 ); - this->SetSizer( bSizer4 ); + this->SetSizer( bMainSizer ); this->Layout(); - bSizer4->Fit( this ); + bMainSizer->Fit( this ); this->Centre( wxBOTH ); // Connect Events - this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelCaptionButtonClick ) ); - m_add_row->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this ); - m_delete_row->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this ); - m_move_up->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveUp ), NULL, this ); - m_move_down->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveDown ), NULL, this ); + m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onSize ), NULL, this ); + m_grid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onUpdateUI ), NULL, this ); + m_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this ); + m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this ); m_listbox->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemSelected ), NULL, this ); m_listbox->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemDoubleClicked ), NULL, this ); m_append_choice_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this ); - m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelButtonClick ), NULL, this ); - m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onOKButtonClick ), NULL, this ); } DIALOG_FP_PLUGIN_OPTIONS_BASE::~DIALOG_FP_PLUGIN_OPTIONS_BASE() { // Disconnect Events - this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelCaptionButtonClick ) ); - m_add_row->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this ); - m_delete_row->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this ); - m_move_up->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveUp ), NULL, this ); - m_move_down->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveDown ), NULL, this ); + m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onSize ), NULL, this ); + m_grid->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onUpdateUI ), NULL, this ); + m_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this ); + m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this ); m_listbox->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemSelected ), NULL, this ); m_listbox->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onListBoxItemDoubleClicked ), NULL, this ); m_append_choice_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this ); - m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelButtonClick ), NULL, this ); - m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onOKButtonClick ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_fp_plugin_options_base.fbp b/pcbnew/dialogs/dialog_fp_plugin_options_base.fbp index d98bc91198..d43b1889de 100644 --- a/pcbnew/dialogs/dialog_fp_plugin_options_base.fbp +++ b/pcbnew/dialogs/dialog_fp_plugin_options_base.fbp @@ -61,7 +61,7 @@ - onCancelCaptionButtonClick + @@ -88,28 +88,28 @@ - + - bSizer4 + bMainSizer wxVERTICAL none - + 5 wxALL|wxEXPAND 1 - + m_horizontal_sizer wxHORIZONTAL none - + 5 - wxEXPAND + wxEXPAND|wxTOP|wxRIGHT|wxLEFT 3 - + wxID_ANY - Plugin Options: - -1,300 + Plugin Options + 400,300 m_grid_sizer wxVERTICAL 1 @@ -117,7 +117,7 @@ 5 - wxEXPAND|wxTOP + wxEXPAND|wxTOP|wxRIGHT|wxLEFT 1 1 @@ -142,11 +142,11 @@ 0 1 wxALIGN_CENTRE - 30 + 22 "Option" "Value" wxALIGN_CENTRE 2 - + 120,240 1 0 @@ -188,7 +188,7 @@ Resizable wxALIGN_CENTRE - 40 + 0 wxALIGN_CENTRE @@ -254,24 +254,24 @@ - - + onSize + onUpdateUI - + 5 - wxALIGN_CENTER + wxEXPAND|wxTOP 0 - + - m_button_sizer + bButtonsSizer wxHORIZONTAL none - + 5 - wxALL + wxLEFT 0 - + 1 1 1 @@ -282,6 +282,7 @@ + 1 0 @@ -290,17 +291,20 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY - Append + Add Library 0 @@ -308,7 +312,7 @@ 0 1 - m_add_row + m_append_button 1 @@ -316,12 +320,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Append a blank row + wxFILTER_NONE wxDefaultValidator @@ -329,7 +334,7 @@ - + onAppendRow @@ -338,7 +343,7 @@ - onAppendRow + @@ -355,11 +360,11 @@ - + 5 - wxALL + wxRIGHT 0 - + 1 1 1 @@ -370,6 +375,7 @@ + 1 0 @@ -378,17 +384,20 @@ 1 0 0 + Dock 0 Left 1 1 + 0 0 + wxID_ANY - Delete + Remove Library 0 @@ -396,7 +405,7 @@ 0 1 - m_delete_row + m_delete_button 1 @@ -404,12 +413,13 @@ 1 Resizable + 1 - - - + 30,30 + wxBU_AUTODRAW + ; forward_declare 0 - Delete the selected row + wxFILTER_NONE wxDefaultValidator @@ -417,7 +427,7 @@ - + onDeleteRow @@ -426,183 +436,7 @@ - onDeleteRow - - - - - - - - - - - - - - - - - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Move Up - - 0 - - - 0 - - 1 - m_move_up - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - Move the selected row up one position - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - onMoveUp - - - - - - - - - - - - - - - - - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Move Down - - 0 - - - 0 - - 1 - m_move_down - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - Move the selected row down one position - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - onMoveDown + @@ -623,28 +457,14 @@ - + 5 - wxEXPAND + wxEXPAND|wxTOP|wxRIGHT|wxLEFT 0 - - 1 - 0 - -1,-1 - m_choose_size - none - 1 - 0 - - - - 5 - wxEXPAND - 2 - + wxID_ANY - Option Choices: - 200,-1 + Option Choices + -1,-1 m_options_sizer wxVERTICAL 1 @@ -653,7 +473,7 @@ 5 wxALL|wxEXPAND - 2 + 3 1 1 @@ -826,93 +646,20 @@ - + 5 - wxLEFT|wxRIGHT|wxTOP + wxEXPAND|wxTOP|wxBOTTOM 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Option Specific Help: - - 0 - - - 0 - - 1 - m_staticText1 - 1 - - + + 0 protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - + 0 5 wxALL|wxEXPAND - 3 + 2 1 1 @@ -946,7 +693,7 @@ -1,-1 300,300 0 - 300,300 + 280,100 1 m_html 1 @@ -999,7 +746,7 @@ 5 - wxALL|wxEXPAND + wxEXPAND 0 0 @@ -1014,11 +761,11 @@ m_sdbSizer1 protected - onCancelButtonClick + - onOKButtonClick + diff --git a/pcbnew/dialogs/dialog_fp_plugin_options_base.h b/pcbnew/dialogs/dialog_fp_plugin_options_base.h index 3fd7431259..4002dca0b5 100644 --- a/pcbnew/dialogs/dialog_fp_plugin_options_base.h +++ b/pcbnew/dialogs/dialog_fp_plugin_options_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Nov 22 2017) +// C++ code generated with wxFormBuilder (version Dec 30 2017) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -18,11 +18,14 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include -#include #include #include @@ -38,29 +41,23 @@ class DIALOG_FP_PLUGIN_OPTIONS_BASE : public DIALOG_SHIM protected: wxGrid* m_grid; - wxButton* m_add_row; - wxButton* m_delete_row; - wxButton* m_move_up; - wxButton* m_move_down; + wxBitmapButton* m_append_button; + wxBitmapButton* m_delete_button; wxListBox* m_listbox; wxButton* m_append_choice_button; - wxStaticText* m_staticText1; wxHtmlWindow* m_html; wxStdDialogButtonSizer* m_sdbSizer1; wxButton* m_sdbSizer1OK; wxButton* m_sdbSizer1Cancel; // Virtual event handlers, overide them in your derived class - virtual void onCancelCaptionButtonClick( wxCloseEvent& event ) = 0; - virtual void onAppendRow( wxMouseEvent& event ) = 0; - virtual void onDeleteRow( wxMouseEvent& event ) = 0; - virtual void onMoveUp( wxMouseEvent& event ) = 0; - virtual void onMoveDown( wxMouseEvent& event ) = 0; + virtual void onSize( wxSizeEvent& event ) = 0; + virtual void onUpdateUI( wxUpdateUIEvent& event ) = 0; + virtual void onAppendRow( wxCommandEvent& event ) = 0; + virtual void onDeleteRow( wxCommandEvent& event ) = 0; virtual void onListBoxItemSelected( wxCommandEvent& event ) = 0; virtual void onListBoxItemDoubleClicked( wxCommandEvent& event ) = 0; virtual void onAppendOption( wxCommandEvent& event ) = 0; - virtual void onCancelButtonClick( wxCommandEvent& event ) = 0; - virtual void onOKButtonClick( wxCommandEvent& event ) = 0; public: diff --git a/pcbnew/invoke_pcb_dialog.h b/pcbnew/invoke_pcb_dialog.h index eee77eb652..c27904dcdd 100644 --- a/pcbnew/invoke_pcb_dialog.h +++ b/pcbnew/invoke_pcb_dialog.h @@ -95,7 +95,7 @@ void Invoke3DShapeLibsDownloaderWizard( wxTopLevelWindow* aCaller ); * @param aOptions is the options string on calling into this function. * @param aResult is where to put the result of the editing. */ -void InvokePluginOptionsEditor( wxTopLevelWindow* aCaller, const wxString& aNickname, +void InvokePluginOptionsEditor( wxWindow* aCaller, const wxString& aNickname, const wxString& aPluginType, const wxString& aOptions, wxString* aResult ); /**