ADDED New Library functionality to Footprint/Symbol Save As.
Fixes https://gitlab.com/kicad/code/kicad/issues/2343
This commit is contained in:
parent
84f620a96e
commit
08f15fe587
|
@ -34,6 +34,8 @@ EDA_LIST_DIALOG_BASE::EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id, con
|
||||||
|
|
||||||
bSizerMain->Add( bMargins, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 );
|
bSizerMain->Add( bMargins, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 );
|
||||||
|
|
||||||
|
m_ButtonsSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
|
|
||||||
m_sdbSizer = new wxStdDialogButtonSizer();
|
m_sdbSizer = new wxStdDialogButtonSizer();
|
||||||
m_sdbSizerOK = new wxButton( this, wxID_OK );
|
m_sdbSizerOK = new wxButton( this, wxID_OK );
|
||||||
m_sdbSizer->AddButton( m_sdbSizerOK );
|
m_sdbSizer->AddButton( m_sdbSizerOK );
|
||||||
|
@ -41,7 +43,10 @@ EDA_LIST_DIALOG_BASE::EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id, con
|
||||||
m_sdbSizer->AddButton( m_sdbSizerCancel );
|
m_sdbSizer->AddButton( m_sdbSizerCancel );
|
||||||
m_sdbSizer->Realize();
|
m_sdbSizer->Realize();
|
||||||
|
|
||||||
bSizerMain->Add( m_sdbSizer, 0, wxEXPAND|wxALL, 5 );
|
m_ButtonsSizer->Add( m_sdbSizer, 1, wxALL, 5 );
|
||||||
|
|
||||||
|
|
||||||
|
bSizerMain->Add( m_ButtonsSizer, 0, wxEXPAND, 5 );
|
||||||
|
|
||||||
|
|
||||||
this->SetSizer( bSizerMain );
|
this->SetSizer( bSizerMain );
|
||||||
|
|
|
@ -260,8 +260,17 @@
|
||||||
</object>
|
</object>
|
||||||
<object class="sizeritem" expanded="1">
|
<object class="sizeritem" expanded="1">
|
||||||
<property name="border">5</property>
|
<property name="border">5</property>
|
||||||
<property name="flag">wxEXPAND|wxALL</property>
|
<property name="flag">wxEXPAND</property>
|
||||||
<property name="proportion">0</property>
|
<property name="proportion">0</property>
|
||||||
|
<object class="wxBoxSizer" expanded="1">
|
||||||
|
<property name="minimum_size"></property>
|
||||||
|
<property name="name">m_ButtonsSizer</property>
|
||||||
|
<property name="orient">wxHORIZONTAL</property>
|
||||||
|
<property name="permission">public</property>
|
||||||
|
<object class="sizeritem" expanded="1">
|
||||||
|
<property name="border">5</property>
|
||||||
|
<property name="flag">wxALL</property>
|
||||||
|
<property name="proportion">1</property>
|
||||||
<object class="wxStdDialogButtonSizer" expanded="1">
|
<object class="wxStdDialogButtonSizer" expanded="1">
|
||||||
<property name="Apply">0</property>
|
<property name="Apply">0</property>
|
||||||
<property name="Cancel">1</property>
|
<property name="Cancel">1</property>
|
||||||
|
@ -279,4 +288,6 @@
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
</wxFormBuilder_Project>
|
</wxFormBuilder_Project>
|
||||||
|
|
|
@ -47,6 +47,7 @@ class EDA_LIST_DIALOG_BASE : public DIALOG_SHIM
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
wxBoxSizer* m_ButtonsSizer;
|
||||||
|
|
||||||
EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
|
EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
|
||||||
~EDA_LIST_DIALOG_BASE();
|
~EDA_LIST_DIALOG_BASE();
|
||||||
|
|
|
@ -828,13 +828,13 @@ bool SYMBOL_EDIT_FRAME::SynchronizePins()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
|
wxString SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
|
||||||
{
|
{
|
||||||
// Select the target library table (global/project)
|
// Select the target library table (global/project)
|
||||||
SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
|
SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
|
||||||
|
|
||||||
if( !libTable )
|
if( !libTable )
|
||||||
return false;
|
return wxEmptyString;
|
||||||
|
|
||||||
wxFileName fn = m_libMgr->GetUniqueLibraryName();
|
wxFileName fn = m_libMgr->GetUniqueLibraryName();
|
||||||
|
|
||||||
|
@ -843,18 +843,18 @@ bool SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
|
||||||
( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
|
( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
|
||||||
PATHS::GetDefaultUserSymbolsPath() ) )
|
PATHS::GetDefaultUserSymbolsPath() ) )
|
||||||
{
|
{
|
||||||
return false;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString libName = fn.GetName();
|
wxString libName = fn.GetName();
|
||||||
|
|
||||||
if( libName.IsEmpty() )
|
if( libName.IsEmpty() )
|
||||||
return false;
|
return wxEmptyString;
|
||||||
|
|
||||||
if( m_libMgr->LibraryExists( libName ) )
|
if( m_libMgr->LibraryExists( libName ) )
|
||||||
{
|
{
|
||||||
DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libName ) );
|
DisplayError( this, wxString::Format( _( "Library '%s' already exists." ), libName ) );
|
||||||
return false;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( aCreateNew )
|
if( aCreateNew )
|
||||||
|
@ -862,9 +862,10 @@ bool SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
|
||||||
if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
|
if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
|
||||||
{
|
{
|
||||||
DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
|
DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
|
||||||
"Make sure you have write permissions and try again." ),
|
"Make sure you have write permissions and "
|
||||||
|
"try again." ),
|
||||||
fn.GetFullPath() ) );
|
fn.GetFullPath() ) );
|
||||||
return false;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -872,7 +873,7 @@ bool SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
|
||||||
if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
|
if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
|
||||||
{
|
{
|
||||||
DisplayError( this, _( "Could not open the library file." ) );
|
DisplayError( this, _( "Could not open the library file." ) );
|
||||||
return false;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,7 +883,7 @@ bool SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
|
||||||
std::string packet = fn.GetFullPath().ToStdString();
|
std::string packet = fn.GetFullPath().ToStdString();
|
||||||
this->Kiway().ExpressMail( FRAME_SCH_SYMBOL_EDITOR, MAIL_LIB_EDIT, packet );
|
this->Kiway().ExpressMail( FRAME_SCH_SYMBOL_EDITOR, MAIL_LIB_EDIT, packet );
|
||||||
|
|
||||||
return true;
|
return fn.GetFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||||
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
||||||
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
* Copyright (C) 2017 CERN
|
* Copyright (C) 2017 CERN
|
||||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||||
*
|
*
|
||||||
|
@ -44,6 +44,7 @@ class LIB_TREE_NODE;
|
||||||
class LIB_ID;
|
class LIB_ID;
|
||||||
class SYMBOL_LIBRARY_MANAGER;
|
class SYMBOL_LIBRARY_MANAGER;
|
||||||
class SYMBOL_EDITOR_SETTINGS;
|
class SYMBOL_EDITOR_SETTINGS;
|
||||||
|
class EDA_LIST_DIALOG;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +122,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Create or add an existing library to the symbol library table.
|
* Create or add an existing library to the symbol library table.
|
||||||
*/
|
*/
|
||||||
bool AddLibraryFile( bool aCreateNew );
|
wxString AddLibraryFile( bool aCreateNew );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new symbol in the selected library.
|
* Create a new symbol in the selected library.
|
||||||
|
@ -369,6 +370,9 @@ private:
|
||||||
// Set up the tool framework
|
// Set up the tool framework
|
||||||
void setupTools();
|
void setupTools();
|
||||||
|
|
||||||
|
EDA_LIST_DIALOG* buildSaveAsDialog( const wxString& aSymbolName,
|
||||||
|
const wxString& aLibraryPreselect );
|
||||||
|
|
||||||
void saveSymbolAs();
|
void saveSymbolAs();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||||
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
||||||
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -646,6 +646,68 @@ void SYMBOL_EDIT_FRAME::SaveSymbolAs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int ID_SAVE_AS_NAME = 4172;
|
||||||
|
static int ID_MAKE_NEW_LIBRARY = 4173;
|
||||||
|
|
||||||
|
|
||||||
|
EDA_LIST_DIALOG* SYMBOL_EDIT_FRAME::buildSaveAsDialog( const wxString& aSymbolName,
|
||||||
|
const wxString& aLibraryPreselect )
|
||||||
|
{
|
||||||
|
SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable();
|
||||||
|
std::vector<wxString> libNicknames = tbl->GetLogicalLibs();
|
||||||
|
wxArrayString headers;
|
||||||
|
std::vector<wxArrayString> itemsToDisplay;
|
||||||
|
|
||||||
|
headers.Add( _( "Nickname" ) );
|
||||||
|
headers.Add( _( "Description" ) );
|
||||||
|
|
||||||
|
for( const wxString& nickname : libNicknames )
|
||||||
|
{
|
||||||
|
wxArrayString item;
|
||||||
|
item.Add( nickname );
|
||||||
|
item.Add( tbl->GetDescription( nickname ) );
|
||||||
|
itemsToDisplay.push_back( item );
|
||||||
|
}
|
||||||
|
|
||||||
|
EDA_LIST_DIALOG* dlg = new EDA_LIST_DIALOG( this, _( "Save Symbol As" ), headers,
|
||||||
|
itemsToDisplay, aLibraryPreselect );
|
||||||
|
|
||||||
|
dlg->SetListLabel( _( "Save in library:" ) );
|
||||||
|
dlg->SetOKLabel( _( "Save" ) );
|
||||||
|
|
||||||
|
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
|
|
||||||
|
wxStaticText* label = new wxStaticText( dlg, wxID_ANY, _( "Name:" ) );
|
||||||
|
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
||||||
|
|
||||||
|
wxTextCtrl* nameTextCtrl = new wxTextCtrl( dlg, ID_SAVE_AS_NAME, aSymbolName );
|
||||||
|
bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||||
|
|
||||||
|
wxButton* newLibraryButton = new wxButton( dlg, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
|
||||||
|
dlg->m_ButtonsSizer->Prepend( 80, 20 );
|
||||||
|
dlg->m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
|
||||||
|
|
||||||
|
dlg->GetSizer()->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
||||||
|
|
||||||
|
dlg->Bind( wxEVT_BUTTON,
|
||||||
|
[dlg]( wxCommandEvent& )
|
||||||
|
{
|
||||||
|
dlg->EndModal( ID_MAKE_NEW_LIBRARY );
|
||||||
|
}, ID_MAKE_NEW_LIBRARY );
|
||||||
|
|
||||||
|
// Move nameTextCtrl to the head of the tab-order
|
||||||
|
if( dlg->GetChildren().DeleteObject( nameTextCtrl ) )
|
||||||
|
dlg->GetChildren().Insert( nameTextCtrl );
|
||||||
|
|
||||||
|
dlg->SetInitialFocus( nameTextCtrl );
|
||||||
|
|
||||||
|
dlg->Layout();
|
||||||
|
dlg->GetSizer()->Fit( dlg );
|
||||||
|
|
||||||
|
return dlg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SYMBOL_EDIT_FRAME::saveSymbolAs()
|
void SYMBOL_EDIT_FRAME::saveSymbolAs()
|
||||||
{
|
{
|
||||||
LIB_SYMBOL* symbol = getTargetSymbol();
|
LIB_SYMBOL* symbol = getTargetSymbol();
|
||||||
|
@ -653,57 +715,36 @@ void SYMBOL_EDIT_FRAME::saveSymbolAs()
|
||||||
if( symbol )
|
if( symbol )
|
||||||
{
|
{
|
||||||
LIB_ID old_lib_id = symbol->GetLibId();
|
LIB_ID old_lib_id = symbol->GetLibId();
|
||||||
wxString old_name = old_lib_id.GetLibItemName();
|
wxString symbolName = old_lib_id.GetLibItemName();
|
||||||
wxString old_lib = old_lib_id.GetLibNickname();
|
wxString libraryName = old_lib_id.GetLibNickname();
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable();
|
std::unique_ptr<EDA_LIST_DIALOG> dlg;
|
||||||
wxArrayString headers;
|
|
||||||
std::vector< wxArrayString > itemsToDisplay;
|
|
||||||
std::vector< wxString > libNicknames = tbl->GetLogicalLibs();
|
|
||||||
|
|
||||||
headers.Add( _( "Nickname" ) );
|
while( !done )
|
||||||
headers.Add( _( "Description" ) );
|
|
||||||
|
|
||||||
for( const wxString& name : libNicknames )
|
|
||||||
{
|
{
|
||||||
wxArrayString item;
|
dlg.reset( buildSaveAsDialog( symbolName, libraryName ) );
|
||||||
item.Add( name );
|
|
||||||
item.Add( tbl->GetDescription( name ) );
|
int ret = dlg->ShowModal();
|
||||||
itemsToDisplay.push_back( item );
|
|
||||||
|
if( ret == wxID_CANCEL )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if( ret == wxID_OK )
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
else if( ret == ID_MAKE_NEW_LIBRARY )
|
||||||
|
{
|
||||||
|
wxFileName newLibrary( AddLibraryFile( true ) );
|
||||||
|
libraryName = newLibrary.GetName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EDA_LIST_DIALOG dlg( this, _( "Save Symbol As" ), headers, itemsToDisplay, old_lib );
|
libraryName = dlg->GetTextSelection();
|
||||||
dlg.SetListLabel( _( "Save in library:" ) );
|
|
||||||
dlg.SetOKLabel( _( "Save" ) );
|
|
||||||
|
|
||||||
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
if( libraryName.IsEmpty() )
|
||||||
|
|
||||||
wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
|
|
||||||
wxDefaultPosition, wxDefaultSize, 0 );
|
|
||||||
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
|
||||||
|
|
||||||
wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, old_name,
|
|
||||||
wxDefaultPosition, wxDefaultSize, 0 );
|
|
||||||
bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
||||||
|
|
||||||
wxSizer* mainSizer = dlg.GetSizer();
|
|
||||||
mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
|
||||||
|
|
||||||
// Move nameTextCtrl to the head of the tab-order
|
|
||||||
if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
|
|
||||||
dlg.GetChildren().Insert( nameTextCtrl );
|
|
||||||
|
|
||||||
dlg.SetInitialFocus( nameTextCtrl );
|
|
||||||
|
|
||||||
dlg.Layout();
|
|
||||||
mainSizer->Fit( &dlg );
|
|
||||||
|
|
||||||
if( dlg.ShowModal() != wxID_OK )
|
|
||||||
return; // canceled by user
|
|
||||||
|
|
||||||
wxString new_lib = dlg.GetTextSelection();
|
|
||||||
|
|
||||||
if( new_lib.IsEmpty() )
|
|
||||||
{
|
{
|
||||||
DisplayError( this, _( "No library specified. Symbol could not be saved." ) );
|
DisplayError( this, _( "No library specified. Symbol could not be saved." ) );
|
||||||
return;
|
return;
|
||||||
|
@ -712,30 +753,30 @@ void SYMBOL_EDIT_FRAME::saveSymbolAs()
|
||||||
// @todo Either check the selecteced library to see if the parent symbol name is in
|
// @todo Either check the selecteced library to see if the parent symbol name is in
|
||||||
// the new library and/or copy the parent symbol as well. This is the lazy
|
// the new library and/or copy the parent symbol as well. This is the lazy
|
||||||
// solution to ensure derived symbols do not get orphaned.
|
// solution to ensure derived symbols do not get orphaned.
|
||||||
if( symbol->IsAlias() && new_lib != old_lib )
|
if( symbol->IsAlias() && libraryName != old_lib_id.GetLibNickname() )
|
||||||
{
|
{
|
||||||
DisplayError( this, _( "Derived symbols must be saved in the same library as their "
|
DisplayError( this, _( "Derived symbols must be saved in the same library as their "
|
||||||
"parent symbol." ) );
|
"parent symbol." ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString new_name = nameTextCtrl->GetValue();
|
symbolName = static_cast<wxTextCtrl*>( dlg->FindWindow( ID_SAVE_AS_NAME ) )->GetValue();
|
||||||
new_name.Trim( true );
|
symbolName.Trim( true );
|
||||||
new_name.Trim( false );
|
symbolName.Trim( false );
|
||||||
new_name.Replace( " ", "_" );
|
symbolName.Replace( " ", "_" );
|
||||||
|
|
||||||
if( new_name.IsEmpty() )
|
if( symbolName.IsEmpty() )
|
||||||
{
|
{
|
||||||
// This is effectively a cancel. No need to nag the user about it.
|
// This is effectively a cancel. No need to nag the user about it.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if there is a symbol with this name already.
|
// Test if there is a symbol with this name already.
|
||||||
if( m_libMgr->SymbolExists( new_name, new_lib ) )
|
if( m_libMgr->SymbolExists( symbolName, libraryName ) )
|
||||||
{
|
{
|
||||||
wxString msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'" ),
|
wxString msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'" ),
|
||||||
new_name,
|
symbolName,
|
||||||
new_lib );
|
libraryName );
|
||||||
|
|
||||||
KIDIALOG errorDlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
KIDIALOG errorDlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
||||||
errorDlg.SetOKLabel( _( "Overwrite" ) );
|
errorDlg.SetOKLabel( _( "Overwrite" ) );
|
||||||
|
@ -746,12 +787,12 @@ void SYMBOL_EDIT_FRAME::saveSymbolAs()
|
||||||
}
|
}
|
||||||
|
|
||||||
LIB_SYMBOL new_symbol( *symbol );
|
LIB_SYMBOL new_symbol( *symbol );
|
||||||
new_symbol.SetName( new_name );
|
new_symbol.SetName( symbolName );
|
||||||
|
|
||||||
m_libMgr->UpdateSymbol( &new_symbol, new_lib );
|
m_libMgr->UpdateSymbol( &new_symbol, libraryName );
|
||||||
SyncLibraries( false );
|
SyncLibraries( false );
|
||||||
m_treePane->GetLibTree()->SelectLibId( LIB_ID( new_lib, new_symbol.GetName() ) );
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( libraryName, new_symbol.GetName() ) );
|
||||||
LoadSymbol( new_name, new_lib, m_unit );
|
LoadSymbol( symbolName, libraryName, m_unit );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
@ -31,6 +31,7 @@ class FP_LIB_TABLE;
|
||||||
class FOOTPRINT_TREE_PANE;
|
class FOOTPRINT_TREE_PANE;
|
||||||
class SYMBOL_LIBRARY_MANAGER;
|
class SYMBOL_LIBRARY_MANAGER;
|
||||||
class FOOTPRINT_EDITOR_SETTINGS;
|
class FOOTPRINT_EDITOR_SETTINGS;
|
||||||
|
class EDA_LIST_DIALOG;
|
||||||
|
|
||||||
namespace PCB { struct IFACE; } // A KIFACE coded in pcbnew.cpp
|
namespace PCB { struct IFACE; } // A KIFACE coded in pcbnew.cpp
|
||||||
|
|
||||||
|
@ -320,6 +321,9 @@ protected:
|
||||||
/// protected so only friend PCB::IFACE::CreateWindow() can act as sole factory.
|
/// protected so only friend PCB::IFACE::CreateWindow() can act as sole factory.
|
||||||
FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
||||||
|
|
||||||
|
EDA_LIST_DIALOG* buildSaveAsDialog( const wxString& aFootprintName,
|
||||||
|
const wxString& aLibraryPreselect );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure the footprint info list is loaded (with a progress dialog) and then initialize
|
* Make sure the footprint info list is loaded (with a progress dialog) and then initialize
|
||||||
* the footprint library tree.
|
* the footprint library tree.
|
||||||
|
|
|
@ -975,22 +975,17 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( FOOTPRINT* aFootprint )
|
static int ID_SAVE_AS_NAME = 4172;
|
||||||
|
static int ID_MAKE_NEW_LIBRARY = 4173;
|
||||||
|
|
||||||
|
|
||||||
|
EDA_LIST_DIALOG* FOOTPRINT_EDIT_FRAME::buildSaveAsDialog( const wxString& aFootprintName,
|
||||||
|
const wxString& aLibraryPreselect )
|
||||||
{
|
{
|
||||||
if( aFootprint == nullptr )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
||||||
|
std::vector<wxString> nicknames = tbl->GetLogicalLibs();
|
||||||
SetMsgPanel( aFootprint );
|
|
||||||
|
|
||||||
wxString libraryName = aFootprint->GetFPID().GetLibNickname();
|
|
||||||
wxString footprintName = aFootprint->GetFPID().GetLibItemName();
|
|
||||||
bool updateValue = aFootprint->GetValue() == footprintName;
|
|
||||||
|
|
||||||
wxArrayString headers;
|
wxArrayString headers;
|
||||||
std::vector<wxArrayString> itemsToDisplay;
|
std::vector<wxArrayString> itemsToDisplay;
|
||||||
std::vector<wxString> nicknames = tbl->GetLogicalLibs();
|
|
||||||
|
|
||||||
headers.Add( _( "Nickname" ) );
|
headers.Add( _( "Nickname" ) );
|
||||||
headers.Add( _( "Description" ) );
|
headers.Add( _( "Description" ) );
|
||||||
|
@ -1003,40 +998,87 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( FOOTPRINT* aFootprint )
|
||||||
itemsToDisplay.push_back( item );
|
itemsToDisplay.push_back( item );
|
||||||
}
|
}
|
||||||
|
|
||||||
EDA_LIST_DIALOG dlg( this, _( "Save Footprint As" ), headers, itemsToDisplay, libraryName );
|
EDA_LIST_DIALOG* dlg = new EDA_LIST_DIALOG( this, _( "Save Footprint As" ), headers,
|
||||||
dlg.SetListLabel( _( "Save in library:" ) );
|
itemsToDisplay, aLibraryPreselect );
|
||||||
dlg.SetOKLabel( _( "Save" ) );
|
|
||||||
|
dlg->SetListLabel( _( "Save in library:" ) );
|
||||||
|
dlg->SetOKLabel( _( "Save" ) );
|
||||||
|
|
||||||
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
|
|
||||||
wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
|
wxStaticText* label = new wxStaticText( dlg, wxID_ANY, _( "Name:" ) );
|
||||||
wxDefaultPosition, wxDefaultSize, 0 );
|
|
||||||
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
||||||
|
|
||||||
wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
|
wxTextCtrl* nameTextCtrl = new wxTextCtrl( dlg, ID_SAVE_AS_NAME, aFootprintName );
|
||||||
wxDefaultPosition, wxDefaultSize, 0 );
|
|
||||||
bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
||||||
|
|
||||||
wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
|
wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
|
||||||
nameValidator.SetCharExcludes( FOOTPRINT::StringLibNameInvalidChars( false ) );
|
nameValidator.SetCharExcludes( FOOTPRINT::StringLibNameInvalidChars( false ) );
|
||||||
nameTextCtrl->SetValidator( nameValidator );
|
nameTextCtrl->SetValidator( nameValidator );
|
||||||
|
|
||||||
wxSizer* mainSizer = dlg.GetSizer();
|
wxButton* newLibraryButton = new wxButton( dlg, ID_MAKE_NEW_LIBRARY, _( "New Library..." ) );
|
||||||
mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
dlg->m_ButtonsSizer->Prepend( 80, 20 );
|
||||||
|
dlg->m_ButtonsSizer->Prepend( newLibraryButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
|
||||||
|
|
||||||
|
dlg->GetSizer()->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
||||||
|
|
||||||
|
dlg->Bind( wxEVT_BUTTON,
|
||||||
|
[dlg]( wxCommandEvent& )
|
||||||
|
{
|
||||||
|
dlg->EndModal( ID_MAKE_NEW_LIBRARY );
|
||||||
|
}, ID_MAKE_NEW_LIBRARY );
|
||||||
|
|
||||||
// Move nameTextCtrl to the head of the tab-order
|
// Move nameTextCtrl to the head of the tab-order
|
||||||
if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
|
if( dlg->GetChildren().DeleteObject( nameTextCtrl ) )
|
||||||
dlg.GetChildren().Insert( nameTextCtrl );
|
dlg->GetChildren().Insert( nameTextCtrl );
|
||||||
|
|
||||||
dlg.SetInitialFocus( nameTextCtrl );
|
dlg->SetInitialFocus( nameTextCtrl );
|
||||||
|
|
||||||
dlg.Layout();
|
dlg->Layout();
|
||||||
mainSizer->Fit( &dlg );
|
dlg->GetSizer()->Fit( dlg );
|
||||||
|
|
||||||
if( dlg.ShowModal() != wxID_OK )
|
return dlg;
|
||||||
return false; // canceled by user
|
}
|
||||||
|
|
||||||
libraryName = dlg.GetTextSelection();
|
|
||||||
|
bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( FOOTPRINT* aFootprint )
|
||||||
|
{
|
||||||
|
if( aFootprint == nullptr )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
|
||||||
|
|
||||||
|
SetMsgPanel( aFootprint );
|
||||||
|
|
||||||
|
wxString libraryName = aFootprint->GetFPID().GetLibNickname();
|
||||||
|
wxString footprintName = aFootprint->GetFPID().GetLibItemName();
|
||||||
|
bool updateValue = aFootprint->GetValue() == footprintName;
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
|
std::unique_ptr<EDA_LIST_DIALOG> dlg;
|
||||||
|
|
||||||
|
while( !done )
|
||||||
|
{
|
||||||
|
dlg.reset( buildSaveAsDialog( footprintName, libraryName ) );
|
||||||
|
|
||||||
|
int ret = dlg->ShowModal();
|
||||||
|
|
||||||
|
if( ret == wxID_CANCEL )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if( ret == wxID_OK )
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
else if( ret == ID_MAKE_NEW_LIBRARY )
|
||||||
|
{
|
||||||
|
wxFileName newLibrary( CreateNewLibrary() );
|
||||||
|
libraryName = newLibrary.GetName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
libraryName = dlg->GetTextSelection();
|
||||||
|
|
||||||
if( libraryName.IsEmpty() )
|
if( libraryName.IsEmpty() )
|
||||||
{
|
{
|
||||||
|
@ -1044,7 +1086,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( FOOTPRINT* aFootprint )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
footprintName = nameTextCtrl->GetValue();
|
footprintName = static_cast<wxTextCtrl*>( dlg->FindWindow( ID_SAVE_AS_NAME ) )->GetValue();
|
||||||
footprintName.Trim( true );
|
footprintName.Trim( true );
|
||||||
footprintName.Trim( false );
|
footprintName.Trim( false );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue