Added 'Browse Library' button to Symbol Library Table dialog

NEW: File browser for the Symbol Library Table dialog
This commit is contained in:
Maciej Suminski 2017-11-14 11:18:45 +01:00
parent 759359f602
commit 4c623daa1d
5 changed files with 2068 additions and 1913 deletions

View File

@ -30,6 +30,8 @@
#include <grid_tricks.h> #include <grid_tricks.h>
#include <confirm.h> #include <confirm.h>
#include <lib_table_grid.h> #include <lib_table_grid.h>
#include <wildcards_and_files_ext.h>
#include <env_paths.h>
/** /**
@ -340,17 +342,61 @@ void DIALOG_SYMBOL_LIB_TABLE::pageChangedHandler( wxAuiNotebookEvent& event )
} }
void DIALOG_SYMBOL_LIB_TABLE::appendRowHandler( wxCommandEvent& event ) void DIALOG_SYMBOL_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
{ {
wxFileDialog dlg( this, _( "Select Library" ), Prj().GetProjectPath(),
wxEmptyString, SchematicLibraryFileWildcard(),
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
if( dlg.ShowModal() == wxID_CANCEL )
return;
wxArrayString files;
dlg.GetFilenames( files );
for( const auto& file : files )
{
wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
if( m_cur_grid->AppendRows( 1 ) ) if( m_cur_grid->AppendRows( 1 ) )
{ {
int last_row = m_cur_grid->GetNumberRows() - 1; int last_row = m_cur_grid->GetNumberRows() - 1;
wxFileName fn( filePath );
// wx documentation is wrong, SetGridCursor does not make visible. m_cur_grid->SetCellValue( last_row, COL_NICKNAME, fn.GetName() );
m_cur_grid->MakeCellVisible( last_row, 0 );
m_cur_grid->SetGridCursor( last_row, 0 ); // TODO the following code can detect only schematic types, not libs
m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() ); // SCH_IO_MGR needs to provide file extension information for libraries too
// auto detect the plugin type
/*for( auto pluginType : SCH_IO_MGR::SCH_FILE_T_vector )
{
if( SCH_IO_MGR::GetFileExtension( pluginType ).Lower() == fn.GetExt().Lower() )
{
m_cur_grid->SetCellValue( last_row, COL_TYPE,
SCH_IO_MGR::ShowType( pluginType ) );
break;
} }
}*/
m_cur_grid->SetCellValue( last_row, COL_TYPE,
SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
// 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
}
void DIALOG_SYMBOL_LIB_TABLE::appendRowHandler( wxCommandEvent& event )
{
if( m_cur_grid->AppendRows( 1 ) )
scrollToRow( m_cur_grid->GetNumberRows() - 1 );
} }
@ -580,6 +626,15 @@ void DIALOG_SYMBOL_LIB_TABLE::populateEnvironReadOnlyTable()
} }
void DIALOG_SYMBOL_LIB_TABLE::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() );
}
SYMBOL_LIB_TABLE_GRID* DIALOG_SYMBOL_LIB_TABLE::global_model() const SYMBOL_LIB_TABLE_GRID* DIALOG_SYMBOL_LIB_TABLE::global_model() const
{ {
return (SYMBOL_LIB_TABLE_GRID*) m_global_grid->GetTable(); return (SYMBOL_LIB_TABLE_GRID*) m_global_grid->GetTable();

View File

@ -57,6 +57,8 @@ private:
void pageChangedHandler( wxAuiNotebookEvent& event ) override; void pageChangedHandler( wxAuiNotebookEvent& event ) override;
void browseLibrariesHandler( wxCommandEvent& event ) override;
void appendRowHandler( wxCommandEvent& event ) override; void appendRowHandler( wxCommandEvent& event ) override;
void deleteRowHandler( wxCommandEvent& event ) override; void deleteRowHandler( wxCommandEvent& event ) override;
@ -71,6 +73,9 @@ private:
/// by examining all the full_uri columns. /// by examining all the full_uri columns.
void populateEnvironReadOnlyTable(); void populateEnvironReadOnlyTable();
/// Makes a specific row visible
void scrollToRow( int aRowNumber );
// Caller's tables are modified only on OK button and successful verification. // Caller's tables are modified only on OK button and successful verification.
SYMBOL_LIB_TABLE* m_global; SYMBOL_LIB_TABLE* m_global;
SYMBOL_LIB_TABLE* m_project; SYMBOL_LIB_TABLE* m_project;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 29 2017) // C++ code generated with wxFormBuilder (version Oct 17 2016)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -131,6 +131,9 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx
wxBoxSizer* bSizer51; wxBoxSizer* bSizer51;
bSizer51 = new wxBoxSizer( wxHORIZONTAL ); 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 wxButton( m_top_sizer->GetStaticBox(), wxID_ANY, _("Append Library"), wxDefaultPosition, wxDefaultSize, 0 ); 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_append_button->SetToolTip( _("Add a PCB library row to this table") );
@ -219,6 +222,7 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::DIALOG_SYMBOL_LIB_TABLE_BASE( wxWindow* parent, wx
// Connect Events // Connect Events
m_auinotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::pageChangedHandler ), NULL, this ); 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_append_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
m_delete_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::deleteRowHandler ), 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_up_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::moveUpHandler ), NULL, this );
@ -229,6 +233,7 @@ DIALOG_SYMBOL_LIB_TABLE_BASE::~DIALOG_SYMBOL_LIB_TABLE_BASE()
{ {
// Disconnect Events // Disconnect Events
m_auinotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::pageChangedHandler ), NULL, this ); 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_append_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
m_delete_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::deleteRowHandler ), 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_up_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_LIB_TABLE_BASE::moveUpHandler ), NULL, this );

View File

@ -1033,6 +1033,94 @@
<property name="name">bSizer51</property> <property name="name">bSizer51</property>
<property name="orient">wxHORIZONTAL</property> <property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property> <property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Browse Libraries...</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_browse_button</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">browseLibrariesHandler</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="0"> <object class="sizeritem" expanded="0">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL</property> <property name="flag">wxALL</property>

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 29 2017) // C++ code generated with wxFormBuilder (version Oct 17 2016)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -51,6 +51,7 @@ class DIALOG_SYMBOL_LIB_TABLE_BASE : public DIALOG_SHIM
wxStaticText* m_staticText4; wxStaticText* m_staticText4;
wxStaticText* m_PrjTableFilename; wxStaticText* m_PrjTableFilename;
wxGrid* m_project_grid; wxGrid* m_project_grid;
wxButton* m_browse_button;
wxButton* m_append_button; wxButton* m_append_button;
wxButton* m_delete_button; wxButton* m_delete_button;
wxButton* m_move_up_button; wxButton* m_move_up_button;
@ -62,6 +63,7 @@ class DIALOG_SYMBOL_LIB_TABLE_BASE : public DIALOG_SHIM
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void pageChangedHandler( wxAuiNotebookEvent& event ) = 0; virtual void pageChangedHandler( wxAuiNotebookEvent& event ) = 0;
virtual void browseLibrariesHandler( wxCommandEvent& event ) = 0;
virtual void appendRowHandler( wxCommandEvent& event ) = 0; virtual void appendRowHandler( wxCommandEvent& event ) = 0;
virtual void deleteRowHandler( wxCommandEvent& event ) = 0; virtual void deleteRowHandler( wxCommandEvent& event ) = 0;
virtual void moveUpHandler( wxCommandEvent& event ) = 0; virtual void moveUpHandler( wxCommandEvent& event ) = 0;