diff --git a/common/dialogs/panel_design_block_lib_table.cpp b/common/dialogs/panel_design_block_lib_table.cpp index be85e42c1e..5157472358 100644 --- a/common/dialogs/panel_design_block_lib_table.cpp +++ b/common/dialogs/panel_design_block_lib_table.cpp @@ -235,84 +235,94 @@ protected: }; +void PANEL_DESIGN_BLOCK_LIB_TABLE::addTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aGlobal ) +{ + DESIGN_BLOCK_LIBRARY_ADAPTER* adapter = m_project->DesignBlockLibs(); + + LIB_TABLE_GRID_TRICKS::AddTable( m_notebook, aTitle ); + + WX_GRID* grid = get_grid( (int) m_notebook->GetPageCount() - 1 ); + + if( aGlobal ) + { + wxString* lastGlobalLibDir = nullptr; + + if( KICAD_SETTINGS* cfg = GetAppSettings( "kicad" ) ) + { + if( cfg->m_lastDesignBlockLibDir.IsEmpty() ) + cfg->m_lastDesignBlockLibDir = PATHS::GetDefaultUserDesignBlocksPath(); + + lastGlobalLibDir = &cfg->m_lastDesignBlockLibDir; + } + + grid->SetTable( new DESIGN_BLOCK_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *table, adapter, m_pluginChoices, + lastGlobalLibDir, wxEmptyString, + m_supportedDesignBlockFiles ), + true /* take ownership */ ); + } + else + { + grid->SetTable( new DESIGN_BLOCK_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *table, adapter, m_pluginChoices, + &m_lastProjectLibDir, m_project->GetProjectPath(), + m_supportedDesignBlockFiles ), + true /* take ownership */ ); + } + + // add Cut, Copy, and Paste to wxGrids + grid->PushEventHandler( new DESIGN_BLOCK_GRID_TRICKS( m_parent, grid ) ); + + auto autoSizeCol = + [&]( int aCol ) + { + int prevWidth = grid->GetColSize( aCol ); + + grid->AutoSizeColumn( aCol, false ); + grid->SetColSize( aCol, std::max( prevWidth, grid->GetColSize( aCol ) ) ); + }; + + // all but COL_OPTIONS, which is edited with Option Editor anyways. + autoSizeCol( COL_NICKNAME ); + autoSizeCol( COL_TYPE ); + autoSizeCol( COL_URI ); + autoSizeCol( COL_DESCR ); + + if( grid->GetNumberRows() > 0 ) + { + grid->SetGridCursor( 0, COL_NICKNAME ); + grid->SelectRow( 0 ); + } +} + + PANEL_DESIGN_BLOCK_LIB_TABLE::PANEL_DESIGN_BLOCK_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PROJECT* aProject ) : PANEL_DESIGN_BLOCK_LIB_TABLE_BASE( aParent ), m_project( aProject ), m_parent( aParent ) { - wxString* lastGlobalLibDir = nullptr; - - if( KICAD_SETTINGS* cfg = GetAppSettings( "kicad" ) ) - { - if( cfg->m_lastDesignBlockLibDir.IsEmpty() ) - cfg->m_lastDesignBlockLibDir = PATHS::GetDefaultUserDesignBlocksPath(); - - lastGlobalLibDir = &cfg->m_lastDesignBlockLibDir; - } - m_lastProjectLibDir = m_project->GetProjectPath(); populatePluginList(); - wxArrayString pluginChoices; - for( auto& [fileType, desc] : m_supportedDesignBlockFiles ) - pluginChoices.Add( DESIGN_BLOCK_IO_MGR::ShowType( fileType ) ); + m_pluginChoices.Add( DESIGN_BLOCK_IO_MGR::ShowType( fileType ) ); std::optional table = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::DESIGN_BLOCK, LIBRARY_TABLE_SCOPE::GLOBAL ); - wxASSERT( table ); + wxASSERT( table.has_value() ); - DESIGN_BLOCK_LIBRARY_ADAPTER* adapter = m_project->DesignBlockLibs(); - - m_global_grid->SetTable( new DESIGN_BLOCK_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_global_grid, *table.value(), - adapter, pluginChoices, lastGlobalLibDir, - wxEmptyString, m_supportedDesignBlockFiles ), - true /* take ownership */ ); - - // add Cut, Copy, and Paste to wxGrids - m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) ); - - // There aren't (yet) any legacy DesignBlock libraries to migrate - m_migrate_libs_button->Hide(); - - auto setupGrid = - [&]( WX_GRID* aGrid ) - { - // add Cut, Copy, and Paste to wxGrids - aGrid->PushEventHandler( new DESIGN_BLOCK_GRID_TRICKS( m_parent, aGrid ) ); - - aGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); - - // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with - // a currentCell which is sometimes not highlighted. - if( aGrid->GetNumberRows() > 0 ) - aGrid->SelectRow( 0 ); - }; - - setupGrid( m_global_grid ); - - populateEnvironReadOnlyTable(); + addTable( table.value(), _( "Global Libraries" ), true ); std::optional projectTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::DESIGN_BLOCK, LIBRARY_TABLE_SCOPE::PROJECT ); - if( projectTable ) - { - m_project_grid->SetTable( new DESIGN_BLOCK_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_project_grid, - *projectTable.value(), adapter, - pluginChoices, &m_lastProjectLibDir, - m_project->GetProjectPath(), - m_supportedDesignBlockFiles ), - true /* take ownership */ ); - setupGrid( m_project_grid ); - } - else - { - m_notebook->DeletePage( 1 ); - m_project_grid = nullptr; - } + if( projectTable.has_value() ) + addTable( projectTable.value(), _( "Project Specific Libraries" ), false ); + + // There aren't (yet) any legacy DesignBlock libraries to migrate + m_migrate_libs_button->Hide(); + + populateEnvironReadOnlyTable(); m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) ); m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) ); @@ -587,10 +597,10 @@ void PANEL_DESIGN_BLOCK_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event wxString dummy; wxString* lastDir; - if( cur_grid() == m_project_grid ) - lastDir = &m_lastProjectLibDir; - else + if( m_notebook->GetSelection() == 0 ) lastDir = cfg ? &cfg->m_lastDesignBlockLibDir : &dummy; + else + lastDir = &m_lastProjectLibDir; wxArrayString files; wxWindow* topLevelParent = wxGetTopLevelParent( this ); @@ -648,8 +658,7 @@ void PANEL_DESIGN_BLOCK_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event if( !applyToAll ) { // The cancel button adds the library to the table anyway - addDuplicates = OKOrCancelDialog( wxGetTopLevelParent( this ), warning, - wxString::Format( msg, nickname ), detailedMsg, + addDuplicates = OKOrCancelDialog( m_parent, warning, wxString::Format( msg, nickname ), detailedMsg, _( "Skip" ), _( "Add Anyway" ), &applyToAll ) == wxID_CANCEL; } diff --git a/common/dialogs/panel_design_block_lib_table.h b/common/dialogs/panel_design_block_lib_table.h index 5a7ce801f7..bdf4fa2445 100644 --- a/common/dialogs/panel_design_block_lib_table.h +++ b/common/dialogs/panel_design_block_lib_table.h @@ -24,6 +24,8 @@ #include #include + +class LIBRARY_TABLE; class DESIGN_BLOCK_LIB_TABLE; class DESIGN_BLOCK_LIB_TABLE_GRID_DATA_MODEL; class PROJECT; @@ -58,6 +60,8 @@ private: void onPageChange( wxBookCtrlEvent& event ) override; + void addTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aGlobal ); + void adjustPathSubsGridColumns( int aWidth ); /// Populate the readonly environment variable table with names and values @@ -74,6 +78,7 @@ private: private: PROJECT* m_project; DIALOG_EDIT_LIBRARY_TABLES* m_parent; + wxArrayString m_pluginChoices; wxString m_lastProjectLibDir; //< Transient (unsaved) last browsed folder when adding a // project level library. diff --git a/common/dialogs/panel_design_block_lib_table_base.cpp b/common/dialogs/panel_design_block_lib_table_base.cpp index 2c422b310c..f5f0b04a3d 100644 --- a/common/dialogs/panel_design_block_lib_table_base.cpp +++ b/common/dialogs/panel_design_block_lib_table_base.cpp @@ -5,7 +5,6 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#include "widgets/panel_notebook_base.h" #include "widgets/std_bitmap_button.h" #include "widgets/wx_grid.h" @@ -19,104 +18,6 @@ PANEL_DESIGN_BLOCK_LIB_TABLE_BASE::PANEL_DESIGN_BLOCK_LIB_TABLE_BASE( wxWindow* bMainSizer = new wxBoxSizer( wxVERTICAL ); m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - m_global_panel = new PANEL_NOTEBOOK_BASE( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* m_global_sizer; - m_global_sizer = new wxBoxSizer( wxVERTICAL ); - - m_global_grid = new WX_GRID( m_global_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - // Grid - m_global_grid->CreateGrid( 1, 7 ); - m_global_grid->EnableEditing( true ); - m_global_grid->EnableGridLines( true ); - m_global_grid->EnableDragGridSize( false ); - m_global_grid->SetMargins( 0, 0 ); - - // Columns - m_global_grid->SetColSize( 0, 48 ); - m_global_grid->SetColSize( 1, 48 ); - m_global_grid->SetColSize( 2, 100 ); - m_global_grid->SetColSize( 3, 240 ); - m_global_grid->SetColSize( 4, 100 ); - m_global_grid->SetColSize( 5, 80 ); - m_global_grid->SetColSize( 6, 240 ); - m_global_grid->EnableDragColMove( false ); - m_global_grid->EnableDragColSize( true ); - m_global_grid->SetColLabelValue( 0, _("Active") ); - m_global_grid->SetColLabelValue( 1, _("Visible") ); - m_global_grid->SetColLabelValue( 2, _("Nickname") ); - m_global_grid->SetColLabelValue( 3, _("Library Path") ); - m_global_grid->SetColLabelValue( 4, _("Library Format") ); - m_global_grid->SetColLabelValue( 5, _("Options") ); - m_global_grid->SetColLabelValue( 6, _("Description") ); - m_global_grid->SetColLabelSize( 22 ); - m_global_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Rows - m_global_grid->EnableDragRowSize( false ); - m_global_grid->SetRowLabelSize( 0 ); - m_global_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_global_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); - m_global_sizer->Add( m_global_grid, 1, wxALL|wxEXPAND, 5 ); - - - m_global_panel->SetSizer( m_global_sizer ); - m_global_panel->Layout(); - m_global_sizer->Fit( m_global_panel ); - m_notebook->AddPage( m_global_panel, _("Global Libraries"), true ); - m_project_panel = new PANEL_NOTEBOOK_BASE( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* m_project_sizer; - m_project_sizer = new wxBoxSizer( wxVERTICAL ); - - m_project_grid = new WX_GRID( m_project_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - // Grid - m_project_grid->CreateGrid( 1, 7 ); - m_project_grid->EnableEditing( true ); - m_project_grid->EnableGridLines( true ); - m_project_grid->EnableDragGridSize( false ); - m_project_grid->SetMargins( 0, 0 ); - - // Columns - m_project_grid->SetColSize( 0, 48 ); - m_project_grid->SetColSize( 1, 48 ); - m_project_grid->SetColSize( 2, 100 ); - m_project_grid->SetColSize( 3, 240 ); - m_project_grid->SetColSize( 4, 100 ); - m_project_grid->SetColSize( 5, 80 ); - m_project_grid->SetColSize( 6, 240 ); - m_project_grid->EnableDragColMove( false ); - m_project_grid->EnableDragColSize( true ); - m_project_grid->SetColLabelValue( 0, _("Active") ); - m_project_grid->SetColLabelValue( 1, _("Visible") ); - m_project_grid->SetColLabelValue( 2, _("Nickname") ); - m_project_grid->SetColLabelValue( 3, _("Library Path") ); - m_project_grid->SetColLabelValue( 4, _("Library Format") ); - m_project_grid->SetColLabelValue( 5, _("Options") ); - m_project_grid->SetColLabelValue( 6, _("Description") ); - m_project_grid->SetColLabelSize( 22 ); - m_project_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Rows - m_project_grid->EnableDragRowSize( false ); - m_project_grid->SetRowLabelSize( 0 ); - m_project_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_project_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); - m_project_sizer->Add( m_project_grid, 1, wxALL|wxEXPAND, 5 ); - - - m_project_panel->SetSizer( m_project_sizer ); - m_project_panel->Layout(); - m_project_sizer->Fit( m_project_panel ); - m_notebook->AddPage( m_project_panel, _("Project Specific Libraries"), false ); bMainSizer->Add( m_notebook, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); diff --git a/common/dialogs/panel_design_block_lib_table_base.fbp b/common/dialogs/panel_design_block_lib_table_base.fbp index 8e2aa60a99..62ab85181b 100644 --- a/common/dialogs/panel_design_block_lib_table_base.fbp +++ b/common/dialogs/panel_design_block_lib_table_base.fbp @@ -119,312 +119,6 @@ onPageChange - - - Global Libraries - 1 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 0 - - 0 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_global_panel - 1 - - - protected - 0 - - Resizable - 1 - - PANEL_NOTEBOOK_BASE; widgets/panel_notebook_base.h; forward_declare - 0 - - - - wxTAB_TRAVERSAL - - - m_global_sizer - wxVERTICAL - none - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - 0 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_CENTER - 0 - 1 - wxALIGN_CENTER - 22 - "Active" "Visible" "Nickname" "Library Path" "Library Format" "Options" "Description" - wxALIGN_CENTER - 7 - 48,48,100,240,100,80,240 - - 1 - 0 - Dock - 1 - Left - 0 - 0 - 1 - 0 - 0 - 1 - 1 - - 0 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - - 0 - m_global_grid - 1 - - - protected - 1 - - Fixed - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 1 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - - - - - - - - Project Specific Libraries - 0 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 1 - - 0 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_project_panel - 1 - - - protected - 1 - - Resizable - 1 - - PANEL_NOTEBOOK_BASE; widgets/panel_notebook_base.h; forward_declare - 0 - - - - wxTAB_TRAVERSAL - - - m_project_sizer - wxVERTICAL - none - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - 0 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_CENTER - 0 - 1 - wxALIGN_CENTER - 22 - "Active" "Visible" "Nickname" "Library Path" "Library Format" "Options" "Description" - wxALIGN_CENTER - 7 - 48,48,100,240,100,80,240 - - 1 - 0 - Dock - 1 - Left - 0 - 0 - 1 - 0 - 0 - 1 - 1 - - 0 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - - 0 - m_project_grid - 1 - - - protected - 1 - - Fixed - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 1 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - - - - - diff --git a/common/dialogs/panel_design_block_lib_table_base.h b/common/dialogs/panel_design_block_lib_table_base.h index 2de42d4901..85438135f9 100644 --- a/common/dialogs/panel_design_block_lib_table_base.h +++ b/common/dialogs/panel_design_block_lib_table_base.h @@ -10,26 +10,25 @@ #include #include #include -class PANEL_NOTEBOOK_BASE; class STD_BITMAP_BUTTON; class WX_GRID; +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include +#include #include #include #include -#include -#include #include #include +#include #include +#include +#include /////////////////////////////////////////////////////////////////////////// @@ -42,10 +41,6 @@ class PANEL_DESIGN_BLOCK_LIB_TABLE_BASE : public wxPanel protected: wxNotebook* m_notebook; - PANEL_NOTEBOOK_BASE* m_global_panel; - WX_GRID* m_global_grid; - PANEL_NOTEBOOK_BASE* m_project_panel; - WX_GRID* m_project_grid; STD_BITMAP_BUTTON* m_append_button; SPLIT_BUTTON* m_browseButton; STD_BITMAP_BUTTON* m_move_up_button; diff --git a/common/lib_table_grid_tricks.cpp b/common/lib_table_grid_tricks.cpp index 6ba8f93dfd..3cd0799f2c 100644 --- a/common/lib_table_grid_tricks.cpp +++ b/common/lib_table_grid_tricks.cpp @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include @@ -39,29 +42,6 @@ LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid, std::function aAddHandler ) : GRID_TRICKS( aGrid, aAddHandler ) { - auto autoSizeCol = - [&]( WX_GRID* aLocGrid, int aCol ) - { - int prevWidth = aLocGrid->GetColSize( aCol ); - - aLocGrid->AutoSizeColumn( aCol, false ); - aLocGrid->SetColSize( aCol, std::max( prevWidth, aLocGrid->GetColSize( aCol ) ) ); - }; - - aGrid->DisableColResize( COL_STATUS ); - aGrid->DisableColResize( COL_VISIBLE ); - aGrid->DisableColResize( COL_ENABLED ); - - aGrid->AutoSizeColumn( COL_STATUS, true ); - aGrid->AutoSizeColumn( COL_VISIBLE, true ); - aGrid->AutoSizeColumn( COL_ENABLED, true ); - - // all but COL_OPTIONS, which is edited with Option Editor anyways. - autoSizeCol( aGrid, COL_NICKNAME ); - autoSizeCol( aGrid, COL_TYPE ); - autoSizeCol( aGrid, COL_URI ); - autoSizeCol( aGrid, COL_DESCR ); - m_grid->Disconnect( wxEVT_CHAR_HOOK ); m_grid->Connect( wxEVT_CHAR_HOOK, wxCharEventHandler( LIB_TABLE_GRID_TRICKS::onCharHook ), nullptr, this ); } @@ -568,3 +548,51 @@ bool LIB_TABLE_GRID_TRICKS::VerifyTable( WX_GRID* aGrid, std::functionCreateGrid( 1, 7 ); + grid->EnableGridLines( true ); + grid->SetMargins( 0, 0 ); + grid->SetSelectionMode( wxGrid::wxGridSelectRows ); + + // Columns + grid->SetColSize( 0, 30 ); + grid->SetColSize( 1, 48 ); + grid->SetColSize( 2, 48 ); + grid->SetColSize( 3, 240 ); + grid->SetColSize( 4, 100 ); + grid->SetColSize( 5, 80 ); + grid->SetColSize( 6, 240 ); + grid->SetColLabelSize( 22 ); + grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Rows + grid->EnableDragRowSize( false ); + grid->SetRowLabelSize( 0 ); + grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Cell Defaults + grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); + + grid->DisableColResize( COL_STATUS ); + grid->DisableColResize( COL_VISIBLE ); + grid->DisableColResize( COL_ENABLED ); + + grid->AutoSizeColumn( COL_VISIBLE, true ); + grid->AutoSizeColumn( COL_ENABLED, true ); + + sizer->Add( grid, 1, wxALL|wxEXPAND, 5 ); + + panel->SetSizer( sizer ); + panel->Layout(); + sizer->Fit( panel ); + + aNotebook->AddPage( panel, aTitle, true ); +} \ No newline at end of file diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index da4ad0bc68..575b4afc04 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -189,22 +189,65 @@ protected: }; -void PANEL_SYM_LIB_TABLE::setupGrid( WX_GRID* aGrid ) +void PANEL_SYM_LIB_TABLE::addTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aGlobal ) { + SYMBOL_LIBRARY_ADAPTER* adapter = PROJECT_SCH::SymbolLibAdapter( m_project ); + + LIB_TABLE_GRID_TRICKS::AddTable( m_notebook, aTitle ); + + WX_GRID* grid = get_grid( (int) m_notebook->GetPageCount() - 1 ); + + if( aGlobal ) + { + wxString* lastGlobalLibDir = nullptr; + + if( EESCHEMA_SETTINGS* cfg = GetAppSettings( "eeschema" ) ) + { + if( cfg->m_lastSymbolLibDir.IsEmpty() ) + cfg->m_lastSymbolLibDir = PATHS::GetDefaultUserSymbolsPath(); + + lastGlobalLibDir = &cfg->m_lastSymbolLibDir; + } + + grid->SetTable( new SYMBOL_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *table, adapter, m_pluginChoices, + lastGlobalLibDir, wxEmptyString ), + true /* take ownership */ ); + } + else + { + grid->SetTable( new SYMBOL_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *table, adapter, m_pluginChoices, + &m_lastProjectLibDir, m_project->GetProjectPath() ), + true /* take ownership */ ); + } + // add Cut, Copy, and Paste to wxGrids - aGrid->PushEventHandler( new SYMBOL_GRID_TRICKS( aGrid, + grid->PushEventHandler( new SYMBOL_GRID_TRICKS( grid, [this]( wxCommandEvent& event ) { appendRowHandler( event ); } ) ); - aGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); + auto autoSizeCol = + [&]( int aCol ) + { + int prevWidth = grid->GetColSize( aCol ); - // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with - // a currentCell which is sometimes not highlighted. - if( aGrid->GetNumberRows() > 0 ) - aGrid->SelectRow( 0 ); -}; + grid->AutoSizeColumn( aCol, false ); + grid->SetColSize( aCol, std::max( prevWidth, grid->GetColSize( aCol ) ) ); + }; + + // all but COL_OPTIONS, which is edited with Option Editor anyways. + autoSizeCol( COL_NICKNAME ); + autoSizeCol( COL_TYPE ); + autoSizeCol( COL_URI ); + autoSizeCol( COL_DESCR ); + + if( grid->GetNumberRows() > 0 ) + { + grid->SetGridCursor( 0, COL_NICKNAME ); + grid->SelectRow( 0 ); + } +} PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PROJECT* aProject ) : @@ -212,22 +255,8 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P m_project( aProject ), m_parent( aParent ) { - wxString* lastGlobalLibDir = nullptr; - - if( EESCHEMA_SETTINGS* cfg = GetAppSettings( "eeschema" ) ) - { - if( cfg->m_lastSymbolLibDir.IsEmpty() ) - cfg->m_lastSymbolLibDir = PATHS::GetDefaultUserSymbolsPath(); - - lastGlobalLibDir = &cfg->m_lastSymbolLibDir; - } - m_lastProjectLibDir = m_project->GetProjectPath(); - // TODO(JE) should use translated string here but type is stored as untranslated string - // Maybe type storage needs to be enum? - m_pluginChoices.Add( wxT( "Table" ) ); - for( const SCH_IO_MGR::SCH_FILE_T& type : SCH_IO_MGR::SCH_FILE_T_vector ) { IO_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) ); @@ -241,32 +270,15 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P std::optional table = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, LIBRARY_TABLE_SCOPE::GLOBAL ); - wxASSERT( table ); + wxASSERT( table.has_value() ); - SYMBOL_LIBRARY_ADAPTER* adapter = PROJECT_SCH::SymbolLibAdapter( m_project ); - - // 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 SYMBOL_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_global_grid, *table.value(), adapter, - m_pluginChoices, lastGlobalLibDir, wxEmptyString ) ); - - setupGrid( m_global_grid ); + addTable( table.value(), _( "Global Libraries" ), true ); std::optional projectTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, LIBRARY_TABLE_SCOPE::PROJECT ); - if( projectTable ) - { - m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_project_grid, *projectTable.value(), - adapter, m_pluginChoices, &m_lastProjectLibDir, - m_project->GetProjectPath() ), true ); - setupGrid( m_project_grid ); - } - else - { - m_notebook->DeletePage( 1 ); - m_project_grid = nullptr; - } + if( projectTable.has_value() ) + addTable( projectTable.value(), _( "Project Specific Libraries" ), false ); // add Cut, Copy, and Paste to wxGrids m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) ); @@ -382,10 +394,10 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) wxString dummy; wxString* lastDir; - if( cur_grid() == m_project_grid ) - lastDir = &m_lastProjectLibDir; - else + if( m_notebook->GetSelection() == 0 ) lastDir = cfg ? &cfg->m_lastSymbolLibDir : &dummy; + else + lastDir = &m_lastProjectLibDir; wxWindow* topLevelParent = wxGetTopLevelParent( this ); @@ -487,10 +499,11 @@ void PANEL_SYM_LIB_TABLE::onReset( wxCommandEvent& event ) if( !cur_grid()->CommitPendingChanges() ) return; + WX_GRID* grid = get_grid( 0 ); + // No need to prompt to preserve an empty table - if( m_global_grid->GetNumberRows() > 0 && - !IsOK( this, wxString::Format( _( "This action will reset your global library table on " - "disk and cannot be undone." ) ) ) ) + if( grid->GetNumberRows() > 0 && !IsOK( this, wxString::Format( _( "This action will reset your global library " + "table on disk and cannot be undone." ) ) ) ) { return; } @@ -513,10 +526,10 @@ void PANEL_SYM_LIB_TABLE::onReset( wxCommandEvent& event ) if( KIFACE *schface = m_parent->Kiway().KiFACE( KIWAY::FACE_SCH ) ) schface->PreloadLibraries( &m_parent->Kiway() ); - m_global_grid->Freeze(); + grid->Freeze(); - wxGridTableBase* table = m_global_grid->GetTable(); - m_global_grid->DestroyTable( table ); + wxGridTableBase* table = grid->GetTable(); + grid->DestroyTable( table ); std::optional newTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, LIBRARY_TABLE_SCOPE::GLOBAL ); @@ -524,13 +537,19 @@ void PANEL_SYM_LIB_TABLE::onReset( wxCommandEvent& event ) SYMBOL_LIBRARY_ADAPTER* adapter = PROJECT_SCH::SymbolLibAdapter( &m_parent->Kiway().Prj() ); - m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_global_grid, *newTable.value(), adapter, - m_pluginChoices, lastGlobalLibDir, wxEmptyString ) ); - m_global_grid->PopEventHandler( true ); - setupGrid( m_global_grid ); + grid->SetTable( new SYMBOL_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *newTable.value(), adapter, m_pluginChoices, + lastGlobalLibDir, wxEmptyString ), + true /* take ownership */ ); + m_parent->m_GlobalTableChanged = true; - m_global_grid->Thaw(); + grid->Thaw(); + + if( grid->GetNumberRows() > 0 ) + { + grid->SetGridCursor( 0, COL_NICKNAME ); + grid->SelectRow( 0 ); + } } @@ -621,11 +640,6 @@ void PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries( wxCommandEvent& event ) { relPath = NormalizePath( newLib.GetFullPath(), &Pgm().GetLocalEnvVariables(), m_project ); - // Do not use the project path in the global library table. This will almost - // assuredly be wrong for a different project. - if( cur_grid() == m_global_grid && relPath.Contains( "${KIPRJMOD}" ) ) - relPath = newLib.GetFullPath(); - cur_grid()->SetCellValue( row, COL_URI, relPath ); cur_grid()->SetCellValue( row, COL_TYPE, kicadType ); cur_grid()->SetCellValue( row, COL_OPTIONS, wxEmptyString ); @@ -647,8 +661,8 @@ bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow() if( !verifyTables() ) return false; - std::optional optTable = - Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, LIBRARY_TABLE_SCOPE::GLOBAL ); + std::optional optTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, + LIBRARY_TABLE_SCOPE::GLOBAL ); wxCHECK( optTable, false ); LIBRARY_TABLE* globalTable = *optTable; @@ -658,8 +672,7 @@ bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow() *globalTable = get_model( 0 )->Table(); } - optTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, - LIBRARY_TABLE_SCOPE::PROJECT ); + optTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, LIBRARY_TABLE_SCOPE::PROJECT ); if( optTable && m_notebook->GetPageCount() > 1 && !static_cast( m_notebook->GetPage( 1 ) )->GetClosable() ) diff --git a/eeschema/dialogs/panel_sym_lib_table.h b/eeschema/dialogs/panel_sym_lib_table.h index 4ef957c48e..41ba6c33d1 100644 --- a/eeschema/dialogs/panel_sym_lib_table.h +++ b/eeschema/dialogs/panel_sym_lib_table.h @@ -25,6 +25,8 @@ #include #include + +class LIBRARY_TABLE; class SYMBOL_LIB_TABLE_GRID_DATA_MODEL; /** @@ -60,7 +62,7 @@ private: void onPageChange( wxBookCtrlEvent& event ) override; void onReset( wxCommandEvent& event ) override; - void setupGrid( WX_GRID* aGrid ); + void addTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aGlobal ); /// Populate the readonly environment variable table with names and values /// by examining all the full_uri columns. diff --git a/eeschema/dialogs/panel_sym_lib_table_base.cpp b/eeschema/dialogs/panel_sym_lib_table_base.cpp index 64a53d8d05..4e8189b808 100644 --- a/eeschema/dialogs/panel_sym_lib_table_base.cpp +++ b/eeschema/dialogs/panel_sym_lib_table_base.cpp @@ -5,7 +5,6 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#include "widgets/panel_notebook_base.h" #include "widgets/std_bitmap_button.h" #include "widgets/wx_grid.h" @@ -19,107 +18,6 @@ PANEL_SYM_LIB_TABLE_BASE::PANEL_SYM_LIB_TABLE_BASE( wxWindow* parent, wxWindowID bMainSizer = new wxBoxSizer( wxVERTICAL ); m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - m_global_panel = new PANEL_NOTEBOOK_BASE( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* m_global_sizer; - m_global_sizer = new wxBoxSizer( wxVERTICAL ); - - m_global_grid = new WX_GRID( m_global_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - // Grid - m_global_grid->CreateGrid( 1, 7 ); - m_global_grid->EnableEditing( true ); - m_global_grid->EnableGridLines( true ); - m_global_grid->EnableDragGridSize( false ); - m_global_grid->SetMargins( 0, 0 ); - - // Columns - m_global_grid->SetColSize( 0, 48 ); - m_global_grid->SetColSize( 1, 48 ); - m_global_grid->SetColSize( 2, 100 ); - m_global_grid->SetColSize( 3, 240 ); - m_global_grid->SetColSize( 4, 100 ); - m_global_grid->SetColSize( 5, 80 ); - m_global_grid->SetColSize( 6, 240 ); - m_global_grid->EnableDragColMove( false ); - m_global_grid->EnableDragColSize( true ); - m_global_grid->SetColLabelValue( 0, _("Active") ); - m_global_grid->SetColLabelValue( 1, _("Visible") ); - m_global_grid->SetColLabelValue( 2, _("Nickname") ); - m_global_grid->SetColLabelValue( 3, _("Library Path") ); - m_global_grid->SetColLabelValue( 4, _("Library Format") ); - m_global_grid->SetColLabelValue( 5, _("Options") ); - m_global_grid->SetColLabelValue( 6, _("Description") ); - m_global_grid->SetColLabelSize( 22 ); - m_global_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Rows - m_global_grid->AutoSizeRows(); - m_global_grid->EnableDragRowSize( false ); - m_global_grid->SetRowLabelSize( 0 ); - m_global_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_global_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); - m_global_sizer->Add( m_global_grid, 5, wxALL|wxEXPAND, 5 ); - - - m_global_panel->SetSizer( m_global_sizer ); - m_global_panel->Layout(); - m_global_sizer->Fit( m_global_panel ); - m_notebook->AddPage( m_global_panel, _("Global Libraries"), true ); - m_project_panel = new PANEL_NOTEBOOK_BASE( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* m_project_sizer; - m_project_sizer = new wxBoxSizer( wxVERTICAL ); - - m_project_grid = new WX_GRID( m_project_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - // Grid - m_project_grid->CreateGrid( 1, 7 ); - m_project_grid->EnableEditing( true ); - m_project_grid->EnableGridLines( true ); - m_project_grid->EnableDragGridSize( false ); - m_project_grid->SetMargins( 0, 0 ); - - // Columns - m_project_grid->SetColSize( 0, 48 ); - m_project_grid->SetColSize( 1, 48 ); - m_project_grid->SetColSize( 2, 100 ); - m_project_grid->SetColSize( 3, 240 ); - m_project_grid->SetColSize( 4, 100 ); - m_project_grid->SetColSize( 5, 80 ); - m_project_grid->SetColSize( 6, 240 ); - m_project_grid->EnableDragColMove( false ); - m_project_grid->EnableDragColSize( true ); - m_project_grid->SetColLabelValue( 0, _("Active") ); - m_project_grid->SetColLabelValue( 1, _("Visible") ); - m_project_grid->SetColLabelValue( 2, _("Nickname") ); - m_project_grid->SetColLabelValue( 3, _("Library Path") ); - m_project_grid->SetColLabelValue( 4, _("Library Format") ); - m_project_grid->SetColLabelValue( 5, _("Options") ); - m_project_grid->SetColLabelValue( 6, _("Description") ); - m_project_grid->SetColLabelSize( 22 ); - m_project_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Rows - m_project_grid->EnableDragRowSize( false ); - m_project_grid->SetRowLabelSize( 0 ); - m_project_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_project_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); - m_project_grid->SetMinSize( wxSize( 600,-1 ) ); - - m_project_sizer->Add( m_project_grid, 2, wxALL|wxEXPAND, 5 ); - - - m_project_panel->SetSizer( m_project_sizer ); - m_project_panel->Layout(); - m_project_sizer->Fit( m_project_panel ); - m_notebook->AddPage( m_project_panel, _("Project Specific Libraries"), false ); bMainSizer->Add( m_notebook, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); diff --git a/eeschema/dialogs/panel_sym_lib_table_base.fbp b/eeschema/dialogs/panel_sym_lib_table_base.fbp index 5915c740bd..68621fe33e 100644 --- a/eeschema/dialogs/panel_sym_lib_table_base.fbp +++ b/eeschema/dialogs/panel_sym_lib_table_base.fbp @@ -119,312 +119,6 @@ onPageChange - - - Global Libraries - 1 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 0 - - 0 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - -1,80 - 0 - - 1 - m_global_panel - 1 - - - protected - 0 - - Resizable - 1 - - PANEL_NOTEBOOK_BASE; widgets/panel_notebook_base.h; forward_declare - 0 - - - - wxTAB_TRAVERSAL - - - m_global_sizer - wxVERTICAL - none - - 5 - wxALL|wxEXPAND - 5 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - 0 - 1 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_CENTER - 0 - 1 - wxALIGN_CENTER - 22 - "Active" "Visible" "Nickname" "Library Path" "Library Format" "Options" "Description" - wxALIGN_CENTER - 7 - 48,48,100,240,100,80,240 - - 1 - 0 - Dock - 1 - Left - 0 - 0 - 1 - 0 - 0 - 1 - 1 - - 0 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - -1,-1 - 0 - m_global_grid - 1 - - - protected - 1 - - Fixed - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 1 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - - - - - - - - Project Specific Libraries - 0 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 1 - - 0 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_project_panel - 1 - - - protected - 1 - - Resizable - 1 - - PANEL_NOTEBOOK_BASE; widgets/panel_notebook_base.h; forward_declare - 0 - - - - wxTAB_TRAVERSAL - - - m_project_sizer - wxVERTICAL - none - - 5 - wxALL|wxEXPAND - 2 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - 0 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_CENTER - 0 - 1 - wxALIGN_CENTER - 22 - "Active" "Visible" "Nickname" "Library Path" "Library Format" "Options" "Description" - wxALIGN_CENTER - 7 - 48,48,100,240,100,80,240 - - 1 - 0 - Dock - 1 - Left - 0 - 0 - 1 - 0 - 0 - 1 - 1 - - 0 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - 600,-1 - 0 - m_project_grid - 1 - - - protected - 1 - - Fixed - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 1 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - - - - - diff --git a/eeschema/dialogs/panel_sym_lib_table_base.h b/eeschema/dialogs/panel_sym_lib_table_base.h index ec3f49ca6f..fb84e43b36 100644 --- a/eeschema/dialogs/panel_sym_lib_table_base.h +++ b/eeschema/dialogs/panel_sym_lib_table_base.h @@ -10,25 +10,24 @@ #include #include #include -class PANEL_NOTEBOOK_BASE; class STD_BITMAP_BUTTON; class WX_GRID; +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include +#include #include #include #include -#include -#include #include +#include #include +#include +#include /////////////////////////////////////////////////////////////////////////// @@ -41,10 +40,6 @@ class PANEL_SYM_LIB_TABLE_BASE : public wxPanel protected: wxNotebook* m_notebook; - PANEL_NOTEBOOK_BASE* m_global_panel; - WX_GRID* m_global_grid; - PANEL_NOTEBOOK_BASE* m_project_panel; - WX_GRID* m_project_grid; STD_BITMAP_BUTTON* m_append_button; STD_BITMAP_BUTTON* m_browse_button; STD_BITMAP_BUTTON* m_move_up_button; diff --git a/include/lib_table_grid_tricks.h b/include/lib_table_grid_tricks.h index 0f2b15ec68..462f5cec85 100644 --- a/include/lib_table_grid_tricks.h +++ b/include/lib_table_grid_tricks.h @@ -20,6 +20,8 @@ #include "grid_tricks.h" #include +class wxNotebook; + class LIB_TABLE_GRID_TRICKS : public GRID_TRICKS { enum @@ -50,6 +52,8 @@ public: static bool VerifyTable( WX_GRID* aGrid, std::function aErrorHandler ); + static void AddTable( wxNotebook* aNotebook, const wxString& aTitle ); + protected: virtual void optionsEditor( int aRow ) = 0; diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index 36f1d7b002..41302a46ff 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -164,22 +164,66 @@ protected: }; -void PANEL_FP_LIB_TABLE::setupGrid( WX_GRID* aGrid ) +void PANEL_FP_LIB_TABLE::addTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aGlobal ) { + FOOTPRINT_LIBRARY_ADAPTER* adapter = PROJECT_PCB::FootprintLibAdapter( m_project ); + + LIB_TABLE_GRID_TRICKS::AddTable( m_notebook, aTitle ); + + WX_GRID* grid = get_grid( (int) m_notebook->GetPageCount() - 1 ); + + if( aGlobal ) + { + wxString* lastGlobalLibDir = nullptr; + + if( PCBNEW_SETTINGS* cfg = GetAppSettings( "pcbnew" ) ) + { + if( cfg->m_LastFootprintLibDir.IsEmpty() ) + cfg->m_LastFootprintLibDir = PATHS::GetDefaultUserFootprintsPath(); + + lastGlobalLibDir = &cfg->m_LastFootprintLibDir; + } + + grid->SetTable( new FP_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *table, adapter, m_pluginChoices, + lastGlobalLibDir, wxEmptyString, m_supportedFpFiles ), + true /* take ownership */ ); + } + else + { + grid->SetTable( new FP_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *table, adapter, m_pluginChoices, + &m_lastProjectLibDir, m_project->GetProjectPath(), + m_supportedFpFiles ), + true /* take ownership */ ); + } + // add Cut, Copy, and Paste to wxGrids - aGrid->PushEventHandler( new FP_GRID_TRICKS( aGrid, + grid->PushEventHandler( new FP_GRID_TRICKS( grid, [this]( wxCommandEvent& event ) { appendRowHandler( event ); } ) ); - aGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); + auto autoSizeCol = + [&]( int aCol ) + { + int prevWidth = grid->GetColSize( aCol ); - // Gives a selection to each grid, mainly for delete button. wxGrid's wake up with - // a currentCell which is sometimes not highlighted. - if( aGrid->GetNumberRows() > 0 ) - aGrid->SelectRow( 0 ); -}; + grid->AutoSizeColumn( aCol, false ); + grid->SetColSize( aCol, std::max( prevWidth, grid->GetColSize( aCol ) ) ); + }; + + // all but COL_OPTIONS, which is edited with Option Editor anyways. + autoSizeCol( COL_NICKNAME ); + autoSizeCol( COL_TYPE ); + autoSizeCol( COL_URI ); + autoSizeCol( COL_DESCR ); + + if( grid->GetNumberRows() > 0 ) + { + grid->SetGridCursor( 0, COL_NICKNAME ); + grid->SelectRow( 0 ); + } +} PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PROJECT* aProject ) : @@ -187,16 +231,6 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO m_project( aProject ), m_parent( aParent ) { - wxString* lastGlobalLibDir = nullptr; - - if( PCBNEW_SETTINGS* cfg = GetAppSettings( "pcbnew" ) ) - { - if( cfg->m_LastFootprintLibDir.IsEmpty() ) - cfg->m_LastFootprintLibDir = PATHS::GetDefaultUserFootprintsPath(); - - lastGlobalLibDir = &cfg->m_LastFootprintLibDir; - } - m_lastProjectLibDir = m_project->GetProjectPath(); populatePluginList(); @@ -206,38 +240,20 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO std::optional table = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::FOOTPRINT, LIBRARY_TABLE_SCOPE::GLOBAL ); - wxASSERT( table ); + wxASSERT( table.has_value() ); - FOOTPRINT_LIBRARY_ADAPTER* adapter = PROJECT_PCB::FootprintLibAdapter( m_project ); - - m_global_grid->SetTable( new FP_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_global_grid, *table.value(), adapter, - m_pluginChoices, lastGlobalLibDir, wxEmptyString, - m_supportedFpFiles ), - true /* take ownership */ ); - - // add Cut, Copy, and Paste to wxGrids - m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) ); - - setupGrid( m_global_grid ); - - populateEnvironReadOnlyTable(); + addTable( table.value(), _( "Global Libraries" ), true ); std::optional projectTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::FOOTPRINT, LIBRARY_TABLE_SCOPE::PROJECT ); - if( projectTable ) - { - m_project_grid->SetTable( new FP_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_project_grid, *projectTable.value(), - adapter, m_pluginChoices, &m_lastProjectLibDir, - m_project->GetProjectPath(), m_supportedFpFiles ), - true /* take ownership */ ); - setupGrid( m_project_grid ); - } - else - { - m_notebook->DeletePage( 1 ); - m_project_grid = nullptr; - } + if( projectTable.has_value() ) + addTable( projectTable.value(), _( "Project Specific Libraries" ), false ); + + // add Cut, Copy, and Paste to wxGrids + m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) ); + + populateEnvironReadOnlyTable(); m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) ); m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) ); @@ -542,10 +558,10 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) else title = wxString::Format( _( "Select %s Library" ), PCB_IO_MGR::ShowType( fileType ) ); - if( cur_grid() == m_project_grid ) - lastDir = &m_lastProjectLibDir; - else + if( m_notebook->GetSelection() == 0 ) lastDir = cfg ? &cfg->m_LastFootprintLibDir : &dummy; + else + lastDir = &m_lastProjectLibDir; wxArrayString files; @@ -604,10 +620,8 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) if( !applyToAll ) { // The cancel button adds the library to the table anyway - addDuplicates = OKOrCancelDialog( wxGetTopLevelParent( this ), warning, - wxString::Format( msg, nickname ), - detailedMsg, _( "Skip" ), _( "Add Anyway" ), - &applyToAll ) == wxID_CANCEL; + addDuplicates = OKOrCancelDialog( m_parent, warning, wxString::Format( msg, nickname ), detailedMsg, + _( "Skip" ), _( "Add Anyway" ), &applyToAll ) == wxID_CANCEL; } doAdd = addDuplicates; @@ -664,10 +678,11 @@ void PANEL_FP_LIB_TABLE::onReset( wxCommandEvent& event ) if( !cur_grid()->CommitPendingChanges() ) return; + WX_GRID* grid = get_grid( 0 ); + // No need to prompt to preserve an empty table - if( m_global_grid->GetNumberRows() > 0 - && !IsOK( this, wxString::Format( _( "This action will reset your global library table on " - "disk and cannot be undone." ) ) ) ) + if( grid->GetNumberRows() > 0 && !IsOK( this, wxString::Format( _( "This action will reset your global library " + "table on disk and cannot be undone." ) ) ) ) { return; } @@ -690,10 +705,10 @@ void PANEL_FP_LIB_TABLE::onReset( wxCommandEvent& event ) if( KIFACE *face = m_parent->Kiway().KiFACE( KIWAY::FACE_PCB ) ) face->PreloadLibraries( &m_parent->Kiway() ); - m_global_grid->Freeze(); + grid->Freeze(); - wxGridTableBase* table = m_global_grid->GetTable(); - m_global_grid->DestroyTable( table ); + wxGridTableBase* table = grid->GetTable(); + grid->DestroyTable( table ); std::optional newTable = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::FOOTPRINT, LIBRARY_TABLE_SCOPE::GLOBAL ); @@ -701,15 +716,19 @@ void PANEL_FP_LIB_TABLE::onReset( wxCommandEvent& event ) FOOTPRINT_LIBRARY_ADAPTER* adapter = PROJECT_PCB::FootprintLibAdapter( m_project ); - m_global_grid->SetTable( new FP_LIB_TABLE_GRID_DATA_MODEL( m_parent, m_global_grid, *newTable.value(), adapter, - m_pluginChoices, lastGlobalLibDir, wxEmptyString, - m_supportedFpFiles ), + grid->SetTable( new FP_LIB_TABLE_GRID_DATA_MODEL( m_parent, grid, *newTable.value(), adapter, m_pluginChoices, + lastGlobalLibDir, wxEmptyString, m_supportedFpFiles ), true /* take ownership */ ); - m_global_grid->PopEventHandler( true ); - setupGrid( m_global_grid ); + m_parent->m_GlobalTableChanged = true; - m_global_grid->Thaw(); + grid->Thaw(); + + if( grid->GetNumberRows() > 0 ) + { + grid->SetGridCursor( 0, COL_NICKNAME ); + grid->SelectRow( 0 ); + } } diff --git a/pcbnew/dialogs/panel_fp_lib_table.h b/pcbnew/dialogs/panel_fp_lib_table.h index 4d94b22c97..a2fc3d2d5f 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.h +++ b/pcbnew/dialogs/panel_fp_lib_table.h @@ -23,6 +23,7 @@ #include #include +class LIBRARY_TABLE; class FP_LIB_TABLE; class FP_LIB_TABLE_GRID_DATA_MODEL; class PROJECT; @@ -60,7 +61,7 @@ private: void onPageChange( wxBookCtrlEvent& event ) override; void onReset( wxCommandEvent& event ) override; - void setupGrid( WX_GRID* aGrid ); + void addTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aGlobal ); void adjustPathSubsGridColumns( int aWidth ); diff --git a/pcbnew/dialogs/panel_fp_lib_table_base.cpp b/pcbnew/dialogs/panel_fp_lib_table_base.cpp index 537db73ee2..1cb53dbdbb 100644 --- a/pcbnew/dialogs/panel_fp_lib_table_base.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table_base.cpp @@ -5,7 +5,6 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#include "widgets/panel_notebook_base.h" #include "widgets/std_bitmap_button.h" #include "widgets/wx_grid.h" @@ -19,104 +18,6 @@ PANEL_FP_LIB_TABLE_BASE::PANEL_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID i bMainSizer = new wxBoxSizer( wxVERTICAL ); m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - m_global_panel = new PANEL_NOTEBOOK_BASE( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* m_global_sizer; - m_global_sizer = new wxBoxSizer( wxVERTICAL ); - - m_global_grid = new WX_GRID( m_global_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - // Grid - m_global_grid->CreateGrid( 1, 7 ); - m_global_grid->EnableEditing( true ); - m_global_grid->EnableGridLines( true ); - m_global_grid->EnableDragGridSize( false ); - m_global_grid->SetMargins( 0, 0 ); - - // Columns - m_global_grid->SetColSize( 0, 48 ); - m_global_grid->SetColSize( 1, 48 ); - m_global_grid->SetColSize( 2, 100 ); - m_global_grid->SetColSize( 3, 240 ); - m_global_grid->SetColSize( 4, 100 ); - m_global_grid->SetColSize( 5, 80 ); - m_global_grid->SetColSize( 6, 240 ); - m_global_grid->EnableDragColMove( false ); - m_global_grid->EnableDragColSize( true ); - m_global_grid->SetColLabelValue( 0, _("Active") ); - m_global_grid->SetColLabelValue( 1, _("Visible") ); - m_global_grid->SetColLabelValue( 2, _("Nickname") ); - m_global_grid->SetColLabelValue( 3, _("Library Path") ); - m_global_grid->SetColLabelValue( 4, _("Library Format") ); - m_global_grid->SetColLabelValue( 5, _("Options") ); - m_global_grid->SetColLabelValue( 6, _("Description") ); - m_global_grid->SetColLabelSize( 22 ); - m_global_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Rows - m_global_grid->EnableDragRowSize( false ); - m_global_grid->SetRowLabelSize( 0 ); - m_global_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_global_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); - m_global_sizer->Add( m_global_grid, 1, wxALL|wxEXPAND, 5 ); - - - m_global_panel->SetSizer( m_global_sizer ); - m_global_panel->Layout(); - m_global_sizer->Fit( m_global_panel ); - m_notebook->AddPage( m_global_panel, _("Global Libraries"), true ); - m_project_panel = new PANEL_NOTEBOOK_BASE( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* m_project_sizer; - m_project_sizer = new wxBoxSizer( wxVERTICAL ); - - m_project_grid = new WX_GRID( m_project_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - // Grid - m_project_grid->CreateGrid( 1, 7 ); - m_project_grid->EnableEditing( true ); - m_project_grid->EnableGridLines( true ); - m_project_grid->EnableDragGridSize( false ); - m_project_grid->SetMargins( 0, 0 ); - - // Columns - m_project_grid->SetColSize( 0, 48 ); - m_project_grid->SetColSize( 1, 48 ); - m_project_grid->SetColSize( 2, 100 ); - m_project_grid->SetColSize( 3, 240 ); - m_project_grid->SetColSize( 4, 100 ); - m_project_grid->SetColSize( 5, 80 ); - m_project_grid->SetColSize( 6, 240 ); - m_project_grid->EnableDragColMove( false ); - m_project_grid->EnableDragColSize( true ); - m_project_grid->SetColLabelValue( 0, _("Active") ); - m_project_grid->SetColLabelValue( 1, _("Visible") ); - m_project_grid->SetColLabelValue( 2, _("Nickname") ); - m_project_grid->SetColLabelValue( 3, _("Library Path") ); - m_project_grid->SetColLabelValue( 4, _("Library Format") ); - m_project_grid->SetColLabelValue( 5, _("Options") ); - m_project_grid->SetColLabelValue( 6, _("Description") ); - m_project_grid->SetColLabelSize( 22 ); - m_project_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Rows - m_project_grid->EnableDragRowSize( false ); - m_project_grid->SetRowLabelSize( 0 ); - m_project_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_project_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); - m_project_sizer->Add( m_project_grid, 1, wxALL|wxEXPAND, 5 ); - - - m_project_panel->SetSizer( m_project_sizer ); - m_project_panel->Layout(); - m_project_sizer->Fit( m_project_panel ); - m_notebook->AddPage( m_project_panel, _("Project Specific Libraries"), false ); bMainSizer->Add( m_notebook, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 ); diff --git a/pcbnew/dialogs/panel_fp_lib_table_base.fbp b/pcbnew/dialogs/panel_fp_lib_table_base.fbp index 72e695f6f6..d5e4ae5828 100644 --- a/pcbnew/dialogs/panel_fp_lib_table_base.fbp +++ b/pcbnew/dialogs/panel_fp_lib_table_base.fbp @@ -119,312 +119,6 @@ onPageChange - - - Global Libraries - 1 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 0 - - 0 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_global_panel - 1 - - - protected - 0 - - Resizable - 1 - - PANEL_NOTEBOOK_BASE; widgets/panel_notebook_base.h; forward_declare - 0 - - - - wxTAB_TRAVERSAL - - - m_global_sizer - wxVERTICAL - none - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - 0 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_CENTER - 0 - 1 - wxALIGN_CENTER - 22 - "Active" "Visible" "Nickname" "Library Path" "Library Format" "Options" "Description" - wxALIGN_CENTER - 7 - 48,48,100,240,100,80,240 - - 1 - 0 - Dock - 1 - Left - 0 - 0 - 1 - 0 - 0 - 1 - 1 - - 0 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - - 0 - m_global_grid - 1 - - - protected - 1 - - Fixed - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 1 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - - - - - - - - Project Specific Libraries - 0 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 1 - - 0 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_project_panel - 1 - - - protected - 1 - - Resizable - 1 - - PANEL_NOTEBOOK_BASE; widgets/panel_notebook_base.h; forward_declare - 0 - - - - wxTAB_TRAVERSAL - - - m_project_sizer - wxVERTICAL - none - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - 0 - 0 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_CENTER - 0 - 1 - wxALIGN_CENTER - 22 - "Active" "Visible" "Nickname" "Library Path" "Library Format" "Options" "Description" - wxALIGN_CENTER - 7 - 48,48,100,240,100,80,240 - - 1 - 0 - Dock - 1 - Left - 0 - 0 - 1 - 0 - 0 - 1 - 1 - - 0 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - - 0 - m_project_grid - 1 - - - protected - 1 - - Fixed - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 1 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - - - - - diff --git a/pcbnew/dialogs/panel_fp_lib_table_base.h b/pcbnew/dialogs/panel_fp_lib_table_base.h index 90a059ffcc..ae34163fbd 100644 --- a/pcbnew/dialogs/panel_fp_lib_table_base.h +++ b/pcbnew/dialogs/panel_fp_lib_table_base.h @@ -10,26 +10,25 @@ #include #include #include -class PANEL_NOTEBOOK_BASE; class STD_BITMAP_BUTTON; class WX_GRID; +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include +#include #include #include #include -#include -#include #include #include +#include #include +#include +#include /////////////////////////////////////////////////////////////////////////// @@ -42,10 +41,6 @@ class PANEL_FP_LIB_TABLE_BASE : public wxPanel protected: wxNotebook* m_notebook; - PANEL_NOTEBOOK_BASE* m_global_panel; - WX_GRID* m_global_grid; - PANEL_NOTEBOOK_BASE* m_project_panel; - WX_GRID* m_project_grid; STD_BITMAP_BUTTON* m_append_button; SPLIT_BUTTON* m_browseButton; STD_BITMAP_BUTTON* m_move_up_button;