ADDED: Reset option for Library tables

This re-shows the option to reset the global library table to its
default, empty or specified state

Fixes https://gitlab.com/kicad/code/kicad/-/issues/2309
This commit is contained in:
Seth Hillbrand 2024-05-01 14:52:02 -07:00
parent f8c8dcde13
commit ae610bbe85
13 changed files with 2667 additions and 2320 deletions

View File

@ -194,6 +194,8 @@ WX_GRID::~WX_GRID()
if( m_weOwnTable )
DestroyTable( GetTable() );
Disconnect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( WX_GRID::onCellEditorShown ), nullptr, this );
Disconnect( wxEVT_GRID_EDITOR_HIDDEN, wxGridEventHandler( WX_GRID::onCellEditorHidden ), nullptr, this );
Disconnect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this );
}

View File

@ -64,61 +64,60 @@ bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow()
ioe.What() ) );
return false;
}
return true;
}
wxString fileName = m_filePicker1->GetPath();
if( fileName.IsEmpty() )
else
{
DisplayError( this, _( "Please select a symbol library table file." ) );
return false;
}
wxString fileName = m_filePicker1->GetPath();
wxFileName fn = fileName;
if( fileName.IsEmpty() )
{
DisplayError( this, _( "Please select a symbol library table file." ) );
return false;
}
// Make sure the symbol library table to copy actually exists.
if( !fn.FileExists() )
{
DisplayError( this, wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) );
return false;
}
wxFileName fn = fileName;
// Make sure the symbol library table to copy is a valid symbol library table file.
SYMBOL_LIB_TABLE tmpTable;
// Make sure the symbol library table to copy actually exists.
if( !fn.FileExists() )
{
DisplayError( this, wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) );
return false;
}
try
{
tmpTable.Load( fn.GetFullPath() );
}
catch( const IO_ERROR& ioe )
{
DisplayError( this, wxString::Format( _( "Error reading symbol library table '%s'.\n"
"%s" ),
fn.GetFullPath(),
ioe.What() ) );
return false;
}
// Make sure the symbol library table to copy is a valid symbol library table file.
SYMBOL_LIB_TABLE tmpTable;
// Create the config path if it doesn't already exist.
wxFileName symTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
try
{
tmpTable.Load( fn.GetFullPath() );
}
catch( const IO_ERROR& ioe )
{
DisplayError( this, wxString::Format( _( "Error reading symbol library table '%s'.\n"
"%s" ),
fn.GetFullPath(), ioe.What() ) );
return false;
}
if( !symTableFileName.DirExists() && !symTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
{
DisplayError( this, wxString::Format( _( "Cannot create global library table '%s'." ),
symTableFileName.GetPath() ) );
return false;
}
// Create the config path if it doesn't already exist.
wxFileName symTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
// Copy the global symbol library table file to the user config.
if( !::wxCopyFile( fn.GetFullPath(), symTableFileName.GetFullPath() ) )
{
DisplayError( this, wxString::Format( _( "Error copying global symbol library table '%s' "
"to '%s'." ),
fn.GetFullPath(),
symTableFileName.GetFullPath() ) );
return false;
if( !symTableFileName.DirExists() && !symTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
{
DisplayError( this, wxString::Format( _( "Cannot create global library table '%s'." ),
symTableFileName.GetPath() ) );
return false;
}
// Copy the global symbol library table file to the user config.
if( !::wxCopyFile( fn.GetFullPath(), symTableFileName.GetFullPath() ) )
{
DisplayError( this,
wxString::Format( _( "Error copying global symbol library table '%s' "
"to '%s'." ),
fn.GetFullPath(), symTableFileName.GetFullPath() ) );
return false;
}
}
// Load the successfully copied symbol library table file. This should not fail since the

View File

@ -24,6 +24,7 @@
#include <build_version.h>
#include <common.h> // For ExpandEnvVarSubstitutions
#include <dialogs/dialog_global_sym_lib_table_config.h>
#include <dialogs/dialog_plugin_options.h>
#include <project.h>
#include <panel_sym_lib_table.h>
@ -230,6 +231,86 @@ protected:
};
void PANEL_SYM_LIB_TABLE::setupGrid( WX_GRID* aGrid )
{
auto autoSizeCol =
[&]( WX_GRID* aGrid, int aCol )
{
int prevWidth = aGrid->GetColSize( aCol );
aGrid->AutoSizeColumn( aCol, false );
aGrid->SetColSize( aCol, std::max( prevWidth, aGrid->GetColSize( aCol ) ) );
};
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
// Give a bit more room for combobox editors
for( int ii = 0; ii < aGrid->GetNumberRows(); ++ii )
aGrid->SetRowSize( ii, aGrid->GetDefaultRowSize() + 4 );
// add Cut, Copy, and Paste to wxGrids
aGrid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, aGrid ) );
aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
// Set special attributes
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
wxString fileFiltersStr;
wxString allWildcardsStr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
&cfg->m_lastSymbolLibDir,
true, m_project->GetProjectPath(),
[]( WX_GRID* grid, int row ) -> wxString
{
auto* libTable = static_cast<SYMBOL_LIB_TABLE_GRID*>( grid->GetTable() );
auto* tableRow = static_cast<SYMBOL_LIB_TABLE_ROW*>( libTable->at( row ) );
IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( tableRow->GetFileType() ) );
if( pi )
{
const IO_BASE::IO_FILE_DESC& desc = pi->GetLibraryDesc();
if( desc.m_IsFile )
return desc.FileFilter();
}
return wxEmptyString;
} ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;
attr->SetEditor( new wxGridCellChoiceEditor( m_pluginChoices ) );
aGrid->SetColAttr( COL_TYPE, attr );
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_ENABLED, attr );
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_VISIBLE, attr );
// 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 );
autoSizeCol( aGrid, COL_ENABLED );
// 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 );
};
PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PROJECT* aProject,
SYMBOL_LIB_TABLE* aGlobalTable,
const wxString& aGlobalTablePath,
@ -245,8 +326,6 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
// so make it a grid owned table.
m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *m_globalTable ), true );
wxArrayString pluginChoices;
for( const SCH_IO_MGR::SCH_FILE_T& type : SCH_IO_MGR::SCH_FILE_T_vector )
{
IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( type ) );
@ -255,7 +334,7 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
continue;
if( const IO_BASE::IO_FILE_DESC& desc = pi->GetLibraryDesc() )
pluginChoices.Add( SCH_IO_MGR::ShowType( type ) );
m_pluginChoices.Add( SCH_IO_MGR::ShowType( type ) );
}
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
@ -265,82 +344,6 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
m_lastProjectLibDir = m_project->GetProjectPath();
auto autoSizeCol =
[&]( WX_GRID* aGrid, int aCol )
{
int prevWidth = aGrid->GetColSize( aCol );
aGrid->AutoSizeColumn( aCol, false );
aGrid->SetColSize( aCol, std::max( prevWidth, aGrid->GetColSize( aCol ) ) );
};
auto setupGrid =
[&]( WX_GRID* aGrid )
{
// Give a bit more room for combobox editors
aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
// add Cut, Copy, and Paste to wxGrids
aGrid->PushEventHandler( new SYMBOL_GRID_TRICKS( m_parent, aGrid ) );
aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
// Set special attributes
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
wxString fileFiltersStr;
wxString allWildcardsStr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
&cfg->m_lastSymbolLibDir,
true, m_project->GetProjectPath(),
[]( WX_GRID* grid, int row ) -> wxString
{
auto* libTable = static_cast<SYMBOL_LIB_TABLE_GRID*>( grid->GetTable() );
auto* tableRow = static_cast<SYMBOL_LIB_TABLE_ROW*>( libTable->at( row ) );
IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( tableRow->GetFileType() ) );
if( pi )
{
const IO_BASE::IO_FILE_DESC& desc = pi->GetLibraryDesc();
if( desc.m_IsFile )
return desc.FileFilter();
}
return wxEmptyString;
} ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;
attr->SetEditor( new wxGridCellChoiceEditor( pluginChoices ) );
aGrid->SetColAttr( COL_TYPE, attr );
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_ENABLED, attr );
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_VISIBLE, attr );
// 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 );
autoSizeCol( aGrid, COL_ENABLED );
// 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 );
@ -413,6 +416,7 @@ bool PANEL_SYM_LIB_TABLE::allowAutomaticPluginTypeSelection( wxString& aLibraryP
bool PANEL_SYM_LIB_TABLE::verifyTables()
{
wxString msg;
wxBusyCursor wait;
for( SYMBOL_LIB_TABLE_GRID* model : { global_model(), project_model() } )
{
@ -443,9 +447,13 @@ bool PANEL_SYM_LIB_TABLE::verifyTables()
badCellDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Remove Invalid Cells" ) ),
wxMessageDialog::ButtonLabel( _( "Cancel Table Update" ) ) );
wxEndBusyCursor();
if( badCellDlg.ShowModal() == wxID_NO )
return false;
wxBeginBusyCursor( wxHOURGLASS_CURSOR );
// 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
@ -468,6 +476,8 @@ bool PANEL_SYM_LIB_TABLE::verifyTables()
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
wxEndBusyCursor();
errdlg.ShowModal();
return false;
}
@ -519,6 +529,7 @@ bool PANEL_SYM_LIB_TABLE::verifyTables()
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxEndBusyCursor();
wxMessageDialog errdlg( topLevelParent, msg, _( "Library Nickname Error" ) );
errdlg.ShowModal();
@ -558,7 +569,7 @@ bool PANEL_SYM_LIB_TABLE::verifyTables()
msg.Printf( _( "Symbol library '%s' failed to load." ), row.GetNickName() );
wxWindow* topLevelParent = wxGetTopLevelParent( this );
wxEndBusyCursor();
wxMessageDialog errdlg( topLevelParent, msg + wxS( "\n" ) + ioe.What(),
_( "Error Loading Library" ) );
errdlg.ShowModal();
@ -574,8 +585,6 @@ bool PANEL_SYM_LIB_TABLE::verifyTables()
void PANEL_SYM_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
{
m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
m_cur_grid = m_pageNdx == 0 ? m_global_grid : m_project_grid;
}
@ -827,6 +836,56 @@ void PANEL_SYM_LIB_TABLE::moveDownHandler( wxCommandEvent& event )
}
void PANEL_SYM_LIB_TABLE::onReset( wxCommandEvent& event )
{
if( !m_cur_grid->CommitPendingChanges() )
return;
// 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." ) ) ) )
{
return;
}
DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG dlg( m_parent );
if( dlg.ShowModal() == wxID_OK )
{
m_global_grid->Freeze();
wxGridTableBase* table = m_global_grid->GetTable();
m_global_grid->DestroyTable( table );
m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *m_globalTable ), true );
m_global_grid->PopEventHandler( true );
setupGrid( m_global_grid );
m_parent->m_GlobalTableChanged = true;
m_global_grid->Thaw();
}
}
void PANEL_SYM_LIB_TABLE::onPageChange( wxBookCtrlEvent& event )
{
m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
if( m_pageNdx == 0 )
{
m_cur_grid = m_global_grid;
m_resetGlobal->Enable();
}
else
{
m_cur_grid = m_project_grid;
m_resetGlobal->Disable();
}
}
void PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries( wxCommandEvent& event )
{
if( !m_cur_grid->CommitPendingChanges() )

View File

@ -59,6 +59,11 @@ private:
void adjustPathSubsGridColumns( int aWidth );
void onConvertLegacyLibraries( wxCommandEvent& event ) override;
void onPageChange( wxBookCtrlEvent& event ) override;
void onReset( wxCommandEvent& event ) override;
void setupGrid( WX_GRID* aGrid );
bool TransferDataFromWindow() override;
/// Populate the readonly environment variable table with names and values
@ -86,6 +91,7 @@ private:
PROJECT* m_project;
DIALOG_EDIT_LIBRARY_TABLES* m_parent;
wxArrayString m_pluginChoices;
WX_GRID* m_cur_grid; ///< changed based on tab choice
static size_t m_pageNdx; ///< Remember the last notebook page selected

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf0)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -156,6 +156,12 @@ PANEL_SYM_LIB_TABLE_BASE::PANEL_SYM_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
bButtonsSizer->Add( 0, 0, 1, wxEXPAND, 5 );
m_resetGlobal = new wxButton( this, wxID_ANY, _("Reset Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
bButtonsSizer->Add( m_resetGlobal, 0, wxALL, 5 );
bButtonsSizer->Add( 0, 0, 0, wxEXPAND, 5 );
m_convertLegacy = new wxButton( this, wxID_ANY, _("Migrate Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
bButtonsSizer->Add( m_convertLegacy, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
@ -211,11 +217,13 @@ PANEL_SYM_LIB_TABLE_BASE::PANEL_SYM_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
// Connect Events
this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_SYM_LIB_TABLE_BASE::OnUpdateUI ) );
m_notebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( PANEL_SYM_LIB_TABLE_BASE::onPageChange ), NULL, this );
m_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
m_browse_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this );
m_move_up_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::moveUpHandler ), NULL, this );
m_move_down_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::moveDownHandler ), NULL, this );
m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::deleteRowHandler ), NULL, this );
m_resetGlobal->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::onReset ), NULL, this );
m_convertLegacy->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::onConvertLegacyLibraries ), NULL, this );
m_path_subs_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( PANEL_SYM_LIB_TABLE_BASE::onSizeGrid ), NULL, this );
}
@ -224,11 +232,13 @@ PANEL_SYM_LIB_TABLE_BASE::~PANEL_SYM_LIB_TABLE_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_SYM_LIB_TABLE_BASE::OnUpdateUI ) );
m_notebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( PANEL_SYM_LIB_TABLE_BASE::onPageChange ), NULL, this );
m_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
m_browse_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::browseLibrariesHandler ), NULL, this );
m_move_up_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::moveUpHandler ), NULL, this );
m_move_down_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::moveDownHandler ), NULL, this );
m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::deleteRowHandler ), NULL, this );
m_resetGlobal->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::onReset ), NULL, this );
m_convertLegacy->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_SYM_LIB_TABLE_BASE::onConvertLegacyLibraries ), NULL, this );
m_path_subs_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( PANEL_SYM_LIB_TABLE_BASE::onSizeGrid ), NULL, this );

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf0)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -50,16 +50,19 @@ class PANEL_SYM_LIB_TABLE_BASE : public wxPanel
STD_BITMAP_BUTTON* m_move_up_button;
STD_BITMAP_BUTTON* m_move_down_button;
STD_BITMAP_BUTTON* m_delete_button;
wxButton* m_resetGlobal;
wxButton* m_convertLegacy;
WX_GRID* m_path_subs_grid;
// Virtual event handlers, override them in your derived class
virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onPageChange( wxNotebookEvent& event ) { event.Skip(); }
virtual void appendRowHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void browseLibrariesHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void moveUpHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void moveDownHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void deleteRowHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void onReset( wxCommandEvent& event ) { event.Skip(); }
virtual void onConvertLegacyLibraries( wxCommandEvent& event ) { event.Skip(); }
virtual void onSizeGrid( wxSizeEvent& event ) { event.Skip(); }

View File

@ -63,62 +63,63 @@ bool DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow()
+ wxS( "\n" ) + ioe.What() );
return false;
}
return true;
}
wxString fileName = m_filePicker1->GetPath();
if( fileName.IsEmpty() )
else
{
DisplayError( this, _( "Please select a footprint library table file." ) );
return false;
}
wxString fileName = m_filePicker1->GetPath();
wxFileName fn = fileName;
if( fileName.IsEmpty() )
{
DisplayError( this, _( "Please select a footprint library table file." ) );
return false;
}
// Make sure the footprint library table to copy actually exists.
if( !fn.FileExists() )
{
DisplayError( this, wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) );
return false;
}
wxFileName fn = fileName;
// Make sure the footprint library table to copy is a valid footprint library table file.
FP_LIB_TABLE tmpTable;
// Make sure the footprint library table to copy actually exists.
if( !fn.FileExists() )
{
DisplayError( this, wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) );
return false;
}
try
{
tmpTable.Load( fn.GetFullPath() );
}
catch( const IO_ERROR& ioe )
{
DisplayError( this, wxString::Format( _( "'%s' is not a valid footprint library table." ),
fn.GetFullPath() )
+ wxS( "\n" ) + ioe.What() );
return false;
}
// Make sure the footprint library table to copy is a valid footprint library table file.
FP_LIB_TABLE tmpTable;
// Create the config path if it doesn't already exist.
wxFileName fpTableFileName = FP_LIB_TABLE::GetGlobalTableFileName();
try
{
tmpTable.Load( fn.GetFullPath() );
}
catch( const IO_ERROR& ioe )
{
DisplayError( this,
wxString::Format( _( "'%s' is not a valid footprint library table." ),
fn.GetFullPath() )
+ wxS( "\n" ) + ioe.What() );
return false;
}
if( !fpTableFileName.DirExists() && !fpTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
{
DisplayError( this, wxString::Format( _( "Cannot create library table path '%s'." ),
fpTableFileName.GetPath() ) );
return false;
}
// Create the config path if it doesn't already exist.
wxFileName fpTableFileName = FP_LIB_TABLE::GetGlobalTableFileName();
// Copy the global footprint library table file to the user config.
if( !::wxCopyFile( fn.GetFullPath(), fpTableFileName.GetFullPath() ) )
{
DisplayError( this, wxString::Format( _( "Cannot copy footprint library table from:\n"
"%s\n"
"to:\n"
"%s." ),
fn.GetFullPath(),
fpTableFileName.GetFullPath() ) );
return false;
if( !fpTableFileName.DirExists() && !fpTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
{
DisplayError( this, wxString::Format( _( "Cannot create library table path '%s'." ),
fpTableFileName.GetPath() ) );
return false;
}
// Copy the global footprint library table file to the user config.
if( !::wxCopyFile( fn.GetFullPath(), fpTableFileName.GetFullPath() ) )
{
DisplayError( this,
wxString::Format( _( "Cannot copy footprint library table from:\n"
"%s\n"
"to:\n"
"%s." ),
fn.GetFullPath(), fpTableFileName.GetFullPath() ) );
return false;
}
}
// Load the successfully copied footprint library table file. This should not fail

View File

@ -58,6 +58,7 @@
#include <pcb_edit_frame.h>
#include <env_paths.h>
#include <dialogs/dialog_edit_library_tables.h>
#include <dialogs/dialog_global_fp_lib_table_config.h>
#include <dialogs/dialog_plugin_options.h>
#include <footprint_viewer_frame.h>
#include <footprint_edit_frame.h>
@ -299,6 +300,73 @@ protected:
};
void PANEL_FP_LIB_TABLE::setupGrid( WX_GRID* aGrid )
{
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
auto autoSizeCol = [&]( WX_GRID* aGrid, int aCol )
{
int prevWidth = aGrid->GetColSize( aCol );
aGrid->AutoSizeColumn( aCol, false );
aGrid->SetColSize( aCol, std::max( prevWidth, aGrid->GetColSize( aCol ) ) );
};
// Give a bit more room for wxChoice editors
for( int ii = 0; ii < aGrid->GetNumberRows(); ++ii )
aGrid->SetRowSize( ii, aGrid->GetDefaultRowSize() + 4 );
// add Cut, Copy, and Paste to wxGrids
aGrid->PushEventHandler( new FP_GRID_TRICKS( m_parent, aGrid ) );
aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR(
m_parent, aGrid, &cfg->m_lastFootprintLibDir, true, m_projectBasePath,
[this]( WX_GRID* grid, int row ) -> wxString
{
auto* libTable = static_cast<FP_LIB_TABLE_GRID*>( grid->GetTable() );
auto* tableRow = static_cast<FP_LIB_TABLE_ROW*>( libTable->at( row ) );
PCB_IO_MGR::PCB_FILE_T fileType = tableRow->GetFileType();
const IO_BASE::IO_FILE_DESC& pluginDesc = m_supportedFpFiles.at( fileType );
if( pluginDesc.m_IsFile )
return pluginDesc.FileFilter();
else
return wxEmptyString;
} ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;
attr->SetEditor( new wxGridCellChoiceEditor( m_pluginChoices ) );
aGrid->SetColAttr( COL_TYPE, attr );
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_ENABLED, attr );
// No visibility control for footprint libraries yet; this feature is primarily
// useful for database libraries and it's only implemented for schematic symbols
// at the moment.
aGrid->HideCol( COL_VISIBLE );
// 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 );
// 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 );
};
PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PROJECT* aProject,
FP_LIB_TABLE* aGlobalTable, const wxString& aGlobalTblPath,
FP_LIB_TABLE* aProjectTable, const wxString& aProjectTblPath,
@ -317,10 +385,8 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO
populatePluginList();
wxArrayString choices;
for( auto& [fileType, desc] : m_supportedFpFiles )
choices.Add( PCB_IO_MGR::ShowType( fileType ) );
m_pluginChoices.Add( PCB_IO_MGR::ShowType( fileType ) );
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
@ -330,71 +396,6 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO
m_lastProjectLibDir = m_projectBasePath;
auto autoSizeCol =
[&]( WX_GRID* aGrid, int aCol )
{
int prevWidth = aGrid->GetColSize( aCol );
aGrid->AutoSizeColumn( aCol, false );
aGrid->SetColSize( aCol, std::max( prevWidth, aGrid->GetColSize( aCol ) ) );
};
auto setupGrid =
[&]( WX_GRID* aGrid )
{
// Give a bit more room for wxChoice editors
aGrid->SetDefaultRowSize( aGrid->GetDefaultRowSize() + 4 );
// add Cut, Copy, and Paste to wxGrids
aGrid->PushEventHandler( new FP_GRID_TRICKS( m_parent, aGrid ) );
aGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, aGrid,
&cfg->m_lastFootprintLibDir, true, m_projectBasePath,
[this]( WX_GRID* grid, int row ) -> wxString
{
auto* libTable = static_cast<FP_LIB_TABLE_GRID*>( grid->GetTable() );
auto* tableRow = static_cast<FP_LIB_TABLE_ROW*>( libTable->at( row ) );
PCB_IO_MGR::PCB_FILE_T fileType = tableRow->GetFileType();
const IO_BASE::IO_FILE_DESC& pluginDesc = m_supportedFpFiles.at( fileType );
if( pluginDesc.m_IsFile )
return pluginDesc.FileFilter();
else
return wxEmptyString;
} ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;
attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
aGrid->SetColAttr( COL_TYPE, attr );
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_ENABLED, attr );
// No visibility control for footprint libraries yet; this feature is primarily
// useful for database libraries and it's only implemented for schematic symbols
// at the moment.
aGrid->HideCol( COL_VISIBLE );
// 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 );
// 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();
@ -639,8 +640,6 @@ bool PANEL_FP_LIB_TABLE::verifyTables()
void PANEL_FP_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
{
m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
m_cur_grid = m_pageNdx == 0 ? m_global_grid : m_project_grid;
}
@ -1053,6 +1052,55 @@ void PANEL_FP_LIB_TABLE::onSizeGrid( wxSizeEvent& event )
}
void PANEL_FP_LIB_TABLE::onReset( wxCommandEvent& event )
{
if( !m_cur_grid->CommitPendingChanges() )
return;
// 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." ) ) ) )
{
return;
}
DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG dlg( m_parent );
if( dlg.ShowModal() == wxID_OK )
{
m_global_grid->Freeze();
wxGridTableBase* table = m_global_grid->GetTable();
m_global_grid->DestroyTable( table );
m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *m_globalTable ), true );
m_global_grid->PopEventHandler( true );
setupGrid( m_global_grid );
m_parent->m_GlobalTableChanged = true;
m_global_grid->Thaw();
}
}
void PANEL_FP_LIB_TABLE::onPageChange( wxBookCtrlEvent& event )
{
m_pageNdx = (unsigned) std::max( 0, m_notebook->GetSelection() );
if( m_pageNdx == 0 )
{
m_cur_grid = m_global_grid;
m_resetGlobal->Enable();
}
else
{
m_cur_grid = m_project_grid;
m_resetGlobal->Disable();
}
}
bool PANEL_FP_LIB_TABLE::TransferDataFromWindow()
{
if( !m_cur_grid->CommitPendingChanges() )

View File

@ -61,6 +61,11 @@ private:
void onMigrateLibraries( wxCommandEvent& event ) override;
void onSizeGrid( wxSizeEvent& event ) override;
void onPageChange( wxBookCtrlEvent& event ) override;
void onReset( wxCommandEvent& event ) override;
void setupGrid( WX_GRID* aGrid );
void adjustPathSubsGridColumns( int aWidth );
/// Populate the readonly environment variable table with names and values
@ -90,6 +95,7 @@ private:
wxString m_projectBasePath;
DIALOG_EDIT_LIBRARY_TABLES* m_parent;
wxArrayString m_pluginChoices;
WX_GRID* m_cur_grid; // changed based on tab choice
static size_t m_pageNdx; // Remember last notebook page selected during a session

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf0)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -153,6 +153,12 @@ PANEL_FP_LIB_TABLE_BASE::PANEL_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID i
bButtonsSizer->Add( 20, 0, 1, wxEXPAND, 5 );
m_resetGlobal = new wxButton( this, wxID_ANY, _("Reset Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
bButtonsSizer->Add( m_resetGlobal, 0, wxALL, 5 );
bButtonsSizer->Add( 0, 0, 0, wxEXPAND, 5 );
m_migrate_libs_button = new wxButton( this, wxID_ANY, _("Migrate Libraries"), wxDefaultPosition, wxDefaultSize, 0 );
bButtonsSizer->Add( m_migrate_libs_button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
@ -205,10 +211,12 @@ PANEL_FP_LIB_TABLE_BASE::PANEL_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID i
// Connect Events
this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_FP_LIB_TABLE_BASE::OnUpdateUI ) );
m_notebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( PANEL_FP_LIB_TABLE_BASE::onPageChange ), NULL, this );
m_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
m_move_up_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::moveUpHandler ), NULL, this );
m_move_down_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::moveDownHandler ), NULL, this );
m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::deleteRowHandler ), NULL, this );
m_resetGlobal->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::onReset ), NULL, this );
m_migrate_libs_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::onMigrateLibraries ), NULL, this );
m_path_subs_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( PANEL_FP_LIB_TABLE_BASE::onSizeGrid ), NULL, this );
}
@ -217,10 +225,12 @@ PANEL_FP_LIB_TABLE_BASE::~PANEL_FP_LIB_TABLE_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PANEL_FP_LIB_TABLE_BASE::OnUpdateUI ) );
m_notebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( PANEL_FP_LIB_TABLE_BASE::onPageChange ), NULL, this );
m_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
m_move_up_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::moveUpHandler ), NULL, this );
m_move_down_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::moveDownHandler ), NULL, this );
m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::deleteRowHandler ), NULL, this );
m_resetGlobal->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::onReset ), NULL, this );
m_migrate_libs_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_FP_LIB_TABLE_BASE::onMigrateLibraries ), NULL, this );
m_path_subs_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( PANEL_FP_LIB_TABLE_BASE::onSizeGrid ), NULL, this );

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf0)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -51,15 +51,18 @@ class PANEL_FP_LIB_TABLE_BASE : public wxPanel
STD_BITMAP_BUTTON* m_move_up_button;
STD_BITMAP_BUTTON* m_move_down_button;
STD_BITMAP_BUTTON* m_delete_button;
wxButton* m_resetGlobal;
wxButton* m_migrate_libs_button;
WX_GRID* m_path_subs_grid;
// Virtual event handlers, override them in your derived class
virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onPageChange( wxNotebookEvent& event ) { event.Skip(); }
virtual void appendRowHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void moveUpHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void moveDownHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void deleteRowHandler( wxCommandEvent& event ) { event.Skip(); }
virtual void onReset( wxCommandEvent& event ) { event.Skip(); }
virtual void onMigrateLibraries( wxCommandEvent& event ) { event.Skip(); }
virtual void onSizeGrid( wxSizeEvent& event ) { event.Skip(); }